Validate Node.js #39
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 Node.js | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| package-manager: [npm, pnpm, yarn] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '21' | |
| # Setup pnpm only when selected | |
| - name: Setup pnpm | |
| if: matrix.package-manager == 'pnpm' | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| # Normalize runner architecture | |
| - name: Normalize runner architecture | |
| shell: bash | |
| run: | | |
| echo "ARCH=$(echo '${{ runner.arch }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
| # Validate lockfile & define cache path | |
| - name: Configure package manager | |
| shell: bash | |
| run: | | |
| set -e | |
| case "${{ matrix.package-manager }}" in | |
| pnpm) | |
| [ -f pnpm-lock.yaml ] || { echo "pnpm-lock.yaml not found"; exit 1; } | |
| echo "NODE_CACHE=$(pnpm store path)" >> $GITHUB_ENV | |
| echo "LOCKFILE=pnpm-lock.yaml" >> $GITHUB_ENV | |
| ;; | |
| yarn) | |
| [ -f yarn.lock ] || { echo "yarn.lock not found"; exit 1; } | |
| echo "NODE_CACHE=$(yarn cache dir)" >> $GITHUB_ENV | |
| echo "LOCKFILE=yarn.lock" >> $GITHUB_ENV | |
| ;; | |
| npm) | |
| [ -f package-lock.json ] || { echo "package-lock.json not found"; exit 1; } | |
| echo "NODE_CACHE=$(npm config get cache)" >> $GITHUB_ENV | |
| echo "LOCKFILE=package-lock.json" >> $GITHUB_ENV | |
| ;; | |
| esac | |
| echo "PACKAGE_MANAGER=${{ matrix.package-manager }}" >> $GITHUB_ENV | |
| # Restore cache | |
| - name: Restore Node cache | |
| uses: actions/cache/restore@v5 | |
| with: | |
| path: ${{ env.NODE_CACHE }} | |
| key: node-cache-${{ runner.os }}-${{ env.ARCH }}-${{ env.PACKAGE_MANAGER }}-${{ hashFiles(env.LOCKFILE) }} | |
| # Install dependencies | |
| - name: Install dependencies | |
| shell: bash | |
| run: | | |
| case "$PACKAGE_MANAGER" in | |
| pnpm) | |
| pnpm install --frozen-lockfile || pnpm install --no-frozen-lockfile | |
| ;; | |
| yarn) | |
| yarn install --frozen-lockfile | |
| ;; | |
| npm) | |
| npm ci | |
| ;; | |
| esac |