Skip to content

Add cache-write input for read-only cache mode#1284

Open
salmanmkc wants to merge 2 commits intoactions:mainfrom
salmanmkc:feature/cache-read-only
Open

Add cache-write input for read-only cache mode#1284
salmanmkc wants to merge 2 commits intoactions:mainfrom
salmanmkc:feature/cache-read-only

Conversation

@salmanmkc
Copy link
Contributor

Right now if you use cache: pip (or pipenv/poetry) in a PR workflow, the action restores and saves the cache. There's no way to get read-only mode where you benefit from existing caches without writing back. This matters for cache poisoning — an untrusted PR could plant bad packages in the cache that later get picked up by pushes to main.

This adds a cache-write input (defaults to true, no breaking change). Set it to false to skip the post-step save.

Usage:

- uses: actions/setup-python@v6
  with:
    python-version: "3.12"
    cache: pip
    cache-write: ${{ github.event_name != 'pull_request' }}

What changed:

  • action.yml — new cache-write input
  • src/cache-save.ts — early return when cache-write is false
  • dist/ — rebuilt

Same change going into setup-node, setup-go, setup-java, setup-dotnet.

Add a 'cache-write' input (default: true) that controls whether the cache
is saved at the end of the workflow. When set to 'false', the action will
restore cached dependencies but skip saving, providing a read-only cache
mode.

This is useful for preventing cache poisoning attacks from untrusted PR
builds while still benefiting from cached dependencies.
@salmanmkc salmanmkc requested a review from a team as a code owner March 9, 2026 12:50
Copilot AI review requested due to automatic review settings March 9, 2026 12:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new action input to support “read-only” cache usage by allowing workflows to restore caches without writing updated caches back, helping mitigate cache poisoning risks for untrusted PRs.

Changes:

  • Introduces a new cache-write input (defaulting to enabled) in action.yml.
  • Skips the post-step cache save when cache-write is set to false.
  • Rebuilds the compiled dist/ output to include the new behavior.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
action.yml Adds the new cache-write input and documents its purpose.
src/cache-save.ts Implements early return to skip saving cache when cache-write is disabled.
dist/cache-save/index.js Compiled output reflecting the new cache-write behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +12 to +13
const cacheWriteEnabled = core.getInput('cache-write');
if (cacheWriteEnabled === 'false') {
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

cache-write is treated as a raw string and only disables saving when the value is exactly 'false'. This is inconsistent with other boolean inputs in this repo (e.g., check-latest uses core.getBooleanInput) and will silently save the cache for values like False/FALSE. Prefer core.getBooleanInput('cache-write') (or normalize/lowercase) and branch on the boolean result.

Suggested change
const cacheWriteEnabled = core.getInput('cache-write');
if (cacheWriteEnabled === 'false') {
const cacheWriteInput = core.getInput('cache-write');
const cacheWriteEnabled =
cacheWriteInput === ''
? true
: core.getBooleanInput('cache-write');
if (!cacheWriteEnabled) {

Copilot uses AI. Check for mistakes.
Comment on lines +12 to 20
const cacheWriteEnabled = core.getInput('cache-write');
if (cacheWriteEnabled === 'false') {
core.info('Cache write is disabled (read-only mode). Skipping cache save.');
return;
}

const cache = core.getInput('cache');
if (cache) {
await saveCache(cache);
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

New cache-write behavior is not covered by tests. Add a unit test in __tests__/cache-save.test.ts that sets cache-write to false and asserts cache.saveCache is not called (and optionally that the skip message is logged) when cache is enabled.

Copilot uses AI. Check for mistakes.
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.

2 participants