Skip to content

Commit bc35dfd

Browse files
committed
Skip update-codeql cron run when upgrade branch already exists
Adds a 'check-existing-branch' job that runs after detect-update and gates the create-pr job. On scheduled (cron) runs, if the target 'codeql/upgrade-to-vX.Y.Z' branch already exists on origin, the rest of the pipeline is skipped so peter-evans/create-pull-request does not force-push over reviewer commits or follow-up fixes (such as manually-applied lock-file refreshes). The check is bypassed on workflow_dispatch so a maintainer can always force a refresh by re-running the workflow manually.
1 parent 4cf9441 commit bc35dfd

1 file changed

Lines changed: 68 additions & 4 deletions

File tree

.github/workflows/update-codeql.yml

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,81 @@ jobs:
102102
fi
103103
104104
# ─────────────────────────────────────────────────────────────────────────────
105-
# Step 2: Update version, build, test, and create PR
105+
# Step 2: Check whether the upgrade branch already exists
106+
#
107+
# When this workflow runs on its nightly cron schedule and an upgrade PR has
108+
# already been opened for the target version, re-running `create-pr` would
109+
# force-push over the existing branch and silently discard any review
110+
# commits already made on top of the bot's initial push (e.g., manual fixes
111+
# to upgrade-packs.sh output or reviewer follow-ups). This job short-circuits
112+
# subsequent work in that case so the existing branch is preserved.
113+
#
114+
# The branch check is skipped on `workflow_dispatch` so a maintainer can
115+
# always re-run the upgrade pipeline on demand to re-create the branch.
116+
# ─────────────────────────────────────────────────────────────────────────────
117+
check-existing-branch:
118+
name: Check for Existing Upgrade Branch
119+
needs: detect-update
120+
if: needs.detect-update.outputs.update_needed == 'true'
121+
runs-on: ubuntu-latest
122+
123+
permissions:
124+
contents: read
125+
126+
outputs:
127+
branch_exists: ${{ steps.check-branch.outputs.branch_exists }}
128+
129+
steps:
130+
- name: Check - Look up upgrade branch on origin
131+
id: check-branch
132+
env:
133+
GH_TOKEN: ${{ github.token }}
134+
BRANCH: 'codeql/upgrade-to-${{ needs.detect-update.outputs.version }}'
135+
EVENT_NAME: ${{ github.event_name }}
136+
run: |
137+
if [ "${EVENT_NAME}" = "workflow_dispatch" ]; then
138+
echo "ℹ️ Manual dispatch — skipping existing-branch check."
139+
echo "branch_exists=false" >> "$GITHUB_OUTPUT"
140+
exit 0
141+
fi
142+
143+
echo "Checking whether branch '${BRANCH}' exists on ${GITHUB_REPOSITORY}..."
144+
if gh api "repos/${GITHUB_REPOSITORY}/branches/${BRANCH}" \
145+
--silent > /dev/null 2>&1; then
146+
echo "✅ Branch '${BRANCH}' already exists — skipping update to preserve manual edits."
147+
echo "branch_exists=true" >> "$GITHUB_OUTPUT"
148+
else
149+
echo "ℹ️ Branch '${BRANCH}' does not exist — proceeding with update."
150+
echo "branch_exists=false" >> "$GITHUB_OUTPUT"
151+
fi
152+
153+
- name: Check - Summary
154+
env:
155+
BRANCH: 'codeql/upgrade-to-${{ needs.detect-update.outputs.version }}'
156+
run: |
157+
echo "## Upgrade Branch Preflight" >> $GITHUB_STEP_SUMMARY
158+
echo "" >> $GITHUB_STEP_SUMMARY
159+
if [ "${{ steps.check-branch.outputs.branch_exists }}" = "true" ]; then
160+
echo "⏭️ Branch \`${BRANCH}\` already exists — skipping the rest of the pipeline to preserve any manual edits or review commits on it." >> $GITHUB_STEP_SUMMARY
161+
echo "" >> $GITHUB_STEP_SUMMARY
162+
echo "Trigger this workflow manually via \`workflow_dispatch\` to force a refresh." >> $GITHUB_STEP_SUMMARY
163+
else
164+
echo "▶️ Branch \`${BRANCH}\` does not exist — proceeding with the update pipeline." >> $GITHUB_STEP_SUMMARY
165+
fi
166+
167+
# ─────────────────────────────────────────────────────────────────────────────
168+
# Step 3: Update version, build, test, and create PR
106169
#
107170
# Updates all version-bearing files, installs dependencies, runs the full
108171
# build-and-test suite, and creates a pull request with the changes.
109172
# ─────────────────────────────────────────────────────────────────────────────
110173
create-pr:
111174
name: Create Update Pull Request
112-
needs: detect-update
113-
if: needs.detect-update.outputs.update_needed == 'true'
175+
needs: [detect-update, check-existing-branch]
176+
if: |
177+
needs.detect-update.outputs.update_needed == 'true' &&
178+
needs.check-existing-branch.outputs.branch_exists != 'true'
114179
runs-on: ubuntu-latest
115-
116180
permissions:
117181
contents: write
118182
pull-requests: write

0 commit comments

Comments
 (0)