From eb969d04f118c6ab9d594b86dac5d60ca83f4e43 Mon Sep 17 00:00:00 2001 From: Jan Havlena Date: Wed, 18 Nov 2026 12:57:53 +0100 Subject: [PATCH 1/3] Create the GitHub Release on publish unless it already exists --- .github/workflows/publish-to-pypi.yml | 31 +++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index cfbf991..db639ba 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -1,6 +1,9 @@ name: Publish to PyPI on: + push: + tags: + - "v*" release: types: [published] workflow_dispatch: @@ -10,9 +13,15 @@ on: required: true default: "" +permissions: + contents: read + jobs: publish: runs-on: ubuntu-latest + permissions: + # Creating the GitHub Release for the version. + contents: write environment: production # Optional: use environment for additional security steps: @@ -60,13 +69,17 @@ jobs: # Run the publish script in non-interactive mode ./publish.sh - - name: Create GitHub Release (if triggered by tag) - if: github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/tags/') - uses: softprops/action-gh-release@v1 - with: - files: | - dist/*.whl - dist/*.tar.gz - generate_release_notes: true + # Skip if the release exists: creating one in the UI also pushes the tag, + # and that is what triggers this workflow in the first place. + - name: Create the GitHub Release unless it exists env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ github.token }} + run: | + VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') + TAG="v$VERSION" + if gh release view "$TAG" > /dev/null 2>&1; then + echo "Release $TAG already exists. Skipping." + else + gh release create "$TAG" dist/*.whl dist/*.tar.gz \ + --generate-notes --target "$GITHUB_SHA" + fi From c521e90031a4764da7611d544ecc4aa030b8b36d Mon Sep 17 00:00:00 2001 From: Jan Havlena Date: Wed, 18 Nov 2026 13:00:52 +0100 Subject: [PATCH 2/3] Set the package version from the release tag and use ubuntu-24.04 for publishing --- .github/workflows/publish-to-pypi.yml | 31 +++++++++++++++++++++------ 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index db639ba..18b303b 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -18,7 +18,7 @@ permissions: jobs: publish: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 permissions: # Creating the GitHub Release for the version. contents: write @@ -42,6 +42,25 @@ jobs: fi echo "✅ Confirmation received for manual publish" + # The tag is the source of truth for the version; the files in the repo + # carry whatever was last committed. These edits live and die with the + # runner. + - name: Set the version from the tag + run: | + if [ "$GITHUB_REF_TYPE" != "tag" ]; then + echo "Run this workflow from a v* tag, not $GITHUB_REF." + exit 1 + fi + if ! [[ "$GITHUB_REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then + echo "Tag $GITHUB_REF_NAME is not a version like v1.2.3." + exit 1 + fi + VERSION="${GITHUB_REF_NAME#v}" + sed -i "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml + sed -i "s/^__version__ = \".*\"/__version__ = \"$VERSION\"/" tonic_fabricate/__init__.py + grep -n '^version = ' pyproject.toml + grep -n '^__version__ = ' tonic_fabricate/__init__.py + - name: Make publish script executable run: chmod +x publish.sh @@ -75,11 +94,9 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') - TAG="v$VERSION" - if gh release view "$TAG" > /dev/null 2>&1; then - echo "Release $TAG already exists. Skipping." + if gh release view "$GITHUB_REF_NAME" > /dev/null 2>&1; then + echo "Release $GITHUB_REF_NAME already exists. Skipping." else - gh release create "$TAG" dist/*.whl dist/*.tar.gz \ - --generate-notes --target "$GITHUB_SHA" + gh release create "$GITHUB_REF_NAME" dist/*.whl dist/*.tar.gz \ + --generate-notes --verify-tag fi From 83b418e21c6e33b9f4406dadfd95a575d1cd356b Mon Sep 17 00:00:00 2001 From: Jan Havlena Date: Wed, 18 Nov 2026 13:01:21 +0100 Subject: [PATCH 3/3] Drop the tag push trigger from the publish workflow --- .github/workflows/publish-to-pypi.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 18b303b..e9ac061 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -1,9 +1,6 @@ name: Publish to PyPI on: - push: - tags: - - "v*" release: types: [published] workflow_dispatch: