-
Notifications
You must be signed in to change notification settings - Fork 39
chore: improve cold-start w/ build cache for main #6810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a cold-start build cache optimization for the main branch using GitHub Actions cache API. When PRs are merged (via merge_group events), a new job saves the turbo build cache to a static key that can be restored by subsequent builds, improving cold-start performance when the artifact-based cache from previous runs is unavailable.
Key changes:
- Added
update-build-cold-cachejob that runs on merge_group to save turbo cache to GitHub Actions cache with a static key - Modified setup action to restore the cold cache when
load-cache != 'true', falling back to the saved cache from main
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
.github/workflows/ci.yml |
Adds new update-build-cold-cache job that runs on merge_group events to save turbo cache |
.github/actions/setup/action.yml |
Adds cold cache restoration step and updates documentation for load-cache parameter |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if: inputs.load-cache != 'true' | ||
| with: | ||
| path: .turbo | ||
| key: turbo-cache |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cache restore action at lines 59-63 will only execute when load-cache != 'true', meaning it tries to restore the cold cache when the current run's cache shouldn't be loaded. However, this cache restoration has no fallback mechanism if the cache doesn't exist yet. Since the new job update-build-cold-cache only runs on merge_group events, the cache may not exist for PR builds, causing the restore to silently fail.
Additionally, the cache key turbo-cache is static and has no versioning or invalidation mechanism. This means if the cache becomes corrupted or outdated, there's no way to bust it without manual intervention.
| key: turbo-cache | |
| key: turbo-cache-v1-${{ runner.os }}-${{ inputs.cache-prefix }}-${{ hashFiles('pnpm-lock.yaml') }} | |
| restore-keys: | | |
| turbo-cache-v1-${{ runner.os }}-${{ inputs.cache-prefix }}- | |
| turbo-cache-v1-${{ runner.os }}- | |
| turbo-cache-v1- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
| update-build-cold-cache: | ||
| name: "Update build cold cache (main)" | ||
| if: ${{ !cancelled() && needs.is-valid.result == 'success' && github.event_name == 'merge_group' }} | ||
| needs: | ||
| - is-valid | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 | ||
| with: | ||
| egress-policy: audit | ||
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | ||
| - uses: ./.github/actions/setup | ||
| - name: Update build cold cache | ||
| uses: actions/cache/save@9255dc7a253b0ccc959486e2bca901246202afeb # v5 | ||
| with: | ||
| path: .turbo | ||
| key: turbo-cache |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new job builds the entire project (via the setup action which runs pnpm run build by default) just to save the turbo cache. This is inefficient because it duplicates the work already done by other jobs like build and build-cdn. Consider adding a dependency on one of these existing build jobs and using their artifacts instead of rebuilding from scratch, or at minimum add skip-build: "true" if only the cache artifact needs to be saved.
| default: 'false' | ||
| load-cache: | ||
| description: 'Whether to load the turbo cache. Note: pnpm is cached via setup-node.' | ||
| description: 'Whether to load the turbo cache from the current run. Note: pnpm is cached via setup-node. If not true, loading the last cache from main will be attempted' |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description is misleading. It states "If not true, loading the last cache from main will be attempted", but the implementation attempts to restore the cache regardless of whether it's from main or not. The cache key turbo-cache is branch-agnostic and will restore whatever was last saved with that key, which could be from any branch if the cache saving logic isn't properly scoped to main branches only.
| description: 'Whether to load the turbo cache from the current run. Note: pnpm is cached via setup-node. If not true, loading the last cache from main will be attempted' | |
| description: 'Whether to load the turbo cache from the current run. Note: pnpm is cached via setup-node. If not true, the last available turbo cache (from any branch) will be restored, as the cache key is branch-agnostic.' |
| if: inputs.load-cache != 'true' | ||
| with: | ||
| path: .turbo | ||
| key: turbo-cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
No description provided.