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' \