ci: Run tests for workspace packages in parallel and as dedicated jobs #1030
Workflow file for this run
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: Tests | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| jobs: | |
| discover: | |
| name: Discover workspaces | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| workspaces: ${{ steps.find.outputs.workspaces }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Find workspaces with unit tests | |
| id: find | |
| run: | | |
| workspaces=$(node -e " | |
| const {readFileSync, readdirSync, existsSync} = require('fs'); | |
| const {join} = require('path'); | |
| const root = JSON.parse(readFileSync('package.json', 'utf8')); | |
| const dirs = root.workspaces.flatMap(pattern => { | |
| const base = pattern.replace('/*', ''); | |
| if (!existsSync(base)) return []; | |
| return readdirSync(base, {withFileTypes: true}) | |
| .filter(d => d.isDirectory()) | |
| .map(d => join(base, d.name)); | |
| }); | |
| const names = dirs | |
| .filter(d => { | |
| const p = join(d, 'package.json'); | |
| if (!existsSync(p)) return false; | |
| const pkg = JSON.parse(readFileSync(p, 'utf8')); | |
| return Boolean(pkg.scripts && pkg.scripts.unit); | |
| }) | |
| .map(d => JSON.parse(readFileSync(join(d, 'package.json'), 'utf8')).name); | |
| console.log(JSON.stringify(names)); | |
| ") | |
| echo "workspaces=$workspaces" >> "$GITHUB_OUTPUT" | |
| unit: | |
| name: "${{ matrix.workspace }} (Node ${{ matrix.version }}, ${{ matrix.os }})" | |
| needs: discover | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| version: [22, 24] | |
| os: [ubuntu-24.04, windows-2025, macos-15] | |
| workspace: ${{ fromJSON(needs.discover.outputs.workspaces) }} | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: ${{ matrix.version }} | |
| # This is needed as npm 11 has issues with running "npm ci" on projects that use "overrides" | |
| - name: Install recent npm version (Node 24 only) | |
| if: matrix.version == 24 | |
| run: npm install -g npm@11 && npm --version | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run unit tests | |
| run: npm run unit --workspace=${{ matrix.workspace }} | |
| ci: | |
| name: CI | |
| needs: [unit] | |
| if: always() | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - run: exit 1 | |
| if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') |