@@ -18,37 +18,73 @@ jobs:
1818 uses : actions/setup-node@v6
1919 with :
2020 node-version : ' 21'
21- package-manager-cache : true # IMPORTANT
21+
2222
23- # Normalize arch
23+ # Normalize runner. arch (x64 / arm64)
2424 - name : Normalize runner architecture
2525 shell : bash
2626 run : |
2727 echo "ARCH=$(echo '${{ runner.arch }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
28- # Node equivalent of `go env GOMODCACHE`
29- - name : Set Node cache path
30- if : runner.os != 'Windows'
28+
29+ # Detect package manager + cache path (Node equivalent of `go env`)
30+ - name : Detect package manager and cache path
3131 shell : bash
3232 run : |
3333 set -e
34- echo "NODE_CACHE=$(npm config get cache)" >> $GITHUB_ENV
35- - name : Set Node cache path (Windows)
36- if : runner.os == 'Windows'
37- shell : pwsh
38- run : |
39- "NODE_CACHE=$(npm config get cache)" | Out-File $env:GITHUB_ENV -Append
40- - name : Debug cache env
34+
35+ if [ -f pnpm-lock.yaml ]; then
36+ PM=pnpm
37+ CACHE_PATH=$(pnpm store path)
38+ LOCK_PATTERN="**/pnpm-lock.yaml"
39+ elif [ -f yarn.lock ]; then
40+ PM=yarn
41+ CACHE_PATH=$(yarn cache dir)
42+ LOCK_PATTERN="**/yarn.lock"
43+ else
44+ PM=npm
45+ CACHE_PATH=$(npm config get cache)
46+ LOCK_PATTERN="**/package-lock.json"
47+ fi
48+
49+ echo "PACKAGE_MANAGER=$PM" >> $GITHUB_ENV
50+ echo "NODE_CACHE=$CACHE_PATH" >> $GITHUB_ENV
51+ echo "LOCK_PATTERN=$LOCK_PATTERN" >> $GITHUB_ENV
52+
53+ - name : Debug cache variables
4154 run : |
55+ echo "OS=${{ runner.os }}"
4256 echo "ARCH=$ARCH"
57+ echo "PACKAGE_MANAGER=$PACKAGE_MANAGER"
4358 echo "NODE_CACHE=$NODE_CACHE"
59+ echo "LOCK_PATTERN=$LOCK_PATTERN"
60+
61+ # Restore Node cache (setup-go equivalent)
4462 - name : Restore Node cache
63+ id : node-cache
4564 uses : actions/cache/restore@v5
4665 with :
4766 path : ${{ env.NODE_CACHE }}
48- key : node-cache-${{ runner.os }}-${{ env.ARCH }}-pnpm -${{ hashFiles('**/pnpm-lock.yaml' ) }}
67+ key : node-cache-${{ runner.os }}-${{ env.ARCH }}-${{ env.PACKAGE_MANAGER }} -${{ hashFiles(env.LOCK_PATTERN ) }}
4968
69+ # Install dependencies (PM-aware)
5070 - name : Install dependencies
51- run : pnpm ci
71+ shell : bash
72+ run : |
73+ if [ "$PACKAGE_MANAGER" = "pnpm" ]; then
74+ pnpm install --frozen-lockfile
75+ elif [ "$PACKAGE_MANAGER" = "yarn" ]; then
76+ yarn install --frozen-lockfile
77+ else
78+ npm ci
79+ fi
5280
5381 - name : Build
54- run : pnpm run build
82+ shell : bash
83+ run : |
84+ if [ "$PACKAGE_MANAGER" = "pnpm" ]; then
85+ pnpm run build
86+ elif [ "$PACKAGE_MANAGER" = "yarn" ]; then
87+ yarn build
88+ else
89+ npm run build --if-present
90+ fi
0 commit comments