[CI] Improve CI speed by optimizing Docker cache in code-quality.yml #1
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 Problem:
In the .github/workflows/code-quality.yml workflow, the clang-tidy job builds a Docker image in two stages: base and code_quality. While the base stage is correctly built and its layers are saved to the GitHub Actions cache (using cache-to), the subsequent code_quality stage only reads from the cache (cache-from) but does not write its own resulting layers back to the cache.
This results in the code_quality stage being rebuilt from scratch on every single run. This leads to significantly longer CI times and inefficient use of resources.
Proposed Solution:
By adding the cache-to parameter to the code_quality build step, we can ensure its layers are also cached. This will dramatically speed up subsequent runs of the workflow. The cache-from should also be updated to look for its own cache first.
Current Code:
code_qualitystageuses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
target: code_quality
cache-from: type=gha,scope=base
Suggested Change:
code_qualitystageuses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
target: code_quality
Attempt to read from both 'code_quality' and 'base' caches
cache-from: |type=gha,scope=code_quality
type=gha,scope=base
Write the resulting layers to the 'code_quality' cache scope
cache-to: type=gha,scope=code_quality,mode=maxThis simple change will make the code quality checks run much faster, improving the overall developer experience and efficiency.