Skip to content

Publish Python Package (PyPi) #130

Publish Python Package (PyPi)

Publish Python Package (PyPi) #130

Workflow file for this run

# This workflow will upload the package to PyPi when a release is published
name: Publish Python Package (PyPi)
on:
release:
types: [published]
jobs:
deploy:
runs-on: ubuntu-latest
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing via PyPi
id-token: write
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Retrieve version from tag name
id: retrieve-version
run: |
tag=${{ github.event.release.tag_name }}
version_number=${tag#?}
echo version: $version_number
echo "version=$version_number" >> $GITHUB_OUTPUT
- name: Bump project version in pyproject.toml
run: |
VERSION=${{ steps.retrieve-version.outputs.version }}
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version $VERSION
- name: Add changes to current branch and tag
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add pyproject.toml
git commit -m "Bump version to ${{ github.event.release.tag_name }}"
- name: Commit changes
run: |
git add pyproject.toml
git commit -m "Bump package version to ${{ steps.retrieve-version.outputs.version }}."
git tag -f -a ${{ github.event.release.tag_name }} -m "Release ${{ steps.retrieve-version.outputs.version }}."
git push origin HEAD:main
git push origin -f ${{ github.event.release.tag_name }}
- name: Build package
run: |
uv build
- name: Publish package to PyPI
run: |
uv publish