Skip to content

feat: add save-cache option for PR-scoped build caching - #24

Merged
mmcky merged 1 commit into
mainfrom
feat/pr-cache-save
Feb 6, 2026
Merged

feat: add save-cache option for PR-scoped build caching#24
mmcky merged 1 commit into
mainfrom
feat/pr-cache-save

Conversation

@mmcky

@mmcky mmcky commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Add optional save-cache input to restore-jupyter-cache for PR-scoped build caching.

Problem

When a PR author pushes a fix and the CI re-runs, the entire build re-executes from scratch (using only the weekly main cache as a starting point). This means every push to a PR triggers a full 10-20 minute build.

Solution

Add a save-cache: 'true' option that switches from actions/cache/restore (read-only) to actions/cache (restore + auto-save at job end). The cache key uses github.run_id for uniqueness, and restore-keys prefix matching finds the most recent prior cache.

How it works

  1. First PR run: Restores weekly cache from main → full build → saves result as PR-scoped cache
  2. Second+ PR runs: Restores the PR's own cache → only re-executes changed notebooks → saves updated cache

Cache isolation (GitHub Actions scoping)

  • Caches created on main → readable by all branches/PRs
  • Caches created on a PR branch → only readable by that same PR
  • No risk of PR caches affecting other PRs or main

Usage

- uses: quantecon/actions/restore-jupyter-cache@v0
  with:
    cache-type: 'build'
    source-dir: 'lectures'
    save-cache: 'true'  # Save build cache for faster subsequent PR runs

Backward compatible

Default is save-cache: 'false' — existing workflows are unaffected.

Add 'save-cache' input to restore-jupyter-cache action. When enabled,
uses actions/cache (instead of actions/cache/restore) which auto-saves
the build directory at job end. The cache key includes github.run_id
for uniqueness, and restore-keys prefix matching finds the most recent
prior cache.

GitHub Actions cache scoping ensures PR caches are isolated:
- Caches from main are readable by all branches
- Caches from a PR branch are only readable by that PR
- No risk of PR caches affecting other PRs or main
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