@@ -12,46 +12,54 @@ jobs:
1212 os : [ubuntu-latest, macos-latest, windows-latest]
1313
1414 steps :
15+ # Checkout repository
1516 - uses : actions/checkout@v6
17+
18+ # Setup Node.js
1619 - name : Setup Node.js
1720 uses : actions/setup-node@v6
1821 with :
1922 node-version : ' 21'
2023
24+ # Setup pnpm only when pnpm-lock.yaml exists
2125 - name : Setup pnpm
2226 if : hashFiles('pnpm-lock.yaml') != ''
2327 uses : pnpm/action-setup@v4
2428 with :
2529 version : 10
2630 run_install : false
2731
32+ # Normalize runner architecture (x64 / arm64)
2833 - name : Normalize runner architecture
2934 shell : bash
3035 run : |
3136 echo "ARCH=$(echo '${{ runner.arch }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
3237
38+ # Detect package manager and its cache path
3339 - name : Detect package manager and cache path
3440 shell : bash
3541 run : |
3642 set -e
3743
3844 if [ -f pnpm-lock.yaml ]; then
39- PM =pnpm
45+ PACKAGE_MANAGER =pnpm
4046 CACHE_PATH=$(pnpm store path)
4147 LOCK_PATTERN="**/pnpm-lock.yaml"
4248 elif [ -f yarn.lock ]; then
43- PM =yarn
49+ PACKAGE_MANAGER =yarn
4450 CACHE_PATH=$(yarn cache dir)
4551 LOCK_PATTERN="**/yarn.lock"
4652 else
47- PM =npm
53+ PACKAGE_MANAGER =npm
4854 CACHE_PATH=$(npm config get cache)
4955 LOCK_PATTERN="**/package-lock.json"
5056 fi
5157
52- echo "PACKAGE_MANAGER=$PM " >> $GITHUB_ENV
58+ echo "PACKAGE_MANAGER=$PACKAGE_MANAGER " >> $GITHUB_ENV
5359 echo "NODE_CACHE=$CACHE_PATH" >> $GITHUB_ENV
5460 echo "LOCK_PATTERN=$LOCK_PATTERN" >> $GITHUB_ENV
61+
62+ # Debug resolved values
5563 - name : Debug cache variables
5664 shell : bash
5765 run : |
@@ -61,12 +69,14 @@ jobs:
6169 echo "NODE_CACHE=$NODE_CACHE"
6270 echo "LOCK_PATTERN=$LOCK_PATTERN"
6371
72+ # Restore dependency cache using a unified key format
6473 - name : Restore Node cache
6574 uses : actions/cache/restore@v5
6675 with :
6776 path : ${{ env.NODE_CACHE }}
6877 key : node-cache-${{ runner.os }}-${{ env.ARCH }}-${{ env.PACKAGE_MANAGER }}-${{ hashFiles(env.LOCK_PATTERN) }}
6978
79+ # Install dependencies based on detected package manager
7080 - name : Install dependencies
7181 shell : bash
7282 run : |
8292 else
8393 npm ci
8494 fi
95+
96+ # Run build script if present
8597 - name : Build
8698 shell : bash
8799 run : |
0 commit comments