Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: Release

# Run this workflow on main (workflow_dispatch) to release the version in
# pyproject.toml: it publishes to PyPI, then creates the v<version> GitHub
# Release. Publishing a GitHub Release by hand still works too. Every step
# skips what is already published, so a re-run only fills in what is missing.
on:
release:
types: [published]
workflow_dispatch:

jobs:
build:
Expand All @@ -16,7 +21,11 @@ jobs:
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Release only from main
if: github.event_name == 'workflow_dispatch'
run: test "$GITHUB_REF" = refs/heads/main
- name: Verify release tag
if: github.event_name == 'release'
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: >-
Expand Down Expand Up @@ -49,3 +58,28 @@ jobs:
name: python-package-distributions
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true

# A Release created with GITHUB_TOKEN does not start this workflow again.
github-release:
needs: publish
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
TAG="v$VERSION"
if gh release view "$TAG" >/dev/null 2>&1; then
echo "$TAG already has a GitHub Release"
else
gh release create "$TAG" --target "$GITHUB_SHA" --title "$TAG" --generate-notes
fi
Loading