Validate corrupted Node.js #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Validate corrupted Node.js SDK | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Setup Node.js | |
| id: setup-node | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '21' | |
| cache: false | |
| # Normalize runner.arch to lowercase (same as Go) | |
| - name: Normalize runner architecture (Linux/macOS) | |
| if: runner.os != 'Windows' | |
| shell: bash | |
| run: | | |
| echo "ARCH=$(echo '${{ runner.arch }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
| - name: Normalize runner architecture (Windows) | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: | | |
| $arch = "${{ runner.arch }}".ToLower() | |
| echo "ARCH=$arch" | Out-File $env:GITHUB_ENV -Append | |
| # Detect package-manager and cache location (Node equivalent of `go env`) | |
| - name: Set Node cache variables | |
| shell: bash | |
| run: | | |
| const fs = require('fs'); | |
| const { execSync } = require('child_process'); | |
| let cache; | |
| if (fs.existsSync('pnpm-lock.yaml')) { | |
| cache = execSync('pnpm store path').toString().trim(); | |
| } else if (fs.existsSync('yarn.lock')) { | |
| cache = execSync('yarn cache dir').toString().trim(); | |
| } else { | |
| cache = execSync('npm config get cache').toString().trim(); | |
| } | |
| fs.appendFileSync(process.env.GITHUB_ENV, `NODE_CACHE=${cache}\n`); | |
| # Restore Node cache (mirrors Restore Go cache) | |
| - name: Restore Node cache | |
| id: node-cache | |
| uses: actions/cache/restore@v5 | |
| with: | |
| path: ${{ env.NODE_CACHE }} | |
| key: setup-node-${{ runner.os }}-${{ env.ARCH }}-node-${{ steps.setup-node.outputs.node-version }}-${{ hashFiles('**/*lock*') }} | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build | |
| run: npm run build --if-present | |