|
1 | | -name: Playwright Tests |
| 1 | +name: Playwright Accessibility Tests |
| 2 | + |
2 | 3 | on: |
3 | | - push: |
4 | | - branches: [ main ] |
5 | 4 | pull_request: |
6 | | - branches: [ main ] |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
7 | 7 | jobs: |
8 | | - test: |
| 8 | + playwright: |
| 9 | + name: Playwright |
| 10 | + runs-on: ubuntu-latest |
9 | 11 | timeout-minutes: 60 |
| 12 | + outputs: |
| 13 | + issue_count: ${{ steps.playwright.outputs.issue_count }} |
| 14 | + steps: |
| 15 | + - name: Checkout repository from GitHub |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Setup Node |
| 19 | + uses: actions/setup-node@v4 |
| 20 | + with: |
| 21 | + node-version: 20 |
| 22 | + |
| 23 | + - name: Install dependencies |
| 24 | + run: npm ci |
| 25 | + |
| 26 | + - name: Install Playwright Browsers |
| 27 | + run: npx playwright install --with-deps |
| 28 | + |
| 29 | + - name: Build app |
| 30 | + run: npm run build |
| 31 | + |
| 32 | + - name: Serve preview |
| 33 | + run: npm run preview & npx wait-on http://localhost:4173 |
| 34 | + |
| 35 | + - name: Run Playwright tests |
| 36 | + run: npx playwright test || true |
| 37 | + |
| 38 | + - name: Count Playwright accessibility issues |
| 39 | + id: playwright |
| 40 | + run: | |
| 41 | + issue_count=$(jq '. | length' playwright-a11y-violations.json) |
| 42 | + echo "issue_count=$issue_count" >> $GITHUB_OUTPUT |
| 43 | +
|
| 44 | + - name: Upload report artifact |
| 45 | + uses: actions/upload-artifact@v4 |
| 46 | + if: ${{ !cancelled() }} |
| 47 | + with: |
| 48 | + name: playwright-report |
| 49 | + path: playwright-report/ |
| 50 | + retention-days: 30 |
| 51 | + |
| 52 | + comment-on-pr: |
| 53 | + needs: playwright |
| 54 | + if: needs.playwright.outputs.issue_count != '0' |
10 | 55 | runs-on: ubuntu-latest |
11 | 56 | steps: |
12 | | - - uses: actions/checkout@v4 |
13 | | - - uses: actions/setup-node@v4 |
14 | | - with: |
15 | | - node-version: lts/* |
16 | | - - name: Install dependencies |
17 | | - run: npm ci |
18 | | - - name: Install Playwright Browsers |
19 | | - run: npx playwright install --with-deps |
20 | | - - name: Run Playwright tests |
21 | | - run: npx playwright test |
22 | | - - uses: actions/upload-artifact@v4 |
23 | | - if: ${{ !cancelled() }} |
24 | | - with: |
25 | | - name: playwright-report |
26 | | - path: playwright-report/ |
27 | | - retention-days: 30 |
| 57 | + - name: Comment on PR |
| 58 | + uses: thollander/actions-comment-pull-request@v3 |
| 59 | + with: |
| 60 | + message: "♿ Playwright detected ${{ needs.playwright.outputs.issue_count }} accessibility issue(s) – please review [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})." |
| 61 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments