chore: improve workflow #8
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] | |
| workflow_dispatch: | |
| concurrency: | |
| group: tests-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| test: | |
| name: ${{ matrix.project }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| project: [chromium, firefox, webkit] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node 20 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - name: Install npm deps | |
| run: npm ci | |
| - name: Cache Playwright browsers | |
| id: playwright-cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/ms-playwright | |
| key: playwright-${{ runner.os }}-${{ matrix.project }}-${{ hashFiles('package-lock.json') }} | |
| - name: Install Playwright browser (${{ matrix.project }}) | |
| if: steps.playwright-cache.outputs.cache-hit != 'true' | |
| run: npx playwright install --with-deps ${{ matrix.project }} | |
| - name: Install Playwright system deps (when cache hit) | |
| if: steps.playwright-cache.outputs.cache-hit == 'true' | |
| run: npx playwright install-deps ${{ matrix.project }} | |
| - name: Lint and typecheck | |
| if: matrix.project == 'chromium' | |
| run: | | |
| npm run lint | |
| npm run typecheck | |
| - name: Run Playwright (${{ matrix.project }}) | |
| env: | |
| CI: 'true' | |
| SEED: '1234' | |
| run: npx playwright test --project=${{ matrix.project }} --reporter=list,html,json,junit | |
| - name: Upload HTML report | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: playwright-report-${{ matrix.project }} | |
| path: playwright-report/ | |
| retention-days: 14 | |
| - name: Upload traces and videos | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: traces-${{ matrix.project }} | |
| path: test-results/ | |
| retention-days: 7 | |
| sonar: | |
| name: SonarCloud | |
| needs: test | |
| runs-on: ubuntu-latest | |
| # SonarCloud rejects analyses on forks (no access to SONAR_TOKEN). Skip those gracefully. | |
| if: ${{ !github.event.pull_request.head.repo.fork && (github.event_name == 'push' || github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch') }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # full history required for blame-based new-code detection | |
| - name: Setup Node 20 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - name: Download Playwright JUnit XMLs | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: playwright-report-* | |
| path: playwright-report-merged | |
| merge-multiple: true | |
| - name: Move junit.xml into the path Sonar expects | |
| run: | | |
| mkdir -p playwright-report | |
| first_junit=$(find playwright-report-merged -name 'junit.xml' | head -1 || true) | |
| if [ -n "$first_junit" ]; then | |
| cp "$first_junit" playwright-report/junit.xml | |
| else | |
| echo "WARN: no junit.xml found in artefacts; Sonar will run without test-execution data." | |
| fi | |
| - name: SonarCloud Scan | |
| uses: SonarSource/sonarqube-scan-action@v3 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |