From 496dfff41a6ee272bb8b59a74046905561b9c5fa Mon Sep 17 00:00:00 2001 From: Hugh Hackman Date: Tue, 24 Mar 2026 23:13:16 +0000 Subject: [PATCH] =?UTF-8?q?fix(release):=20handle=20re-triggers=20?= =?UTF-8?q?=E2=80=94=20clean=20up=20stale=20branch=20and=20skip=20duplicat?= =?UTF-8?q?e=20PR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a release workflow fails after creating the branch (e.g. pnpm setup failure, network error) but before creating the tag, re-triggering the workflow previously failed at 'git push origin $BRANCH' because the branch already existed. Changes: - Commit and tag: check for existing remote branch and delete it before re-creating, so re-triggers are clean. Safe because check-tag skips when the tag already exists — we only reach this point when the tag does NOT exist yet. - Create PR: guard with 'gh pr view' so a pre-existing PR from a failed run is reused instead of causing 'pr already exists' failure. Split the single 'git push origin $BRANCH --tags' into two pushes (branch and tag separately) to avoid any flag ambiguity. --- .github/workflows/plugin-release.yaml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/plugin-release.yaml b/.github/workflows/plugin-release.yaml index cfc93dd..82c4870 100644 --- a/.github/workflows/plugin-release.yaml +++ b/.github/workflows/plugin-release.yaml @@ -215,11 +215,20 @@ jobs: run: | VERSION="${{ inputs.version }}" BRANCH="release/v${VERSION}" + # If the release branch already exists (e.g. from a failed prior run), + # delete it so the re-trigger can proceed cleanly. The check-tag job + # above already skips when the tag exists, so we only reach here when + # the tag does NOT exist yet — safe to remove a stale branch. + if git ls-remote --exit-code origin "refs/heads/$BRANCH" 2>/dev/null; then + echo "::notice::Branch $BRANCH already exists — deleting for clean re-trigger." + git push origin --delete "$BRANCH" + fi git checkout -b "$BRANCH" git add package.json "${{ steps.pkg-manager.outputs.lockfile }}" artifacthub-pkg.yml git commit -m "release: v${VERSION}" git tag "v${VERSION}" - git push origin "$BRANCH" --tags + git push origin "$BRANCH" + git push origin "refs/tags/v${VERSION}" - name: Create GitHub Release uses: softprops/action-gh-release@v2 @@ -255,11 +264,16 @@ jobs: run: | VERSION="${{ inputs.version }}" BODY=$(printf "Automated version bump and checksum update for v%s.\n\ncc @cpfarhood" "${VERSION}") - gh pr create \ - --title "release: v${VERSION}" \ - --body "$BODY" \ - --base main \ - --head "release/v${VERSION}" + # Create PR only if one doesn't already exist (idempotent re-trigger). + if ! gh pr view "release/v${VERSION}" --json number 2>/dev/null; then + gh pr create \ + --title "release: v${VERSION}" \ + --body "$BODY" \ + --base main \ + --head "release/v${VERSION}" + else + echo "::notice::PR for release/v${VERSION} already exists — skipping creation." + fi # Try auto-merge first (works on repos with required status checks pending). # Fall back to direct squash merge on repos without required status checks # (auto-merge is rejected when there are no pending required checks to wait for).