Skip to content

Commit 716ead5

Browse files
committed
ci: publish Python SDK with trusted publishing
1 parent d569e7d commit 716ead5

4 files changed

Lines changed: 129 additions & 12 deletions

File tree

.github/workflows/ci.yml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ on:
66
pull_request:
77
branches: [main]
88

9+
permissions:
10+
contents: read
11+
912
jobs:
1013
unit-tests:
1114
name: Unit Tests
1215
runs-on: ubuntu-latest
1316
strategy:
1417
matrix:
15-
python-version: ["3.11", "3.12", "3.13"]
18+
python-version: ["3.11", "3.12", "3.13", "3.14"]
1619
steps:
17-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@v7
1821

19-
- uses: actions/setup-python@v5
22+
- uses: actions/setup-python@v6
2023
with:
2124
python-version: ${{ matrix.python-version }}
2225

@@ -28,15 +31,44 @@ jobs:
2831
- name: Run unit tests
2932
run: python -m pytest tests/ --ignore=tests/test_integration.py -v
3033

34+
package:
35+
name: Package
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v7
39+
40+
- uses: actions/setup-python@v6
41+
with:
42+
python-version: "3.11"
43+
44+
- name: Install build tools
45+
run: python -m pip install --upgrade build twine
46+
47+
- name: Check Python syntax
48+
run: python -m compileall -q insforge tests
49+
50+
- name: Build distributions
51+
run: python -m build
52+
53+
- name: Check distribution metadata
54+
run: python -m twine check dist/*
55+
56+
- name: Smoke test wheel
57+
run: |
58+
python -m venv /tmp/insforge-wheel-test
59+
/tmp/insforge-wheel-test/bin/python -m pip install dist/*.whl
60+
cd /tmp
61+
/tmp/insforge-wheel-test/bin/python -c 'import insforge; from importlib.metadata import version; print(version("insforge"))'
62+
3163
integration-tests:
3264
name: Integration Tests
3365
runs-on: ubuntu-latest
3466
needs: unit-tests
3567
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
3668
steps:
37-
- uses: actions/checkout@v4
69+
- uses: actions/checkout@v7
3870

39-
- uses: actions/setup-python@v5
71+
- uses: actions/setup-python@v6
4072
with:
4173
python-version: "3.13"
4274

.github/workflows/publish.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: pypi-${{ github.ref }}
13+
cancel-in-progress: false
14+
15+
jobs:
16+
build:
17+
name: Build distributions
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v7
21+
22+
- uses: actions/setup-python@v6
23+
with:
24+
python-version: "3.11"
25+
26+
- name: Validate tag matches package version
27+
env:
28+
RELEASE_TAG: ${{ github.ref_name }}
29+
run: |
30+
package_version="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')"
31+
if [ "$RELEASE_TAG" != "v$package_version" ]; then
32+
echo "Tag $RELEASE_TAG does not match package version $package_version."
33+
exit 1
34+
fi
35+
36+
- name: Install test and build tools
37+
run: |
38+
python -m pip install --upgrade -e .
39+
python -m pip install --upgrade pytest pytest-asyncio build twine
40+
41+
- name: Run unit tests
42+
run: python -m pytest tests/ --ignore=tests/test_integration.py -v
43+
44+
- name: Build distributions
45+
run: python -m build
46+
47+
- name: Check distribution metadata
48+
run: python -m twine check dist/*
49+
50+
- name: Smoke test wheel
51+
run: |
52+
python -m venv /tmp/insforge-wheel-test
53+
/tmp/insforge-wheel-test/bin/python -m pip install dist/*.whl
54+
cd /tmp
55+
/tmp/insforge-wheel-test/bin/python -c 'import insforge; from importlib.metadata import version; print(version("insforge"))'
56+
57+
- name: Upload distributions
58+
uses: actions/upload-artifact@v7
59+
with:
60+
name: python-package-distributions
61+
path: dist/
62+
if-no-files-found: error
63+
retention-days: 1
64+
65+
publish:
66+
name: Publish distributions
67+
needs: build
68+
runs-on: ubuntu-latest
69+
permissions:
70+
id-token: write
71+
steps:
72+
- name: Download distributions
73+
uses: actions/download-artifact@v8
74+
with:
75+
name: python-package-distributions
76+
path: dist/
77+
78+
- name: Publish to PyPI
79+
uses: pypa/gh-action-pypi-publish@v1.14.0

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,20 @@ python -m build
257257

258258
This produces `dist/insforge-<version>.tar.gz` and `dist/insforge-<version>-py3-none-any.whl`.
259259

260-
### Publish to PyPI
260+
### Release to PyPI
261261

262-
```bash
263-
pip install twine
262+
Publishing uses PyPI Trusted Publishing through `.github/workflows/publish.yml`; no PyPI API token is stored in GitHub. The workflow publishes both the wheel and source distribution and produces digital attestations.
264263

265-
# Test PyPI (recommended first)
266-
twine upload --repository testpypi dist/*
264+
1. Update `project.version` in `pyproject.toml` and merge the change to `main` after CI passes.
265+
2. Create and push an annotated tag that exactly matches the package version with a `v` prefix:
267266

268-
# Production PyPI
269-
twine upload dist/*
267+
```bash
268+
git tag -a vX.Y.Z -m "vX.Y.Z"
269+
git push origin vX.Y.Z
270270
```
271271

272+
The tag triggers a build, metadata validation, and publication to PyPI. PEP 440 prerelease versions are supported as long as the tag exactly matches the version in `pyproject.toml`.
273+
272274
## License
273275

274276
See [LICENSE](LICENSE) for details.

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ dependencies = [
1313
"pydantic>=2.0",
1414
]
1515

16+
[project.urls]
17+
Source = "https://github.com/InsForge/insforge-python"
18+
Issues = "https://github.com/InsForge/insforge-python/issues"
19+
1620
[tool.setuptools]
1721
packages = [
1822
"insforge",

0 commit comments

Comments
 (0)