From eaec9e3fff830f776e1237f1eff4e660ee2f3cd1 Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Sun, 31 May 2026 18:22:49 +0800 Subject: [PATCH] ci(release-plz): prune stale release branches before opening the PR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit release-plz leaves its `release-plz-*` branch behind after a release PR is merged; the leftover ref makes the next `release-pr` fail with HTTP 422 (the job swallows it as a warning, so no release PR is ever created and releases silently stop). Before running release-pr, delete any `release-plz-*` branch that has no open PR — keeping the active release PR's branch untouched — so the pipeline self-heals instead of needing a manual branch deletion each time. --- .github/workflows/release-plz.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml index f667f9b..c8590f8 100644 --- a/.github/workflows/release-plz.yml +++ b/.github/workflows/release-plz.yml @@ -66,6 +66,26 @@ jobs: with: app-id: ${{ steps.load_secrets.outputs.GITHUB_APP_ID }} private-key: ${{ steps.app_key.outputs.pem }} + # release-plz leaves its release branch behind after a release PR merges, + # and a leftover ref then makes the next `release-pr` fail with HTTP 422 + # (so no PR is created). Prune any `release-plz-*` branch that no longer + # has an open PR — never the active release PR's branch — before running. + - name: Prune stale release-plz branches + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + REPO: ${{ github.repository }} + run: | + for branch in $(gh api "repos/$REPO/branches" --paginate --jq '.[].name' \ + | grep '^release-plz-' || true); do + open=$(gh pr list --repo "$REPO" --head "$branch" --state open --json number --jq 'length') + if [ "$open" = "0" ]; then + echo "Pruning stale release branch: $branch" + gh api -X DELETE "repos/$REPO/git/refs/heads/$branch" \ + || echo "::warning::could not delete $branch" + else + echo "Keeping $branch (open PR exists)" + fi + done - name: Run release-plz (release-pr) uses: release-plz/action@v0.5 with: