Skip to content

Commit ad1b57e

Browse files
docs: Update restore-only cache documentation (#1550)
* update restore-only cache example in advanced-usage.md * fix copilot suggestion * update naming
1 parent 670825a commit ad1b57e

1 file changed

Lines changed: 40 additions & 25 deletions

File tree

docs/advanced-usage.md

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -329,36 +329,51 @@ steps:
329329
- run: npm test
330330
```
331331

332-
**Restore-Only Cache**
332+
**Restore-only cache**
333+
334+
You can restore caches without saving new entries, which helps reduce cache writes and storage usage in read-only cache workflows.
333335

334336
```yaml
335-
## 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
336-
jobs:
337-
build:
338-
runs-on: ubuntu-latest
339-
steps:
340-
- uses: actions/checkout@v6
341-
# Restore Node.js modules cache (restore-only)
342-
- name: Restore Node modules cache
343-
uses: actions/cache@v5
344-
id: cache-node-modules
345-
with:
346-
path: ~/.npm
347-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
348-
restore-keys: |
349-
${{ runner.os }}-node-
350-
# Setup Node.js
351-
- name: Setup Node.js
352-
uses: actions/setup-node@v6
353-
with:
354-
node-version: '24'
355-
# Install dependencies
356-
- run: npm install
337+
steps:
338+
- uses: actions/checkout@v6
339+
# - uses: pnpm/action-setup@v6
340+
# with:
341+
# version: 10
342+
343+
- name: Setup Node.js
344+
uses: actions/setup-node@v6
345+
with:
346+
node-version: '24'
347+
348+
- name: Normalize runner architecture
349+
shell: bash
350+
run: echo "ARCH=$(echo '${{ runner.arch }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
351+
352+
- name: Output of cache path
353+
id: cachepath
354+
shell: bash
355+
run: echo "path=$(npm config get cache)" >> $GITHUB_OUTPUT
356+
# run: echo "path=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
357+
# For yarn workflow, output of yarn cache dir (v1) or yarn config get cacheFolder (v2+)
358+
# run: echo "path=$(yarn cache dir)" >> $GITHUB_OUTPUT
359+
360+
- name: Restore Node cache
361+
uses: actions/cache/restore@v5
362+
with:
363+
path: ${{ steps.cachepath.outputs.path }}
364+
key: node-cache-${{ runner.os }}-${{ env.ARCH }}-npm-${{ hashFiles('**/package-lock.json') }}
365+
# key: node-cache-${{ runner.os }}-${{ env.ARCH }}-yarn-${{ hashFiles('**/yarn.lock') }}
366+
# key: node-cache-${{ runner.os }}-${{ env.ARCH }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
367+
368+
- run: npm ci
369+
# - run: yarn install --frozen-lockfile # optional, --immutable
370+
# - run: pnpm install
357371
```
372+
> **Note**: Uncomment the commands relevant to your project's package manager.
358373

359-
> For more details related to cache scenarios, please refer [Node – npm](https://github.com/actions/cache/blob/main/examples.md#node---npm).
374+
> For more details related to cache scenarios, please refer [actions/cache/restore](https://github.com/actions/cache/tree/main/restore#only-restore-cache).
360375

361-
## Multiple Operating Systems and Architectures
376+
## Multiple operating systems and architectures
362377

363378
```yaml
364379
jobs:

0 commit comments

Comments
 (0)