4
0
Fork 0
mirror of https://github.com/actions/setup-node.git synced 2025-11-07 04:56:55 +00:00

Compare commits

...

3 commits

Author SHA1 Message Date
leavesster
1a91d1fa4d
Merge 09158c28ef into dda4788290 2025-10-22 10:02:09 +08:00
aparnajyothi-y
dda4788290
Add example for restore-only cache in documentation (#1419)
* Update versions.yml

* Update versions.yml

* doc update

* update

* update

* doc update
2025-10-21 14:44:57 -05:00
yleaf
09158c28ef fix: add restore key for all package managers 2024-09-10 10:44:45 +08:00
2 changed files with 30 additions and 13 deletions

View file

@ -300,6 +300,35 @@ steps:
- run: npm test
```
**Restore-Only Cache**
```yaml
## In some workflows, you may want to restore a cache without saving it. This can help reduce cache writes and storage usage in workflows that only need to read from cache
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
# Restore Node.js modules cache (restore-only)
- name: Restore Node modules cache
uses: actions/cache@v4
id: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
# Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
# Install dependencies
- run: npm install
```
> For more details related to cache scenarios, please refer [Node npm](https://github.com/actions/cache/blob/main/examples.md#node---npm).
## Multiple Operating Systems and Architectures
```yaml

View file

@ -46,19 +46,7 @@ export const restoreCache = async (
core.saveState(State.CachePrimaryKey, primaryKey);
const isManagedByYarnBerry = await repoHasYarnBerryManagedDependencies(
packageManagerInfo,
cacheDependencyPath
);
let cacheKey: string | undefined;
if (isManagedByYarnBerry) {
core.info(
'All dependencies are managed locally by yarn3, the previous cache can be used'
);
cacheKey = await cache.restoreCache(cachePaths, primaryKey, [keyPrefix]);
} else {
cacheKey = await cache.restoreCache(cachePaths, primaryKey);
}
const cacheKey = await cache.restoreCache(cachePaths, primaryKey, [keyPrefix]);
core.setOutput('cache-hit', Boolean(cacheKey));