1- # This workflow will upload a Python package when a release is published
1+ # This workflow will upload the package to PyPi when a release is published
22
33name : Publish Python Package (PyPi)
44
@@ -12,32 +12,48 @@ jobs:
1212 environment : release
1313
1414 permissions :
15- # IMPORTANT: this permission is mandatory for trusted publishing
15+ # IMPORTANT: this permission is mandatory for trusted publishing via PyPi
1616 id-token : write
17+ contents : write
1718
1819 steps :
1920 - uses : actions/checkout@v6
21+
22+ - name : Install uv
23+ uses : astral-sh/setup-uv@v7
24+
2025 - name : Set up Python
2126 uses : actions/setup-python@v6
2227 with :
23- python-version : ' 3.x'
24- - name : Install uv
25- uses : astral-sh/setup-uv@v7
26- - name : Bump project version
28+ python-version : " 3.x"
29+
30+ - name : Retrieve version from tag name
31+ id : retrieve- version
2732 run : |
28- tag=${{ github.event.release.tag_name }}
29- version_number=${tag#?}
30- uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version "$version_number"
31- - name : Commit changes
32- uses : EndBug/add-and-commit@v4
33- with :
34- message : " Bump version to ${{ github.event.release.tag_name }}"
35- add : " pyproject.toml"
36- ref : " main"
37- env :
38- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
39- - name : Build package distribution
33+ tag="${{ github.event.release.tag_name }}"
34+ version_number="${tag#?}"
35+ echo "version: $version_number"
36+ echo "version=$version_number" >> "$GITHUB_OUTPUT"
37+
38+ - name : Bump project version in pyproject.toml and commit changes to current branch and tag
39+ run : |
40+ VERSION=${{ steps.retrieve-version.outputs.version }}
41+ uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version $VERSION
42+
43+ git config --local user.email "action@github.com"
44+ git config --local user.name "GitHub Action"
45+
46+ git add pyproject.toml
47+ git commit -m "Bump package version to ${{ steps.retrieve-version.outputs.version }}."
48+
49+ git tag -f -a ${{ github.event.release.tag_name }} -m "Release ${{ steps.retrieve-version.outputs.version }}."
50+ git push origin HEAD:main
51+ git push origin -f ${{ github.event.release.tag_name }}
52+
53+ - name : Build package
54+ run : |
55+ uv build
56+
57+ - name : Publish package to PyPI
4058 run : |
41- uv build
42- - name : Publish package distributions to PyPI
43- uses : pypa/gh-action-pypi-publish@release/v1
59+ uv publish
0 commit comments