Skip to content

fix(ci): save the Next.js build cache every run instead of freezing it at the lockfile key#5859

Merged
waleedlatif1 merged 2 commits into
stagingfrom
ci/build-cache
Jul 22, 2026
Merged

fix(ci): save the Next.js build cache every run instead of freezing it at the lockfile key#5859
waleedlatif1 merged 2 commits into
stagingfrom
ci/build-cache

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • The Build App job's Next.js cache key was os + hashFiles(bun.lock) with no unique suffix — GitHub caches are immutable per key, so the cache was saved once per lockfile change and then frozen: every subsequent run logged Cache hit occurred on the primary key ... not saving cache and compiled against an ever-staler cache
  • Suffix the key with github.sha so every run saves its refreshed .next/cache, and restore via prefix match (os-nextjs-<lockfile>-os-nextjs-) so each run starts from the most recently saved cache
  • This is the standard pattern from the Next.js CI caching docs; expected effect is a meaningfully warmer incremental build on every PR (the build step is ~83% of the 3–4 min job, which gates merges)

Type of Change

  • Bug fix

Testing

Verified the frozen-cache behavior in the live run log (primary-key hit → save skipped). The fix's effect shows up in this PR's own Build App check and the following runs as the cache warms per-commit.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…t at the lockfile key

The cache key was only runner.os + bun.lock hash, and GitHub caches are
immutable per key: the first run after a lockfile change saved the cache
once, then every later run hit the primary key and skipped the save
('Cache hit occurred on the primary key ... not saving cache'), so builds
compiled against a cache stale since the last lockfile bump. Suffix the
key with the commit SHA so each run saves its refreshed cache, and
restore via prefix match to the most recent entry.
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Jul 22, 2026 9:28pm

Request Review

@cursor

cursor Bot commented Jul 22, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
CI-only caching configuration with no application, auth, or data-path changes; worst case is slower builds or extra cache entries if keys misbehave.

Overview
Fixes Build App CI so the Next.js .next/cache is written on every run instead of only once per bun.lock hash.

The cache primary key now includes github.sha, run_id, and run_attempt, so GitHub Actions no longer treats repeat runs as a primary-key hit and skips saving an updated cache. Restore keys use prefix fallbacks (lockfile + sha, then lockfile, then OS-wide) so each build still restores the newest compatible cache while warming incrementally between commits.

Reviewed by Cursor Bugbot for commit a860339. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refreshes the Next.js build cache on every workflow attempt. The main changes are:

  • Adds the commit SHA, run ID, and run attempt to the cache key.
  • Restores the latest cache for the same commit before broader fallbacks.
  • Allows reruns to save updated cache contents under a new key.

Confidence Score: 5/5

This looks safe to merge.

  • Reruns receive a distinct key because github.run_attempt increments.
  • The commit-level prefix restores the cache saved by the preceding attempt.
  • No blocking issues remain in the updated workflow.

Important Files Changed

Filename Overview
.github/workflows/test-build.yml Makes each Next.js cache key unique per workflow attempt while preserving ordered cache fallbacks.

Reviews (2): Last reviewed commit: "fix(ci): make the Next.js cache key uniq..." | Re-trigger Greptile

Comment thread .github/workflows/test-build.yml Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a860339. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant