ci: skip Playwright merge job when E2E job is skipped (#196) #345
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: E2E Tests | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| concurrency: | |
| group: e2e-${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| direct_push_check: | |
| name: Detect direct push to main | |
| runs-on: ubuntu-latest | |
| outputs: | |
| is_direct: ${{ steps.detect.outputs.is_direct }} | |
| steps: | |
| - name: Determine if commit belongs to a PR | |
| id: detect | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| if (context.eventName !== 'push' || context.ref !== 'refs/heads/main') { | |
| // Only `push` to `main` needs direct-vs-merge detection. | |
| core.setOutput('is_direct', 'false') | |
| return | |
| } | |
| const sha = context.sha | |
| // If this commit is associated with any PR, it's almost certainly coming from a PR merge. | |
| // Direct pushes to main won't have associated PRs. | |
| const { data } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| commit_sha: sha, | |
| }) | |
| core.setOutput('is_direct', String(data.length === 0)) | |
| e2e: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: mcr.microsoft.com/playwright:v1.57.0-jammy | |
| options: --ipc=host | |
| needs: [direct_push_check] | |
| if: | | |
| github.event_name == 'pull_request' || | |
| (github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.direct_push_check.outputs.is_direct == 'true') | |
| env: | |
| # Playwright's Firefox won't launch in the container unless $HOME is owned by the current user. | |
| HOME: /root | |
| timeout-minutes: 45 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - browser: chromium | |
| shardIndex: 1 | |
| shardTotal: 2 | |
| - browser: chromium | |
| shardIndex: 2 | |
| shardTotal: 2 | |
| - browser: firefox | |
| shardIndex: 1 | |
| shardTotal: 2 | |
| - browser: firefox | |
| shardIndex: 2 | |
| shardTotal: 2 | |
| # WebKit is consistently slower; split into more shards so no single job dominates. | |
| - browser: webkit | |
| shardIndex: 1 | |
| shardTotal: 3 | |
| - browser: webkit | |
| shardIndex: 2 | |
| shardTotal: 3 | |
| - browser: webkit | |
| shardIndex: 3 | |
| shardTotal: 3 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Install unzip | |
| run: apt-get update && apt-get install -y unzip | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Cache Bun install + node_modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.bun/install/cache | |
| node_modules | |
| key: ${{ runner.os }}-bun-${{ hashFiles('bun.lock') }} | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: Build app | |
| run: bun run build | |
| - name: Run E2E tests (headless) | |
| env: | |
| CI: true | |
| E2E_BROWSERS: ${{ matrix.browser }} | |
| run: bun run test:e2e -- --project=${{ matrix.browser }} --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} | |
| - name: Upload Playwright blob report | |
| if: always() | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: playwright-blob-${{ matrix.browser }}-${{ matrix.shardIndex }}of${{ matrix.shardTotal }} | |
| path: blob-report/ | |
| if-no-files-found: ignore | |
| e2e_report: | |
| name: Merge Playwright report | |
| runs-on: ubuntu-latest | |
| # Skip when `e2e` did not run (e.g. merge push to main); merge-reports fails with no blob artifacts. | |
| if: ${{ !cancelled() && (needs.e2e.result == 'success' || needs.e2e.result == 'failure') }} | |
| needs: [direct_push_check, e2e] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Install unzip | |
| run: sudo apt-get update && sudo apt-get install -y unzip | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Cache Bun install + node_modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.bun/install/cache | |
| node_modules | |
| key: ${{ runner.os }}-bun-${{ hashFiles('bun.lock') }} | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: Download all blob reports | |
| uses: actions/download-artifact@v6 | |
| with: | |
| pattern: playwright-blob-* | |
| path: playwright-blobs | |
| merge-multiple: true | |
| - name: Merge HTML report | |
| run: bunx playwright merge-reports --reporter=html playwright-blobs | |
| - name: Upload Playwright HTML report | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: playwright-report | |
| path: playwright-report/ | |
| if-no-files-found: ignore |