Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/scripts/wait-for-push-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ query() {
--arg sha "$GITHUB_SHA" --argjson repo_id "$GITHUB_REPOSITORY_ID" "$@"
}

# GitHub's filtered run listing can lag a push by minutes, and can briefly return a page that
# disagrees with its own count: both mean "not listed yet", so poll again rather than fail.
run_id=''
deadline=$((SECONDS + 120))
deadline=$((SECONDS + 600))
while [ "$SECONDS" -lt "$deadline" ]; do
response=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs" --method GET \
-f event=push -f branch="$GITHUB_REF_NAME" -f head_sha="$GITHUB_SHA" -F per_page=100)
selection=$(query "$provenance
if (.workflow_runs | type) != \"array\" or .total_count != (.workflow_runs | length)
then error(\"Incomplete validation run listing\") else .workflow_runs end
then empty else .workflow_runs end
| map(select(trusted))
| if length > 1 then error(\"Ambiguous matching push validations\")
elif length == 1 then .[0] | [.id, .workflow_id] | @tsv
Expand All @@ -42,7 +44,7 @@ while [ "$SECONDS" -lt "$deadline" ]; do
IFS=$'\t' read -r run_id workflow_id <<< "$selection"
break
fi
sleep 2
sleep 10
done

if [ -z "$run_id" ]; then
Expand Down
25 changes: 24 additions & 1 deletion scripts/wait-for-push-checks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ function runGate(options: GateOptions = {}) {
repos/example/project/actions/runs)
if [ "$LIST_STATUS" -ne 0 ]; then return "$LIST_STATUS"; fi
if [ "$poll" -eq 0 ]; then printf '%s\\n' "$FIRST_LIST";
else printf '%s\\n' "$NEXT_LIST"; fi
elif [ "$poll" -eq 1 ]; then printf '%s\\n' "$NEXT_LIST";
else printf '%s\\n' "$LATER_LIST"; fi
;;
repos/example/project/actions/runs/101)
if [ "$TERMINAL_STATUS" -ne 0 ]; then return "$TERMINAL_STATUS"; fi
Expand All @@ -76,6 +77,7 @@ function runGate(options: GateOptions = {}) {
GITHUB_SHA: sha,
FIRST_LIST: fixtures[0],
NEXT_LIST: fixtures[1] ?? fixtures[0],
LATER_LIST: fixtures[2] ?? fixtures[1] ?? fixtures[0],
TERMINAL_RESPONSE: JSON.stringify(options.terminal ?? validation()),
LIST_STATUS: String(options.listStatus ?? 0),
TERMINAL_STATUS: String(options.terminalStatus ?? 0),
Expand Down Expand Up @@ -126,6 +128,27 @@ describe('independent push-validation admission', () => {
expect(result.stdout).toContain('WATCH 101')
})

it('keeps waiting past two minutes for a run GitHub lists late', () => {
const none = { total_count: 0, workflow_runs: [] }
const result = runGate({
listings: [none, none, { total_count: 1, workflow_runs: [validation()] }],
})
expect(result.status, result.stderr).toBe(0)
expect(result.stdout).toContain('WATCH 101')
})

it.each([
['a truncated listing', { total_count: 2, workflow_runs: [validation()] }],
['a missing count', { workflow_runs: [validation()] }],
['malformed runs', { total_count: 1, workflow_runs: null }],
])('polls again past %s and admits from the next complete one', (_name, listing) => {
const result = runGate({
listings: [listing, { total_count: 1, workflow_runs: [validation()] }],
})
expect(result.status, result.stderr).toBe(0)
expect(result.stdout).toContain('WATCH 101')
})

it('selects the validation among unrelated runs for the same commit', () => {
const result = runGate({
listings: [
Expand Down
Loading