Skip to content

Commit 93c6637

Browse files
committed
ci: Add GitHub Actions for testing and publishing
- test.yml: Run tests on push/PR across Python 3.8-3.12 and all OS - publish.yml: Auto-publish to PyPI when GitHub Release is created - Uses PyPI trusted publishing (no token in secrets needed)
1 parent 50f77f3 commit 93c6637

20 files changed

Lines changed: 939 additions & 0 deletions

.github/workflows/publish.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Publish to PyPI when a release is created
2+
name: Publish to PyPI
3+
4+
on:
5+
release:
6+
types: [published]
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
# Required for trusted publishing (no token needed)
13+
permissions:
14+
id-token: write
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.11"
23+
24+
- name: Install build dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install build twine
28+
29+
- name: Verify version matches tag
30+
run: |
31+
TAG_VERSION=${GITHUB_REF#refs/tags/v}
32+
PKG_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
33+
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
34+
echo "Error: Tag version ($TAG_VERSION) doesn't match package version ($PKG_VERSION)"
35+
exit 1
36+
fi
37+
echo "Version check passed: $PKG_VERSION"
38+
39+
- name: Build package
40+
run: python -m build
41+
42+
- name: Check package
43+
run: twine check dist/*
44+
45+
- name: Publish to PyPI
46+
uses: pypa/gh-action-pypi-publish@release/v1
47+
# Uses trusted publishing - configure at pypi.org/manage/project/dii-calculator/settings/publishing/
48+

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Run tests on every push and pull request
2+
name: Tests
3+
4+
on:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
branches: [main]
9+
10+
jobs:
11+
test:
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os: [ubuntu-latest, windows-latest, macos-latest]
17+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install -e .[dev]
31+
32+
- name: Run tests
33+
run: |
34+
pytest tests/ -v --tb=short
35+
36+
- name: Test CLI
37+
run: |
38+
python -m dii --help
39+
python -m dii --nutrients
40+

0 commit comments

Comments
 (0)