|
| 1 | +name: Apply release notes |
| 2 | + |
| 3 | +# Approval-based publish. When a member of the supabase/cli team approves a |
| 4 | +# release-notes PR (head ref `release-notes/v<VERSION>`), this workflow pushes |
| 5 | +# the proposed notes to the GitHub Release body for the corresponding tag, |
| 6 | +# comments the release URL on the PR, and closes the PR without merging. The |
| 7 | +# release-notes PR targets `develop` (not `main`) so an accidental merge can |
| 8 | +# never rewrite `main`'s history; the file is not meant to land on any branch. |
| 9 | +# |
| 10 | +# Mirrors the fast-forward job in release.yml, which already gates on a |
| 11 | +# `pull_request_review` + `approved` event. |
| 12 | + |
| 13 | +on: |
| 14 | + pull_request_review: |
| 15 | + types: [submitted] |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +jobs: |
| 21 | + authorize: |
| 22 | + # `state == 'open'` makes re-approvals on an already-closed PR a no-op |
| 23 | + # (a reviewer can re-approve from the GitHub UI even after close). |
| 24 | + if: | |
| 25 | + github.event.review.state == 'approved' && |
| 26 | + startsWith(github.event.pull_request.head.ref, 'release-notes/') && |
| 27 | + github.event.pull_request.base.ref == 'develop' && |
| 28 | + github.event.pull_request.state == 'open' |
| 29 | + runs-on: ubuntu-latest |
| 30 | + permissions: |
| 31 | + pull-requests: write |
| 32 | + outputs: |
| 33 | + authorized: ${{ steps.check.outputs.authorized }} |
| 34 | + steps: |
| 35 | + # App token: needs `orgs/.../teams/.../memberships` read (the org-installed |
| 36 | + # App has it), repo write to edit the release, and PR write to comment |
| 37 | + # and close. Matches release.yml's fast-forward step. |
| 38 | + - id: app-token |
| 39 | + uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 |
| 40 | + with: |
| 41 | + client-id: ${{ vars.GH_APP_CLIENT_ID }} |
| 42 | + private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} |
| 43 | + |
| 44 | + - name: Authorize approver against supabase/cli team |
| 45 | + id: check |
| 46 | + env: |
| 47 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 48 | + APPROVER: ${{ github.event.review.user.login }} |
| 49 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 50 | + # Fail closed: any response other than an active membership means the |
| 51 | + # approval is ignored. We post a comment so the reviewer sees why their |
| 52 | + # approval didn't apply, then exit 0 so the workflow isn't flagged red. |
| 53 | + run: | |
| 54 | + set -euo pipefail |
| 55 | + status=$(gh api \ |
| 56 | + -H "Accept: application/vnd.github+json" \ |
| 57 | + "orgs/supabase/teams/cli/memberships/${APPROVER}" \ |
| 58 | + --jq '.state' 2>/dev/null || true) |
| 59 | + if [ "$status" != "active" ]; then |
| 60 | + echo "Approver @${APPROVER} is not an active supabase/cli team member (state='${status:-none}'); ignoring approval." >&2 |
| 61 | + gh pr comment "$PR_NUMBER" --repo "${{ github.repository }}" --body \ |
| 62 | + "@${APPROVER} is not an active \`supabase/cli\` team member, so this approval was ignored. Ask a team member to approve to publish the notes." |
| 63 | + echo "authorized=false" >> "$GITHUB_OUTPUT" |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | + echo "authorized=true" >> "$GITHUB_OUTPUT" |
| 67 | +
|
| 68 | + apply: |
| 69 | + needs: authorize |
| 70 | + if: needs.authorize.outputs.authorized == 'true' |
| 71 | + runs-on: ubuntu-latest |
| 72 | + permissions: |
| 73 | + contents: write |
| 74 | + pull-requests: write |
| 75 | + steps: |
| 76 | + - id: app-token |
| 77 | + uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 |
| 78 | + with: |
| 79 | + client-id: ${{ vars.GH_APP_CLIENT_ID }} |
| 80 | + private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} |
| 81 | + |
| 82 | + # Checkout the PR head so any reviewer edits made in the GitHub UI before |
| 83 | + # approval are captured. apply-release-notes.ts reads from the working |
| 84 | + # tree. |
| 85 | + - uses: useblacksmith/checkout@41cdeedae8edb2e684ba22896a5fd2a3cb85db6b # v1 |
| 86 | + with: |
| 87 | + ref: ${{ github.event.pull_request.head.sha }} |
| 88 | + fetch-depth: 1 |
| 89 | + persist-credentials: false |
| 90 | + |
| 91 | + - uses: ./.github/actions/setup |
| 92 | + |
| 93 | + - name: Apply notes, comment, and close |
| 94 | + env: |
| 95 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 96 | + HEAD_REF: ${{ github.event.pull_request.head.ref }} |
| 97 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 98 | + APPROVER: ${{ github.event.review.user.login }} |
| 99 | + # The branch is named `release-notes/v<VERSION>`, so the tag is just |
| 100 | + # the basename. apply-release-notes.ts validates the file's existence. |
| 101 | + run: | |
| 102 | + set -euo pipefail |
| 103 | + tag="${HEAD_REF##release-notes/}" |
| 104 | + if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-(beta|alpha)\.[0-9]+)?$ ]]; then |
| 105 | + echo "Unexpected head ref '$HEAD_REF'; cannot derive tag." >&2 |
| 106 | + exit 1 |
| 107 | + fi |
| 108 | + echo "==> Applying notes for $tag" |
| 109 | + pnpm exec bun apps/cli/scripts/apply-release-notes.ts --tag "$tag" |
| 110 | + release_url="https://github.com/${{ github.repository }}/releases/tag/${tag}" |
| 111 | + gh pr comment "$PR_NUMBER" --repo "${{ github.repository }}" --body \ |
| 112 | + "Applied to [${tag}](${release_url}) after approval by @${APPROVER}." |
| 113 | + gh pr close "$PR_NUMBER" --repo "${{ github.repository }}" --delete-branch |
0 commit comments