I have a Github actions workflow that on pushing a tag does the following for a python package:
- Creates a Github release using the tag version.
- Publishes the package to PyPI.
The package build and publishing is done using uv.
Question: How can I improve this code? Would it be better to break this into two workflow files. One for Github release and one for PyPI publishing?
# .github/workflows/github_release_pypi_publish.yaml
name: Github Release
on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+" # Python versioning format
jobs:
# Build the package
build:
name: Build dists
runs-on: ubuntu-latest
steps:
- name: Checkout repo at tagged commit
- uses: actions/checkout@v4
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v6
# Build wheels + sdist into ./dist
- name: Build package with uv
run: uv build
# Persist artifacts for the next jobs
- uses: actions/upload-artifact@v4
with:
name: dists
path: dist/
# Create a Github Release with the current tag version
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repo to read from CHANGELOG.md
- uses: actions/checkout@v4
- name: Download build artifacts from the build job
- uses: actions/download-artifact@v4
with:
name: dists
path: dist/
- name: Create Github Release for tag and attach built files
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }} # e.g. 1.2.3
name: ${{ github.ref_name }} # release title
body_path: CHANGELOG.md # use the file as release notes
files: |
dist/*.whl
dist/*.tar.gz
# Publish package to PyPI
publish:
name: Publish to PyPI
needs: release
runs-on: ubuntu-latest
permissions:
id-token: write # required for PyPI Trusted Publishing (OIDC)
steps:
- uses: actions/download-artifact@v4
with:
name: dists
path: dist/
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v6
# Upload to PyPI via OIDC (no token needed once Trusted Publisher is configured)
- name: uv publish
run: uv publish