Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Introduced restore-only flag#1743

Open
gmazzo wants to merge 1 commit into
actions:mainfrom
gmazzo:restore-only-flag
Open

feat: Introduced restore-only flag#1743
gmazzo wants to merge 1 commit into
actions:mainfrom
gmazzo:restore-only-flag

Conversation

@gmazzo
Copy link
Copy Markdown

@gmazzo gmazzo commented Apr 1, 2026

Introduces controlling when to save the cache with a flag.

Description

Introduces a new restore-only flag into the main @actions/cache. If set, the action will download the cache, but it will skip its saving at the post actions phase.

Fixes #1730

Motivation and Context

It's true that we do have the @actions/cache/restore and @actions/cache/save actions, but this change serves a new unsupported use-case: "only feed the cache given a condition".

This use case is a generalisation of the one I'm interesting on to support, which is "only feed the cache at the default branch". A topic you raise at force-deletion-of-caches-overriding-default-cache-eviction-policy. After carefully reviewing the setup options for the action, we concluded there is no straight forward way (currently) to achieve this.

The change will also allow us to align our ad-hocs @actions/cache with the default gradle/actions/setup-gradle's behavior, where its cache-read-only (defaulting to ${{ github.event.repository != null && github.ref_name != github.event.repository.default_branch }}) behaves the same.

Right now, to support our use case, we have been forced to create an internal wrapper composite action that runs @actions/cache/restore or @actions/cache based on this condition.
@actions/cache/save is not fully suitable for the use case, because it does not runs as a post action.

How Has This Been Tested?

A dedicated unit test was added to the saveImpl.test.ts suite.

Test PR in the fork running CI: gmazzo#1

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (add or update README or docs)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@gmazzo gmazzo force-pushed the restore-only-flag branch from 4e5d7b7 to 832f315 Compare April 1, 2026 20:34
@gmazzo gmazzo marked this pull request as ready for review April 1, 2026 20:36
@gmazzo gmazzo requested a review from a team as a code owner April 1, 2026 20:36
Copilot AI review requested due to automatic review settings April 1, 2026 20:36
Copy link
Copy Markdown
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 restore-only input to the main actions/cache action to support “restore but don’t save” scenarios (e.g., avoid overwriting caches on non-default branches).

Changes:

  • Introduces new restore-only input in action metadata and README.
  • Adds Inputs.RestoreOnly constant and test utilities support for the new input.
  • Updates save implementation and adds a unit test intending to ensure save is skipped when restore-only is set.

Reviewed changes

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

Show a summary per file
File Description
src/utils/testUtils.ts Adds test input wiring/cleanup for restore-only.
src/saveImpl.ts Adds restore-only handling in the post-save implementation.
src/constants.ts Introduces Inputs.RestoreOnly.
tests/saveImpl.test.ts Adds a test for restore-only behavior.
action.yml Exposes restore-only as an action input.
README.md Documents the new restore-only option and an example expression.
dist/save/index.js Updates compiled save bundle for the new input/behavior.
dist/save-only/index.js Updates compiled save-only bundle for the new input/behavior.
dist/restore/index.js Updates compiled restore bundle enum to include the new input.
dist/restore-only/index.js Updates compiled restore-only bundle enum to include the new input.

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

Comment thread src/saveImpl.ts
Comment thread __tests__/saveImpl.test.ts
Comment thread action.yml Outdated
@gmazzo gmazzo force-pushed the restore-only-flag branch from 832f315 to 063fc74 Compare April 1, 2026 20:59
@gmazzo gmazzo force-pushed the restore-only-flag branch from b9a2cb5 to e58227c Compare April 1, 2026 21:00
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.

Create an option restore-only

2 participants