|
| 1 | +name: release-please |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + # Reopens the release PR when a push to main never fired the webhook. |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +# The App token does the writing, so the workflow token stays read-only. |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: release-please-${{ github.ref }} |
| 16 | + cancel-in-progress: false |
| 17 | + |
| 18 | +jobs: |
| 19 | + release-please: |
| 20 | + # Keeps a manual dispatch from running release-please against another ref. |
| 21 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 22 | + runs-on: ubuntu-latest |
| 23 | + timeout-minutes: 10 |
| 24 | + steps: |
| 25 | + - name: Generate App token |
| 26 | + id: app-token |
| 27 | + uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 |
| 28 | + with: |
| 29 | + client-id: ${{ secrets.RELEASE_PLEASE_APP_ID }} |
| 30 | + private-key: ${{ secrets.RELEASE_PLEASE_APP_PRIVATE_KEY }} |
| 31 | + permission-contents: write |
| 32 | + permission-issues: write |
| 33 | + permission-pull-requests: write |
| 34 | + |
| 35 | + - name: Release please |
| 36 | + id: release |
| 37 | + uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0 |
| 38 | + with: |
| 39 | + # Branch protection requires Verify, which never runs on a PR the |
| 40 | + # workflow token opens, so the App authors the release PR. |
| 41 | + token: ${{ steps.app-token.outputs.token }} |
| 42 | + config-file: release-please-config.json |
| 43 | + manifest-file: .release-please-manifest.json |
| 44 | + |
| 45 | + - name: Checkout |
| 46 | + if: ${{ steps.release.outputs.release_created }} |
| 47 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 48 | + with: |
| 49 | + persist-credentials: false |
| 50 | + |
| 51 | + - name: Sync the release body from the changelog |
| 52 | + if: ${{ steps.release.outputs.release_created }} |
| 53 | + env: |
| 54 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 55 | + TAG_NAME: ${{ steps.release.outputs.tag_name }} |
| 56 | + VERSION: ${{ steps.release.outputs.version }} |
| 57 | + run: | |
| 58 | + # CHANGELOG.md is the one source of the release notes. The first release has |
| 59 | + # no compare link, so its heading is "## 0.1.0 (" rather than "## [0.1.0]". |
| 60 | + # index(), not a regex, because the version carries literal dots. |
| 61 | + awk -v ver="$VERSION" ' |
| 62 | + index($0, "## [" ver "]") == 1 || index($0, "## " ver " ") == 1 { found = 1; next } |
| 63 | + found && index($0, "## ") == 1 { exit } |
| 64 | + found { print } |
| 65 | + ' CHANGELOG.md > release-notes.md |
| 66 | +
|
| 67 | + # A missing section fails the run rather than blanking a correct body. |
| 68 | + if ! grep -q '[^[:space:]]' release-notes.md; then |
| 69 | + echo "::error::No CHANGELOG.md section found for ${VERSION}; release body left as generated." |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | +
|
| 73 | + gh release edit "$TAG_NAME" --notes-file release-notes.md |
0 commit comments