Skip to content

Commit 8be321a

Browse files
Update test-cache-restore.yml
1 parent 3ecba94 commit 8be321a

File tree

1 file changed

+41
-62
lines changed

1 file changed

+41
-62
lines changed
Lines changed: 41 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Validate corrupted Node.js SDK
1+
name: Validate Node.js
22

33
on:
44
workflow_dispatch:
@@ -8,99 +8,78 @@ jobs:
88
runs-on: ${{ matrix.os }}
99

1010
strategy:
11+
fail-fast: false
1112
matrix:
1213
os: [ubuntu-latest, macos-latest, windows-latest]
14+
package-manager: [npm, pnpm, yarn]
1315

1416
steps:
15-
# Checkout repository
1617
- uses: actions/checkout@v6
1718

18-
# Setup Node.js
1919
- name: Setup Node.js
2020
uses: actions/setup-node@v6
2121
with:
2222
node-version: '21'
2323

24-
# Setup pnpm only when pnpm-lock.yaml exists
24+
# Setup pnpm only when selected
2525
- name: Setup pnpm
26-
if: hashFiles('pnpm-lock.yaml') != ''
26+
if: matrix.package-manager == 'pnpm'
2727
uses: pnpm/action-setup@v4
2828
with:
2929
version: 10
30-
run_install: false
30+
3131

32-
# Normalize runner architecture (x64 / arm64)
32+
# Normalize runner architecture
3333
- name: Normalize runner architecture
3434
shell: bash
3535
run: |
3636
echo "ARCH=$(echo '${{ runner.arch }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
3737
38-
# Detect package manager and its cache path
39-
- name: Detect package manager and cache path
38+
# Validate lockfile & define cache path
39+
- name: Configure package manager
4040
shell: bash
4141
run: |
4242
set -e
4343
44-
if [ -f pnpm-lock.yaml ]; then
45-
PACKAGE_MANAGER=pnpm
46-
CACHE_PATH=$(pnpm store path)
47-
LOCK_PATTERN="**/pnpm-lock.yaml"
48-
elif [ -f yarn.lock ]; then
49-
PACKAGE_MANAGER=yarn
50-
CACHE_PATH=$(yarn cache dir)
51-
LOCK_PATTERN="**/yarn.lock"
52-
else
53-
PACKAGE_MANAGER=npm
54-
CACHE_PATH=$(npm config get cache)
55-
LOCK_PATTERN="**/package-lock.json"
56-
fi
44+
case "${{ matrix.package-manager }}" in
45+
pnpm)
46+
[ -f pnpm-lock.yaml ] || { echo "pnpm-lock.yaml not found"; exit 1; }
47+
echo "NODE_CACHE=$(pnpm store path)" >> $GITHUB_ENV
48+
echo "LOCKFILE=pnpm-lock.yaml" >> $GITHUB_ENV
49+
;;
50+
yarn)
51+
[ -f yarn.lock ] || { echo "yarn.lock not found"; exit 1; }
52+
echo "NODE_CACHE=$(yarn cache dir)" >> $GITHUB_ENV
53+
echo "LOCKFILE=yarn.lock" >> $GITHUB_ENV
54+
;;
55+
npm)
56+
[ -f package-lock.json ] || { echo "package-lock.json not found"; exit 1; }
57+
echo "NODE_CACHE=$(npm config get cache)" >> $GITHUB_ENV
58+
echo "LOCKFILE=package-lock.json" >> $GITHUB_ENV
59+
;;
60+
esac
5761
58-
echo "PACKAGE_MANAGER=$PACKAGE_MANAGER" >> $GITHUB_ENV
59-
echo "NODE_CACHE=$CACHE_PATH" >> $GITHUB_ENV
60-
echo "LOCK_PATTERN=$LOCK_PATTERN" >> $GITHUB_ENV
62+
echo "PACKAGE_MANAGER=${{ matrix.package-manager }}" >> $GITHUB_ENV
6163
62-
# Debug resolved values
63-
- name: Debug cache variables
64-
shell: bash
65-
run: |
66-
echo "OS=${{ runner.os }}"
67-
echo "ARCH=$ARCH"
68-
echo "PACKAGE_MANAGER=$PACKAGE_MANAGER"
69-
echo "NODE_CACHE=$NODE_CACHE"
70-
echo "LOCK_PATTERN=$LOCK_PATTERN"
71-
72-
# Restore dependency cache using a unified key format
64+
# Restore cache
7365
- name: Restore Node cache
7466
uses: actions/cache/restore@v5
7567
with:
7668
path: ${{ env.NODE_CACHE }}
77-
key: node-cache-${{ runner.os }}-${{ env.ARCH }}-${{ env.PACKAGE_MANAGER }}-${{ hashFiles(env.LOCK_PATTERN) }}
69+
key: node-cache-${{ runner.os }}-${{ env.ARCH }}-${{ env.PACKAGE_MANAGER }}-${{ hashFiles(env.LOCKFILE) }}
7870

79-
# Install dependencies based on detected package manager
71+
# Install dependencies
8072
- name: Install dependencies
8173
shell: bash
8274
run: |
83-
if [ "$PACKAGE_MANAGER" = "pnpm" ]; then
84-
if pnpm install --frozen-lockfile; then
85-
echo "pnpm frozen-lockfile install succeeded"
86-
else
87-
echo "pnpm lockfile incompatible — retrying without frozen-lockfile"
88-
pnpm install --no-frozen-lockfile
89-
fi
90-
elif [ "$PACKAGE_MANAGER" = "yarn" ]; then
91-
yarn install --frozen-lockfile
92-
else
93-
npm ci
94-
fi
95-
96-
# Run build script if present
97-
- name: Build
98-
shell: bash
99-
run: |
100-
if [ "$PACKAGE_MANAGER" = "pnpm" ]; then
101-
pnpm run build
102-
elif [ "$PACKAGE_MANAGER" = "yarn" ]; then
103-
yarn build
104-
else
105-
npm run build --if-present
106-
fi
75+
case "$PACKAGE_MANAGER" in
76+
pnpm)
77+
pnpm install --frozen-lockfile || pnpm install --no-frozen-lockfile
78+
;;
79+
yarn)
80+
yarn install --frozen-lockfile
81+
;;
82+
npm)
83+
npm ci
84+
;;
85+
esac

0 commit comments

Comments
 (0)