|
3 | 3 | on: |
4 | 4 | pull_request: |
5 | 5 | branches: [develop, main] |
6 | | - push: |
7 | | - branches: [develop] |
8 | 6 |
|
9 | 7 | jobs: |
10 | 8 | ci: |
|
30 | 28 |
|
31 | 29 | - name: Test |
32 | 30 | run: pnpm test:run |
| 31 | + |
| 32 | + lighthouse: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + permissions: |
| 35 | + issues: write |
| 36 | + pull-requests: write |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v6 |
| 39 | + |
| 40 | + - uses: pnpm/action-setup@v5 |
| 41 | + |
| 42 | + - uses: actions/setup-node@v6 |
| 43 | + with: |
| 44 | + node-version: 22 |
| 45 | + cache: pnpm |
| 46 | + |
| 47 | + - name: Install dependencies |
| 48 | + run: pnpm install --frozen-lockfile |
| 49 | + |
| 50 | + # No NUXT_APP_BASE_URL here — Lighthouse audits the site at root, |
| 51 | + # unlike deploy.yml which prefixes /clearance-website/ for GitHub Pages. |
| 52 | + - name: Generate static site |
| 53 | + run: pnpm generate |
| 54 | + |
| 55 | + - name: Lighthouse CI |
| 56 | + id: lhci |
| 57 | + uses: treosh/lighthouse-ci-action@v12 |
| 58 | + if: always() |
| 59 | + with: |
| 60 | + configPath: ./lighthouserc.cjs |
| 61 | + |
| 62 | + - name: Comment Lighthouse results on PR |
| 63 | + if: always() && github.event_name == 'pull_request' && steps.lhci.outputs.resultsPath != '' |
| 64 | + env: |
| 65 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 66 | + RESULTS_PATH: ${{ steps.lhci.outputs.resultsPath }} |
| 67 | + LINKS: ${{ steps.lhci.outputs.links }} |
| 68 | + run: | |
| 69 | + MANIFEST="$RESULTS_PATH/manifest.json" |
| 70 | + if [ ! -f "$MANIFEST" ]; then exit 0; fi |
| 71 | +
|
| 72 | + COMMENT=$(jq -r ' |
| 73 | + "## Lighthouse Report\n\n| URL | Performance | Accessibility | Best Practices | SEO |\n|-----|:-----------:|:------------:|:--------------:|:---:|", |
| 74 | + ( |
| 75 | + [ .[] | select(.isRepresentativeRun == true) ] | |
| 76 | + .[] | |
| 77 | + "| `\(.url | split("//")[1] | split("/")[1:] | "/" + join("/"))` | \((.summary.performance // 0) * 100 | round) | \((.summary.accessibility // 0) * 100 | round) | \((.summary["best-practices"] // 0) * 100 | round) | \((.summary.seo // 0) * 100 | round) |" |
| 78 | + ) |
| 79 | + ' "$MANIFEST") |
| 80 | +
|
| 81 | + if [ -n "$LINKS" ]; then |
| 82 | + COMMENT+=$'\n\n'"**Report links:** ${LINKS}" |
| 83 | + fi |
| 84 | +
|
| 85 | + echo "$COMMENT" | gh pr comment "${{ github.event.pull_request.number }}" --body-file - |
| 86 | +
|
| 87 | + - name: Create issue on Lighthouse regression |
| 88 | + if: always() && steps.lhci.outcome == 'failure' && steps.lhci.outputs.resultsPath != '' |
| 89 | + env: |
| 90 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + RESULTS_PATH: ${{ steps.lhci.outputs.resultsPath }} |
| 92 | + LINKS: ${{ steps.lhci.outputs.links }} |
| 93 | + run: | |
| 94 | + if [ ! -f "$RESULTS_PATH/assertion-results.json" ]; then |
| 95 | + echo "No assertion results found — LHCI likely crashed during collection." |
| 96 | + exit 0 |
| 97 | + fi |
| 98 | +
|
| 99 | + REPORT=$(jq -r ' |
| 100 | + .[] | select(.level == "error" or .level == "warn") | |
| 101 | + "- **\(.level)**: \(.auditId // .name) — score \(.actual) (expected ≥ \(.expected))" |
| 102 | + ' "$RESULTS_PATH/assertion-results.json") |
| 103 | +
|
| 104 | + gh issue create \ |
| 105 | + --title "Lighthouse regression detected on $(date +%Y-%m-%d)" \ |
| 106 | + --label "lighthouse" \ |
| 107 | + --assignee wazolab \ |
| 108 | + --body "$(cat <<EOF |
| 109 | + ## Lighthouse CI failed |
| 110 | +
|
| 111 | + **Run:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 112 | + **Commit:** \`${{ github.sha }}\` |
| 113 | + **Branch:** \`${{ github.ref_name }}\` |
| 114 | +
|
| 115 | + ### Failures |
| 116 | +
|
| 117 | + ${REPORT} |
| 118 | +
|
| 119 | + ### Report links |
| 120 | +
|
| 121 | + ${LINKS} |
| 122 | + EOF |
| 123 | + )" |
0 commit comments