From d88a456dfa9ae49122d02e0d2f7d71f94f420b87 Mon Sep 17 00:00:00 2001 From: Sandeep Date: Mon, 23 Nov 2026 21:42:13 -0800 Subject: [PATCH] Make release publishing safe to rerun Skip files PyPI already has, update an existing GitHub release instead of failing, and write release notes from CHANGELOG.md. Move artifact actions to Node 24 versions. --- .github/workflows/publish.yml | 39 ++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 659f4cb..8557fae 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,7 +21,7 @@ jobs: - run: python -m pip install build twine - run: python -m build - run: python -m twine check dist/* - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v5 with: name: python-package-distributions path: dist/ @@ -35,11 +35,15 @@ jobs: permissions: id-token: write steps: - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v5 with: name: python-package-distributions path: dist/ - uses: pypa/gh-action-pypi-publish@release/v1 + with: + # Re-running a release (or re-pushing its tag) must not fail on files + # PyPI already has; PyPI never allows replacing them anyway. + skip-existing: true release: needs: publish @@ -47,16 +51,31 @@ jobs: permissions: contents: write steps: - - uses: actions/download-artifact@v4 + - uses: actions/checkout@v5 + with: + persist-credentials: false + - uses: actions/download-artifact@v5 with: name: python-package-distributions path: dist/ - - name: Create GitHub release + - name: Create or update the GitHub release from CHANGELOG.md env: GH_TOKEN: ${{ github.token }} - run: >- - gh release create "$GITHUB_REF_NAME" dist/* - --repo "$GITHUB_REPOSITORY" - --verify-tag - --generate-notes - --title "TaskSeam $GITHUB_REF_NAME" + run: | + version="${GITHUB_REF_NAME#v}" + awk -v heading="## $version" ' + index($0, heading " ") == 1 || $0 == heading { found = 1; next } + found && /^## / { exit } + found { print } + ' CHANGELOG.md > release-notes.md + if ! grep -q '[^[:space:]]' release-notes.md; then + echo "See [CHANGELOG.md](https://github.com/$GITHUB_REPOSITORY/blob/main/CHANGELOG.md)." > release-notes.md + fi + if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then + gh release edit "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" \ + --title "TaskSeam $GITHUB_REF_NAME" --notes-file release-notes.md + gh release upload "$GITHUB_REF_NAME" dist/* --repo "$GITHUB_REPOSITORY" --clobber + else + gh release create "$GITHUB_REF_NAME" dist/* --repo "$GITHUB_REPOSITORY" --verify-tag \ + --title "TaskSeam $GITHUB_REF_NAME" --notes-file release-notes.md + fi