Skip to content

Commit eae3c7d

Browse files
heiskrCopilot
andauthored
Fix repo-sync failures: retry merge and ensure CodeQL runs on all PRs (#59882)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f17cab4 commit eae3c7d

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ on:
88
pull_request:
99
branches:
1010
- main
11-
paths:
12-
- '**/*.ts'
13-
- '**/*.tsx'
14-
- '.github/workflows/codeql.yml'
1511
# This is so that when CodeQL runs on a pull request, it can compare
1612
# against the state of the base branch.
1713
push:

.github/workflows/repo-sync.yml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,30 @@ jobs:
146146
147147
console.log('Merging the pull request')
148148
// Admin merge pull request to avoid squash
149-
await github.rest.pulls.merge({
150-
owner,
151-
repo,
152-
pull_number,
153-
merge_method: 'merge',
154-
})
155-
// Error loud here, so no try/catch
156-
console.log('Merged the pull request successfully')
149+
// Retry once per minute for up to 15 minutes to wait for required checks (e.g. CodeQL)
150+
const maxAttempts = 15
151+
const delay = 60_000 // 1 minute
152+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
153+
try {
154+
await github.rest.pulls.merge({
155+
owner,
156+
repo,
157+
pull_number,
158+
merge_method: 'merge',
159+
})
160+
console.log('Merged the pull request successfully')
161+
break
162+
} catch (mergeError) {
163+
const msg = mergeError.message || mergeError.response?.data?.message || ''
164+
const isRuleViolation = mergeError.status === 405 &&
165+
msg.includes('Repository rule violations')
166+
if (!isRuleViolation || attempt === maxAttempts) {
167+
throw mergeError
168+
}
169+
console.log(`Merge blocked by required checks (attempt ${attempt}/${maxAttempts}), retrying in 60s...`)
170+
await new Promise(resolve => setTimeout(resolve, delay))
171+
}
172+
}
157173
158174
- uses: ./.github/actions/slack-alert
159175
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}

0 commit comments

Comments
 (0)