@@ -3,32 +3,47 @@ name: Publish Python 🐍 distributions 📦 to PyPI
33on :
44 push :
55 tags :
6- - ' *'
6+ - ' *'
77
88jobs :
99 build-n-publish :
1010 name : Build and publish Python 🐍 distributions 📦 to PyPI
1111 runs-on : ubuntu-latest
12+
13+ # Required for PyPI Trusted Publishing (OIDC). No API token or
14+ # password is stored in this repository. The token is minted on
15+ # demand by GitHub and verified by PyPI against the trusted
16+ # publisher configuration for this project.
17+ permissions :
18+ id-token : write
19+
1220 steps :
13- - uses : actions/checkout@master
14- - name : Set up Python 3.12
15- uses : actions/setup-python@v3
16- with :
17- python-version : ' 3.12'
18- - name : Install pypa/setuptools
19- run : >-
20- python -m
21- pip install setuptools wheel
22- - name : Extract tag name
23- id : tag
24- run : echo ::set-output name=TAG_NAME::$(echo $GITHUB_REF | cut -d / -f 3)
25- - name : Update version in setup.py
26- run : >-
27- sed -i "s/{{VERSION_PLACEHOLDER}}/${{ steps.tag.outputs.TAG_NAME }}/g" setup.py
28- - name : Build a binary wheel
29- run : >-
30- python setup.py sdist bdist_wheel
31- - name : Publish distribution 📦 to PyPI
32- uses : pypa/gh-action-pypi-publish@master
33- with :
34- password : ${{ secrets.PYPI_API_TOKEN }}
21+ - uses : actions/checkout@v4
22+
23+ - name : Set up Python 3.12
24+ uses : actions/setup-python@v5
25+ with :
26+ python-version : ' 3.12'
27+
28+ - name : Install build tooling
29+ run : python -m pip install --upgrade pip build
30+
31+ - name : Verify that the tag matches the package version
32+ run : |
33+ TAG_NAME="${GITHUB_REF_NAME#v}"
34+ PACKAGE_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
35+ echo "Tag: $TAG_NAME"
36+ echo "Package version: $PACKAGE_VERSION"
37+ if [ "$TAG_NAME" != "$PACKAGE_VERSION" ]; then
38+ echo "::error::Tag '${GITHUB_REF_NAME}' does not match the version '${PACKAGE_VERSION}' in pyproject.toml."
39+ exit 1
40+ fi
41+
42+ - name : Build a binary wheel and source distribution
43+ run : python -m build
44+
45+ # Publishes via PyPI Trusted Publishing (OIDC). The distribution
46+ # is attested (PEP 740) and the provenance is shown on PyPI under
47+ # the "Provenance" information for the release files.
48+ - name : Publish distribution 📦 to PyPI
49+ uses : pypa/gh-action-pypi-publish@release/v1
0 commit comments