|
| 1 | +name: Release Please |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + actions: write |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: release-${{ github.ref }} |
| 15 | + cancel-in-progress: false |
| 16 | + |
| 17 | +jobs: |
| 18 | + release-please: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - id: release |
| 22 | + uses: googleapis/release-please-action@v5 |
| 23 | + with: |
| 24 | + config-file: release-please-config.json |
| 25 | + manifest-file: .release-please-manifest.json |
| 26 | + |
| 27 | + - if: ${{ steps.release.outputs.pr }} |
| 28 | + env: |
| 29 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + REPO: ${{ github.repository }} |
| 31 | + WORKFLOW: ${{ github.workflow }} |
| 32 | + PR_JSON: ${{ steps.release.outputs.pr }} |
| 33 | + run: | |
| 34 | + PR=$(echo "$PR_JSON" | jq -r .number) |
| 35 | + BRANCH=$(echo "$PR_JSON" | jq -r .headBranchName) |
| 36 | + # Rebase-merge works when main has advanced past the release branch's |
| 37 | + # base. When the release commit already sits directly on main HEAD, |
| 38 | + # GitHub refuses ("This branch can't be rebased") on a rebase-only |
| 39 | + # repo — fast-forward main to the release commit via the API instead. |
| 40 | + gh pr merge --rebase --auto -R "$REPO" "$PR" \ |
| 41 | + || gh pr merge --rebase -R "$REPO" "$PR" \ |
| 42 | + || gh api -X PATCH "repos/$REPO/git/refs/heads/main" \ |
| 43 | + -f sha="$(gh api "repos/$REPO/git/refs/heads/$BRANCH" --jq .object.sha)" |
| 44 | + for _ in $(seq 1 30); do |
| 45 | + STATE=$(gh pr view "$PR" -R "$REPO" --json state --jq .state) |
| 46 | + [ "$STATE" = "MERGED" ] && break |
| 47 | + sleep 2 |
| 48 | + done |
| 49 | + gh api -X DELETE "repos/$REPO/git/refs/heads/$BRANCH" 2>/dev/null || true |
| 50 | + gh workflow run "$WORKFLOW" -R "$REPO" --ref main |
| 51 | +
|
| 52 | + # When a release is actually published, redeploy from main so the live |
| 53 | + # build carries the bumped version. release-please's own version-bump |
| 54 | + # commit is pushed by GITHUB_TOKEN and does NOT trigger the on:push deploy, |
| 55 | + # so the site would otherwise stay one release behind. |
| 56 | + - if: ${{ steps.release.outputs.release_created }} |
| 57 | + env: |
| 58 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + REPO: ${{ github.repository }} |
| 60 | + run: gh workflow run deploy.yml -R "$REPO" --ref main |
0 commit comments