Skip to content

Commit f110c11

Browse files
marcelolynchbryangingechen
authored andcommitted
ci(cache): fall back to latest cache-snapshot when the resolved run has none (leanprover-community#40734)
The resolved master run can predate the `cache-snapshot` artifact (or have an expired one), making the warm step's `download-artifact` log a spurious "Artifact not found" error. Verify the artifact exists first; otherwise fall back to the latest master run that has one, and skip the warm if none does.
1 parent b6b3fc8 commit f110c11

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

.github/actions/get-cache/action.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ runs:
4040
'[.workflow_runs[] | select(.created_at <= $d and ($c == "" or .created_at >= $c))][0].id // empty' \
4141
2>/dev/null || true
4242
}
43+
# True if run-id $1 actually carries a `cache-snapshot` artifact. Older runs
44+
# predate the feature and artifacts expire, so a successful run is not enough.
45+
# Filters server-side by name, but re-checks in jq in case `name` is ignored.
46+
has_snapshot() {
47+
[[ -n "$(gh api "repos/leanprover-community/mathlib4/actions/runs/$1/artifacts?name=cache-snapshot&per_page=100" \
48+
--jq '.artifacts[] | select(.name == "cache-snapshot") | .id' 2>/dev/null | head -1 || true)" ]]
49+
}
4350
4451
# This PR's merge-base with master (+ its commit date), and the cutoff below which
4552
# snapshots have expired (retention ~14d).
@@ -57,6 +64,19 @@ runs:
5764
fi
5865
[[ -z "${run_id}" ]] && run_id=$(latest_run)
5966
67+
# The resolved run may carry no `cache-snapshot` artifact: an older merge-base
68+
# predating the feature, or one whose artifact already expired (older-than-today
69+
# runs often won't have one). Rather than let the download step hard-error on a
70+
# missing artifact, confirm it's present; if not, fall back to the latest master
71+
# run, and warm only if that one has it.
72+
if [[ -n "${run_id}" ]] && ! has_snapshot "${run_id}"; then
73+
echo "Run ${run_id} has no cache-snapshot artifact; falling back to latest master run."
74+
run_id=$(latest_run)
75+
if [[ -n "${run_id}" ]] && ! has_snapshot "${run_id}"; then
76+
run_id=""
77+
fi
78+
fi
79+
6080
echo "Resolved cache-snapshot run_id: '${run_id}' (merge-base: ${mb:-unknown})"
6181
echo "run_id=${run_id}" >> "$GITHUB_OUTPUT"
6282

0 commit comments

Comments
 (0)