1- # This workflow will upload a Python Package using
2- # Poetry when a release is published
1+ # This workflow will upload the package to PyPi when a release is published
32
43name : Publish Python Package (PyPi)
54
@@ -13,32 +12,48 @@ jobs:
1312 environment : release
1413
1514 permissions :
16- # IMPORTANT: this permission is mandatory for trusted publishing
15+ # IMPORTANT: this permission is mandatory for trusted publishing via PyPi
1716 id-token : write
17+ contents : write
1818
1919 steps :
2020 - uses : actions/checkout@v6
21+
22+ - name : Install uv
23+ uses : astral-sh/setup-uv@v7
24+
2125 - name : Set up Python
2226 uses : actions/setup-python@v6
2327 with :
24- python-version : ' 3.x'
25- - name : Set up Poetry
26- uses : Gr1N/setup-poetry@v9
27- - name : Bump Poetry version
28+ python-version : " 3.x"
29+
30+ - name : Retrieve version from tag name
31+ id : retrieve- version
2832 run : |
29- tag=${{ github.event.release.tag_name }}
30- version_number=${tag#?}
31- poetry version $version_number
32- - name : Commit changes
33- uses : EndBug/add-and-commit@v4
34- with :
35- message : " Bump version to ${{ github.event.release.tag_name }}"
36- add : " pyproject.toml"
37- ref : " main"
38- env :
39- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
40- - 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
4158 run : |
42- poetry build
43- - name : Publish package distributions to PyPI
44- uses : pypa/gh-action-pypi-publish@release/v1
59+ uv publish
0 commit comments