|
63 | 63 | # No password / token needed — OIDC token issued automatically |
64 | 64 | # to the configured trusted publisher on pypi.org. |
65 | 65 | packages-dir: dist/ |
| 66 | + |
| 67 | + github-release: |
| 68 | + # Creates the GitHub Release automatically on every `v*` tag, so the |
| 69 | + # Releases page never lags behind the tags. Runs only after a |
| 70 | + # successful PyPI publish, keeping GitHub Releases and PyPI in sync. |
| 71 | + name: Create GitHub Release |
| 72 | + needs: [build, publish] |
| 73 | + if: startsWith(github.ref, 'refs/tags/') |
| 74 | + runs-on: ubuntu-latest |
| 75 | + permissions: |
| 76 | + contents: write # required to create the release |
| 77 | + steps: |
| 78 | + - uses: actions/checkout@v5 |
| 79 | + - uses: actions/download-artifact@v4 |
| 80 | + with: |
| 81 | + name: dist |
| 82 | + path: dist/ |
| 83 | + - name: Extract release notes from CHANGELOG |
| 84 | + id: notes |
| 85 | + run: | |
| 86 | + VERSION="${GITHUB_REF_NAME#v}" |
| 87 | + awk -v ver="$VERSION" ' |
| 88 | + /^## \[/ { if (found) exit; if (index($0, "[" ver "]")) { found=1; next } } |
| 89 | + found { print } |
| 90 | + ' CHANGELOG.md > release-notes.md |
| 91 | + if [ -s release-notes.md ]; then |
| 92 | + echo "have_notes=true" >> "$GITHUB_OUTPUT" |
| 93 | + else |
| 94 | + echo "have_notes=false" >> "$GITHUB_OUTPUT" |
| 95 | + fi |
| 96 | + - name: Create GitHub Release |
| 97 | + env: |
| 98 | + GH_TOKEN: ${{ github.token }} |
| 99 | + run: | |
| 100 | + if [ "${{ steps.notes.outputs.have_notes }}" = "true" ]; then |
| 101 | + gh release create "$GITHUB_REF_NAME" dist/* \ |
| 102 | + --repo "$GITHUB_REPOSITORY" \ |
| 103 | + --title "$GITHUB_REF_NAME" \ |
| 104 | + --notes-file release-notes.md \ |
| 105 | + --verify-tag --latest |
| 106 | + else |
| 107 | + gh release create "$GITHUB_REF_NAME" dist/* \ |
| 108 | + --repo "$GITHUB_REPOSITORY" \ |
| 109 | + --title "$GITHUB_REF_NAME" \ |
| 110 | + --generate-notes \ |
| 111 | + --verify-tag --latest |
| 112 | + fi |
0 commit comments