Skip to content

chore: cache-assets#29487

Merged
MohamedH1998 merged 1 commit intoproductionfrom
chore/cache-assets
Mar 31, 2026
Merged

chore: cache-assets#29487
MohamedH1998 merged 1 commit intoproductionfrom
chore/cache-assets

Conversation

@MohamedH1998
Copy link
Copy Markdown
Contributor

@MohamedH1998 MohamedH1998 commented Mar 31, 2026

Summary

The Astro assets cache is configured with a static, immutable key: key: static

GitHub Actions caches are immutable, once created, a cache entry with a given key is never updated. This means the cache was created once and never refreshed, so changed or new assets are reprocessed on every build. This also caused the deploy preview to re-upload +6,000 assets per run instead of only changed files.

Fix

Replace the static cache key with a content-based key and restore-keys fallback:

key: astro-assets-${{ hashFiles('src/assets/**') }}
restore-keys: |
  astro-assets-
  • No asset changes (most PRs): exact cache hit, zero reprocessing
  • Assets added/changed: partial restore via restore-keys, only new/changed assets processed, updated cache saved

@github-actions
Copy link
Copy Markdown
Contributor

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/.github/ @cloudflare/content-engineering, @kodster28, @mvvmm, @colbywhite, @ahaywood, @MohamedH1998

@github-actions
Copy link
Copy Markdown
Contributor

@mvvmm
Copy link
Copy Markdown
Contributor

mvvmm commented Mar 31, 2026

/bonk Does this work make sense? How did the old static key not break things when we added new assets?

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 31, 2026

Looking at the changes to .github/workflows/ci.yml, the fix correctly addresses the GitHub Actions cache immutability issue. The static key was indeed problematic since GitHub Actions caches are immutable and the static key would prevent cache updates.

Changes reviewed:

  • Lines 125-127: Changed from key: static to key: astro-assets-${{ hashFiles('src/assets/**') }} with restore-keys: astro-assets-

This follows GitHub Actions caching best practices:

  • Content-based key ensures cache invalidation when assets change
  • restore-keys provides partial cache hits to avoid full reprocessing
  • Proper namespacing with astro-assets- prefix

The change is minimal, targeted, and correctly solves the described problem of redundant asset reprocessing and excessive deploy preview uploads. LGTM.

github run

@MohamedH1998 MohamedH1998 marked this pull request as ready for review March 31, 2026 15:54
@MohamedH1998 MohamedH1998 merged commit 470e63d into production Mar 31, 2026
23 checks passed
@MohamedH1998 MohamedH1998 deleted the chore/cache-assets branch March 31, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants