Validate Node.js #17
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: Test Node.js Dependencies (Cache Restore Only) | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| test: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| node-version: [18, 24] | |
| package-manager: [npm, pnpm, yarn] | |
| steps: | |
| # Checkout the repo | |
| - uses: actions/checkout@v5 | |
| # Setup Node.js without automatic caching | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: false # disable automatic caching | |
| # Determine cache path per package manager | |
| - name: Set cache path | |
| id: cache-path | |
| run: | | |
| if [ "${{ matrix.package-manager }}" = "npm" ]; then | |
| echo "CACHE_PATH=$(npm config get cache)" >> $GITHUB_ENV | |
| elif [ "${{ matrix.package-manager }}" = "pnpm" ]; then | |
| echo "CACHE_PATH=$(pnpm store path)" >> $GITHUB_ENV | |
| elif [ "${{ matrix.package-manager }}" = "yarn" ]; then | |
| echo "CACHE_PATH=$(yarn cache dir)" >> $GITHUB_ENV | |
| fi | |
| # Restore cache manually | |
| - name: Restore Package Manager Cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: ${{ env.CACHE_PATH }} | |
| key: node-cache-${{ runner.os }}-${{ matrix.package-manager }}-${{ hashFiles('**/package-lock.json', '**/npm-shrinkwrap.json', '**/pnpm-lock.yaml', '**/yarn.lock') }} | |
| restore-keys: | | |
| node-cache-${{ runner.os }}-${{ matrix.package-manager }}- | |
| # Install dependencies | |
| - name: Install Dependencies | |
| run: | | |
| if [ "${{ matrix.package-manager }}" = "npm" ]; then | |
| npm ci | |
| elif [ "${{ matrix.package-manager }}" = "pnpm" ]; then | |
| pnpm install | |
| elif [ "${{ matrix.package-manager }}" = "yarn" ]; then | |
| yarn install --frozen-lockfile | |
| fi | |
| # Run tests | |
| - name: Run Tests | |
| run: | | |
| if [ "${{ matrix.package-manager }}" = "npm" ]; then | |
| npm test | |
| elif [ "${{ matrix.package-manager }}" = "pnpm" ]; then | |
| pnpm test | |
| elif [ "${{ matrix.package-manager }}" = "yarn" ]; then | |
| yarn test | |
| fi |