Skip to content
Merged
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
45 changes: 36 additions & 9 deletions .github/workflows/current-revision-rerun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,51 @@ jobs:

reservations_pages="$(gh api --paginate --slurp \
"repos/${REPOSITORY}/commits/${EXPECTED_HEAD}/check-runs?check_name=Protected%20current-revision%20verifier&filter=all&per_page=100")"
reservations="$(jq -c \
--arg head "${EXPECTED_HEAD}" \
--arg prefix "rep60-required-workflow:v2:" \
--arg suffix ":${PR_NUMBER}:${EXPECTED_HEAD}" '
all_reservations="$(jq -c \
--arg head "${EXPECTED_HEAD}" '
[.[].check_runs[]? |
select(.name == "Protected current-revision verifier") |
select(.app.id == 15368 and .app.slug == "github-actions") |
select(.head_sha == $head) |
select((.external_id | type) == "string") |
select(.external_id | startswith($prefix) and endswith($suffix))]
select((.external_id | type) == "string")]
' <<<"${reservations_pages}")"
test "$(jq 'length' <<<"${reservations}")" -eq 1
v3_reservations="$(jq -c \
--arg prefix "rep60-required-workflow:v3:" \
--arg suffix ":${PR_NUMBER}:${EXPECTED_BASE}:${EXPECTED_HEAD}" '
[.[] |
select(.external_id | startswith($prefix) and endswith($suffix))]
' <<<"${all_reservations}")"
v2_reservations="$(jq -c \
--arg prefix "rep60-required-workflow:v2:" \
--arg suffix ":${PR_NUMBER}:${EXPECTED_HEAD}" '
[.[] |
select(.external_id | startswith($prefix) and endswith($suffix))]
' <<<"${all_reservations}")"
v3_count="$(jq 'length' <<<"${v3_reservations}")"
v2_count="$(jq 'length' <<<"${v2_reservations}")"
if [ "${v3_count}" -eq 1 ]; then
# v3 is base-bound and therefore authoritative even when a stale
# v2 reservation for the same PR/head remains visible during the
# bounded cutover.
reservations="${v3_reservations}"
elif [ "${v3_count}" -eq 0 ] && [ "${v2_count}" -eq 1 ]; then
# Bounded cutover compatibility: v2 lacks the base in external_id,
# so the protected run payload below must bind the exact live base.
reservations="${v2_reservations}"
else
echo "Protected verifier evidence is missing or version-ambiguous." >&2
exit 1
fi
reservation_id="$(jq -er '.[0].id | select(type == "number" and . > 0)' <<<"${reservations}")"
reservation_url="$(jq -r '.[0].details_url // empty' <<<"${reservations}")"
test "${reservation_url}" = "${GITHUB_SERVER_URL}/${REPOSITORY}/runs/${reservation_id}"
reservation_external_id="$(jq -er '.[0].external_id | select(type == "string" and length > 0)' <<<"${reservations}")"
[[ "${reservation_external_id}" =~ ^rep60-required-workflow:v2:([1-9][0-9]*):${PR_NUMBER}:${EXPECTED_HEAD}$ ]]
run_id="${BASH_REMATCH[1]}"
if [[ "${reservation_external_id}" =~ ^rep60-required-workflow:v3:([1-9][0-9]*):${PR_NUMBER}:${EXPECTED_BASE}:${EXPECTED_HEAD}$ ]]; then
run_id="${BASH_REMATCH[1]}"
else
[[ "${reservation_external_id}" =~ ^rep60-required-workflow:v2:([1-9][0-9]*):${PR_NUMBER}:${EXPECTED_HEAD}$ ]]
run_id="${BASH_REMATCH[1]}"
fi
verifier_run_url="${GITHUB_SERVER_URL}/${REPOSITORY}/actions/runs/${run_id}"
run="$(gh api "repos/${REPOSITORY}/actions/runs/${run_id}")"
jq -e \
Expand Down
Loading