Add Astro Build Cache Support #92
Open
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.
Fixes #89
Overview
This PR adds support for caching Astro's build artifacts (optimized images and other assets) between workflow runs, significantly improving build performance for subsequent runs.
Problem
As discussed in #89, Astro maintains its own cache directory (default:
node_modules/.astro) that stores optimized images and other build artifacts. Without caching this directory, every workflow run needs to re-optimize the same images, which can add significant time to builds - especially for sites with many images.While
actions/setup-nodecaches the npm package store, it does not cache Astro's build artifacts, which live innode_modules/.astro.Solution
This PR implements automatic caching of Astro's build directory using
actions/cache:astro-cache-${runner.os}-${github.sha}with fallback toastro-cache-${runner.os}-to allow reusing caches across commits while maintaining OS-specific cachesChanges
New Inputs
cache(optional, default:"true")"false"to disable caching (useful for debugging)cache-dir(optional, default:"node_modules/.astro")pathinput)cacheDirin their Astro configImplementation Details
actions/cache/restore@v5.0.1to restore cache before buildactions/cache/save@v5.0.1to save cache after build (only if cache wasn't hit)Testing
Test Methodology
cache: "true"Test Results
Evidence of caching working: Workflow Run #58564230627
Key log lines showing cache reuse:
Cache Behavior Verified
Backwards Compatibility
This change is fully backwards compatible:
cache: "false"Usage Examples
Default (caching enabled)
Explicitly enable caching
Disable caching (for debugging)
Custom cache directory