From 762d84d4169b4fdcc5255332c642518d637e5b80 Mon Sep 17 00:00:00 2001 From: Michael Shaffer Date: Sun, 29 Mar 2026 12:56:50 -0400 Subject: [PATCH] Update release workflow to handle branch push safely --- .github/workflows/release.yml | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 730c703..c1438b2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -105,7 +105,16 @@ jobs: exit 1 fi git commit -m "chore: bump manifest to ${VERSION} for ${TAG}" - git push -u origin "$BRANCH" + + # Re-runs reuse branch name release/v*; a plain push fails non-fast-forward if the + # branch already exists with different history. Force-with-lease updates only when + # the remote ref still matches what we fetched (safer than bare --force). + git fetch origin "refs/heads/${BRANCH}:refs/remotes/origin/${BRANCH}" 2>/dev/null || true + if git rev-parse "refs/remotes/origin/${BRANCH}" >/dev/null 2>&1; then + git push -u origin "$BRANCH" --force-with-lease="refs/heads/${BRANCH}:refs/remotes/origin/${BRANCH}" + else + git push -u origin "$BRANCH" + fi git fetch origin --tags HEAD_SHA=$(git rev-parse HEAD) @@ -128,11 +137,15 @@ jobs: gh release create "$TAG" --target "$BRANCH" --title "$TAG" --generate-notes "${EXTRA[@]}" fi - gh pr create \ - --base "$DEFAULT_BRANCH" \ - --head "$BRANCH" \ - --title "Merge ${TAG} manifest bump" \ - --body "Automated manifest bump for [${TAG}](https://github.com/${{ github.repository }}/releases/tag/${TAG}). Merge after checks pass so \`${DEFAULT_BRANCH}\` matches the release." + if [ "$(gh pr list --head "$BRANCH" --state open --json number -q 'length')" -eq 0 ]; then + gh pr create \ + --base "$DEFAULT_BRANCH" \ + --head "$BRANCH" \ + --title "Merge ${TAG} manifest bump" \ + --body "Automated manifest bump for [${TAG}](https://github.com/${{ github.repository }}/releases/tag/${TAG}). Merge after checks pass so \`${DEFAULT_BRANCH}\` matches the release." + else + echo "::notice::An open PR already exists for \`${BRANCH}\`; skipping \`gh pr create\`." + fi - name: Summary if: success()