Skip to content

Commit 72bd62b

Browse files
Update cachetest.yml for Node.js caching setup
1 parent 2eea4fe commit 72bd62b

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

.github/workflows/cachetest.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Test cache restore
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build:
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
os: [ubuntu-latest, macos-latest, windows-latest]
13+
14+
steps:
15+
# Checkout repository
16+
- uses: actions/checkout@v6
17+
# Setup Node.js
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v6
20+
with:
21+
node-version: '21'
22+
- name: Normalize runner architecture (Linux/macOS)
23+
if: runner.os != 'Windows'
24+
shell: bash
25+
run: echo "ARCH=$(echo '${{ runner.arch }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
26+
- name: Normalize runner architecture (Windows)
27+
if: runner.os == 'Windows'
28+
shell: pwsh
29+
run: |
30+
$arch = "${{ runner.arch }}".ToLower()
31+
echo "ARCH=$arch" | Out-File $env:GITHUB_ENV -Append
32+
# Detect package manager and its cache path
33+
- name: Detect package manager and cache path
34+
shell: bash
35+
run: |
36+
set -e
37+
# UPDATE THESE VALUES FOR YOUR PROJECT:
38+
PACKAGE_MANAGER="npm" # Specify: npm, yarn, or pnpm
39+
CACHE_PATH="$(npm config get cache)" # npm: npm config get cache | yarn: yarn cache dir | pnpm: pnpm store path
40+
LOCK_PATTERN="**/package-lock.json" # npm: **/package-lock.json | yarn: **/yarn.lock | pnpm: **/pnpm-lock.yaml
41+
echo "PACKAGE_MANAGER=$PACKAGE_MANAGER" >> $GITHUB_ENV
42+
echo "NODE_CACHE=$CACHE_PATH" >> $GITHUB_ENV
43+
echo "LOCK_PATTERN=$LOCK_PATTERN" >> $GITHUB_ENV
44+
# Restore dependency cache using a unified key format
45+
- name: Restore Node cache
46+
uses: actions/cache/restore@v5
47+
with:
48+
path: ${{ env.NODE_CACHE }}
49+
key: node-cache-${{ runner.os }}-${{ env.ARCH }}-${{ env.PACKAGE_MANAGER }}-${{ hashFiles(env.LOCK_PATTERN) }}
50+
# Install dependencies based on detected package manager
51+
- name: Install dependencies
52+
shell: bash
53+
run: npm ci # npm: npm ci | yarn: yarn install --frozen-lockfile | pnpm: pnpm install --frozen-lockfile

0 commit comments

Comments
 (0)