test(playwright): add setup-demo accessibility e2e #101
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: Accessibility tests | ||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| pull_request: | ||
| branches: [ main ] | ||
| jobs: | ||
| accessibility: | ||
| runs-on: ubuntu-22.04 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Use Node.js 20 | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| - name: Install dependencies | ||
| run: npm ci | ||
| - name: Install Playwright browsers | ||
| run: npx playwright install --with-deps | ||
| - name: Build site | ||
| run: npm run build | ||
| - name: Force checkout latest commit | ||
| if: always() | ||
| run: | | ||
| # Ensure runner uses the exact commit we pushed (deterministic script version) | ||
| git fetch --no-tags origin "${{ github.sha }}" | ||
| git checkout "${{ github.sha }}" | ||
| - name: Verify service worker presence | ||
| if: always() | ||
| run: | | ||
| echo "VERIFY-SW: start" | ||
| if [ -f dist/service-worker.js ]; then | ||
| echo "VERIFY-SW: SW present" | ||
| else | ||
| echo "VERIFY-SW: MISSING" | ||
| ls -la dist || true | ||
| exit 1 | ||
| fi | ||
| - name: Serve built site (SPA fallback) | ||
| run: npx serve -s dist -l 5173 & | ||
| - name: Wait for server to be ready | ||
| run: | | ||
| echo "Waiting for http://127.0.0.1:5173 to return 200..." | ||
| for i in {1..60}; do | ||
| if curl -sSf http://127.0.0.1:5173 > /dev/null; then | ||
| echo "server ready" | ||
| exit 0 | ||
| fi | ||
| sleep 1 | ||
| done | ||
| echo "server did not become ready in time" | ||
| exit 1 | ||
| - name: Run debug accessibility capture (guarantee artifacts) | ||
| run: | | ||
| echo "Running debug capture test to ensure playwright-report has artifacts" | ||
| npx playwright test tests/accessibility/debug.spec.ts --project=chromium --reporter=list --timeout=300000 || true | ||
| - name: Run accessibility tests (Playwright + axe) | ||
| run: npm run test:accessibility | ||
| - name: Ensure playwright-report exists and list contents (debug) | ||
| if: always() | ||
| run: | | ||
| echo "Ensuring playwright-report exists and listing contents" | ||
| mkdir -p playwright-report | ||
| # if empty, write a placeholder so upload action finds at least one file | ||
| if [ -z "$(ls -A playwright-report 2>/dev/null)" ]; then echo "placeholder" > playwright-report/placeholder.txt; fi | ||
| ls -la playwright-report || true | ||
| - name: Upload Playwright report | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: playwright-report | ||
| path: playwright-report | ||
| - name: Debug: Confirm script version and commit | ||
| if: always() | ||
| run: | | ||
| echo "Commit SHA:" | ||
| git rev-parse --short HEAD | ||
| echo "Python version:" | ||
| python3 -V | ||
| echo "Script head:" | ||
| head -n 20 scripts/monitor_a11y_ci.py || true | ||
| echo "Monitor help output:" | ||
| python3 scripts/monitor_a11y_ci.py --help || true | ||
| - name: Post accessibility comment | ||
| if: always() | ||
| run: | | ||
| # Use local playwright-report (already present on runner) so monitor doesn't try to download artifact | ||
| # Determine a branch to use: prefer github.head_ref (PR), fallback to github.ref_name (push/workflow_dispatch) | ||
| BRANCH="${{ github.head_ref }}" | ||
| if [ -z "$BRANCH" ]; then BRANCH="${{ github.ref_name }}"; fi | ||
| echo "Using branch: $BRANCH" | ||
| python3 scripts/monitor_a11y_ci.py --branch "$BRANCH" --auto-comment --local-report-dir playwright-report | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||