From f83bfa17ff878a6689b875353df7200ab2d30053 Mon Sep 17 00:00:00 2001 From: Kris Austin Date: Tue, 22 Sep 2026 13:41:30 -0500 Subject: [PATCH] ci: keep older compiler cache entries when the save wrote nothing (#15828) #15668 saves the compiler cache on cancelled and failed builds and then drops the older entries for the leg on the ref. actions/cache/save only warns when its tar fails, so a cancelled build whose ccache directory was still being written saved nothing, the drop ran anyway and deleted the leg's last good entry. The next run on main restored nothing and compiled cold, and so did every PR that restored in the gap. Run 35405244634 (Flatpak x86_64, 2026-09-18) did this to ccache-Flatpak-x86_64-35397824860-1; between 13 and 18 September 9 of 87 cancelled main build jobs did the same. Look the new entry up before deleting anything, and keep the older ones when it is not there. --- .github/workflows/build_all.yml | 8 ++++++++ .github/workflows/build_orca.yml | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/.github/workflows/build_all.yml b/.github/workflows/build_all.yml index ed106ec65e..24317b0add 100644 --- a/.github/workflows/build_all.yml +++ b/.github/workflows/build_all.yml @@ -413,6 +413,14 @@ jobs: GH_TOKEN: ${{ github.token }} run: | api="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/caches" + # The save step reports success even when its tar failed, so keep + # the older entries unless the new one is listed. + if ! curl -sSf -H "Authorization: Bearer $GH_TOKEN" \ + "$api?ref=$GITHUB_REF&key=$CCACHE_ENTRY" \ + | jq -e --arg entry "$CCACHE_ENTRY" 'any(.actions_caches[]; .key == $entry)' > /dev/null; then + echo "$CCACHE_ENTRY was not saved; keeping the older entries." + exit 0 + fi curl -sSf -H "Authorization: Bearer $GH_TOKEN" \ "$api?ref=$GITHUB_REF&key=ccache-$CCACHE_LEG-&per_page=100" \ | jq -r --arg prefix "ccache-$CCACHE_LEG-" --argjson run "$GITHUB_RUN_ID" \ diff --git a/.github/workflows/build_orca.yml b/.github/workflows/build_orca.yml index 85458615b4..2ea72d0773 100644 --- a/.github/workflows/build_orca.yml +++ b/.github/workflows/build_orca.yml @@ -798,6 +798,13 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | + # The save step reports success even when its tar failed, so keep + # the older entries unless the new one is listed. + if ! gh cache list --ref "$GITHUB_REF" --key "$CCACHE_ENTRY" --json key \ + | jq -e --arg entry "$CCACHE_ENTRY" 'any(.[]; .key == $entry)' > /dev/null; then + echo "$CCACHE_ENTRY was not saved; keeping the older entries." + exit 0 + fi gh cache list --ref "$GITHUB_REF" --key "ccache-$CCACHE_LEG-" --limit 100 --json id,key \ | jq -r --arg prefix "ccache-$CCACHE_LEG-" --argjson run "$GITHUB_RUN_ID" \ '.[] | select((.key | ltrimstr($prefix) | split("-")[0] | tonumber?) < $run) | .id' \