|
1 | | -name: Test Node.js Dependencies (Cache Restore Only) |
| 1 | +name: Validate corrupted Node.js SDK |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | workflow_dispatch: |
|
9 | 9 | strategy: |
10 | 10 | matrix: |
11 | 11 | os: [ubuntu-latest, macos-latest, windows-latest] |
12 | | - node-version: [21] |
13 | | - package-manager: [npm, pnpm, yarn] |
14 | 12 |
|
15 | 13 | steps: |
16 | | - # Checkout code |
17 | 14 | - uses: actions/checkout@v6 |
18 | 15 |
|
19 | | - # Setup Node.js without automatic caching |
20 | 16 | - name: Setup Node.js |
| 17 | + id: setup-node |
21 | 18 | uses: actions/setup-node@v6 |
22 | 19 | with: |
23 | | - node-version: ${{ matrix.node-version }} |
24 | | - package-manager-cache: false |
| 20 | + node-version: '21' |
| 21 | + package-manager-cache: true # IMPORTANT |
25 | 22 |
|
26 | | - # Normalize runner architecture |
| 23 | + # Normalize arch |
27 | 24 | - name: Normalize runner architecture |
28 | 25 | shell: bash |
29 | 26 | run: | |
30 | 27 | echo "ARCH=$(echo '${{ runner.arch }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV |
31 | | -
|
32 | | - # Determine cache path per package manager |
| 28 | + # Node equivalent of `go env GOMODCACHE` |
33 | 29 | - name: Set Node cache path |
34 | | - id: cache-path |
| 30 | + if: runner.os != 'Windows' |
35 | 31 | shell: bash |
36 | 32 | run: | |
37 | | - if [ "${{ matrix.package-manager }}" = "npm" ]; then |
38 | | - echo "node_cache_path=$(npm config get cache)" >> $GITHUB_OUTPUT |
39 | | - elif [ "${{ matrix.package-manager }}" = "pnpm" ]; then |
40 | | - echo "node_cache_path=$(pnpm store path)" >> $GITHUB_OUTPUT |
41 | | - elif [ "${{ matrix.package-manager }}" = "yarn" ]; then |
42 | | - echo "node_cache_path=$(yarn cache dir)" >> $GITHUB_OUTPUT |
43 | | - fi |
44 | | -
|
45 | | -
|
46 | | - # Debug cache env |
47 | | - - name: Debug cache environment |
| 33 | + 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 |
48 | 41 | run: | |
49 | 42 | echo "ARCH=$ARCH" |
50 | 43 | echo "NODE_CACHE=$NODE_CACHE" |
51 | | - echo "Package Manager: ${{ matrix.package-manager }}" |
52 | | -
|
53 | 44 | - name: Restore Node cache |
54 | 45 | uses: actions/cache/restore@v5 |
55 | 46 | with: |
56 | | - path: ${{ steps.cache-path.outputs.node_cache_path }} |
57 | | - key: node-cache-${{ runner.os }}-${{ env.ARCH }}-${{ matrix.package-manager }}-${{ hashFiles('**/package-lock.json','**/npm-shrinkwrap.json','**/pnpm-lock.yaml','**/yarn.lock') }} |
| 47 | + path: ${{ env.NODE_CACHE }} |
| 48 | + key: node-cache-${{ runner.os }}-${{ env.ARCH }}-pnpm-${{ hashFiles('**/package-lock.json', '**/npm-shrinkwrap.json') }} |
58 | 49 |
|
59 | | - # Install dependencies |
60 | 50 | - name: Install dependencies |
61 | | - shell: bash |
62 | | - run: | |
63 | | - if [ "${{ matrix.package-manager }}" = "npm" ]; then |
64 | | - npm ci |
65 | | - elif [ "${{ matrix.package-manager }}" = "pnpm" ]; then |
66 | | - pnpm install |
67 | | - elif [ "${{ matrix.package-manager }}" = "yarn" ]; then |
68 | | - yarn install --frozen-lockfile |
69 | | - fi |
| 51 | + run: npm ci |
70 | 52 |
|
71 | | - # Build |
72 | 53 | - name: Build |
73 | | - shell: bash |
74 | | - run: | |
75 | | - if [ "${{ matrix.package-manager }}" = "npm" ]; then |
76 | | - npm run build --if-present |
77 | | - elif [ "${{ matrix.package-manager }}" = "pnpm" ]; then |
78 | | - pnpm run build --if-present |
79 | | - elif [ "${{ matrix.package-manager }}" = "yarn" ]; then |
80 | | - yarn build || true |
81 | | - fi |
| 54 | + run: npm run build --if-present |
0 commit comments