Harden restore-cache image verification and cache cleanup#12
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix Docker image verification and cache deletion in restore-cache job
Harden restore-cache image verification and cache cleanup
May 30, 2026
jiaheng
approved these changes
May 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
restore-cachejob could fail after a successful cache restore because the empty image check was matching unreliably, and cache cleanup could 404 on the delete request. This updates the workflow to verify the cached image by reference and to treat cache deletion misses as non-fatal.Restore verification
emptyCache deletion
refquery parameter from the cache deletion callKey consistency
Original prompt
The GitHub Actions workflow for the
restore-cachejob in thejiaheng/docker-cacherepository is failing due to the following problems:\n\n1. Docker Image Verification Fails:\n - The check to verify cached Docker images does not reliably find the expectedemptyimage because the filter does not match correctly.\n\n2. Cache Deletion Request Fails:\n - Thecurlcommand used to delete the GitHub Actions cache returns a404 Not Founderror, likely due to incorrect$GITHUB_REFor cachekeyvalues.\n\n### Proposed Fixes\n\n1. Fix Docker Image Verification:\n Update the verification command to use a filter that reliably matches the Docker image by reference:\nbash\n id="$(docker images --quiet --filter 'reference=empty')"\n [[ -n "$id" ]] || { echo 'Image "empty" not found'; exit 1; }\n\n\n2. Fix Cache Deletion Request:\n - Log the constructed URL and key for debugging.\n - Allow the workflow to continue even if the cache deletion fails, treating it as a non-critical error.\n - Updatedcurlcommand: \nbash\n curl --request DELETE \\n --header 'Accept: application/vnd.github.v3+json' \\n --header "Authorization: Bearer $GITHUB_TOKEN" \\n "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/caches?key=docker-cache-test-${{ matrix.os }}-${{ github.run_id }}-${{ github.run_attempt }}" \\n || echo "Cache not found (non-fatal)."\n\n\n3. Implement Workflow Changes:\n Apply the proposed fixes to therestore-cachejob in.github/workflows/test.yaml.\n\n4. Validation:\n - Test the workflow on pull request branches to ensure it handles both success and failure scenarios gracefully.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.
Assistant: The job failure indicates issues with verifying and removing cached Docker images and appears to stem from errors in the
restore-cachejob, specifically when:description="empty image"label, leading to a non-zero exit code.404 Not Founderror occurs when attempting aDELETErequest to remove caches. This likely happens due to an incorrect$GITHUB_REFvalue or a misconstructed cache key.Diagnosis and Solutions
Problem 1: Verifying Cached Docker Images
The command below fails to find an image:
Root Cause: There might be an issue with tag usage (
empty), the label definition in theDockerfile, or the image not being created or cached as intended.Solution:
Dockerfilelabel. It's correctly defined:docker buildstep creates images with the right label duringBuild one tagged and one dangling empty test Docker image:Update the verification check to be more robust:
Problem 2: Cache Deletion HTTP Request
The
curlDELETEoperation fails with:$GITHUB_REForkeydoesn't point to the existing cache on GitHub.Solution:
Log and verify variables passed to the
DELETErequest:Use the following fallback for
curl:This approach ensures non-critical errors during cache deletion don’t halt workflows.
Updated Workflow Snippet
Here’s the relevant fix for the
restore-cachejob: