File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 :
Original file line number Diff line number Diff 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' }}
You can’t perform that action at this time.
0 commit comments