From ddc7abc21ad3b12bca605ce91ed205c251d50a20 Mon Sep 17 00:00:00 2001 From: Jetshree Date: Sun, 22 Feb 2026 01:46:51 +0530 Subject: [PATCH 1/2] feat: integrate lighthouse-ci Signed-off-by: Jetshree --- .github/workflows/lighthouse-ci.yml | 128 ++++++++++++++++++++++++++++ .gitignore | 3 + .lighthouserc.json | 69 +++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 .github/workflows/lighthouse-ci.yml create mode 100644 .lighthouserc.json diff --git a/.github/workflows/lighthouse-ci.yml b/.github/workflows/lighthouse-ci.yml new file mode 100644 index 00000000..2e349d6d --- /dev/null +++ b/.github/workflows/lighthouse-ci.yml @@ -0,0 +1,128 @@ +name: Lighthouse CI + +on: + pull_request: + types: [opened, synchronize, reopened] + push: + branches: [main] + +jobs: + lighthouse: + name: Lighthouse Performance Audit + runs-on: ubuntu-latest + + permissions: + contents: read + pull-requests: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install just + uses: extractions/setup-just@v3 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" + cache: "npm" + + - name: Install dependencies + run: npm ci + + - name: Build project + run: just build-local + + - name: Ensure jq is installed + run: sudo apt-get update && sudo apt-get install -y jq + + - name: Run Lighthouse CI + id: lighthouse + run: npx @lhci/cli@0.14.x autorun --config=./.lighthouserc.json + + - name: Parse Lighthouse Results + id: parse + if: always() + run: | + REPORT_DIR=".lighthouseci" + MANIFEST="$REPORT_DIR/manifest.json" + + if [ -f "$MANIFEST" ]; then + PERF_SCORE=$(jq '[.[].summary.performance] | (add / length * 100) | floor' "$MANIFEST") + A11Y_SCORE=$(jq '[.[].summary.accessibility] | (add / length * 100) | floor' "$MANIFEST") + BP_SCORE=$(jq '[.[].summary["best-practices"]] | (add / length * 100) | floor' "$MANIFEST") + SEO_SCORE=$(jq '[.[].summary.seo] | (add / length * 100) | floor' "$MANIFEST") + + REPORT_URL=$(jq -r '.[0].links.publicUrl // "Not Available"' "$MANIFEST") + + echo "PERF_SCORE=$PERF_SCORE" >> $GITHUB_OUTPUT + echo "A11Y_SCORE=$A11Y_SCORE" >> $GITHUB_OUTPUT + echo "BP_SCORE=$BP_SCORE" >> $GITHUB_OUTPUT + echo "SEO_SCORE=$SEO_SCORE" >> $GITHUB_OUTPUT + echo "REPORT_URL=$REPORT_URL" >> $GITHUB_OUTPUT + else + echo "PERF_SCORE=N/A" >> $GITHUB_OUTPUT + echo "A11Y_SCORE=N/A" >> $GITHUB_OUTPUT + echo "BP_SCORE=N/A" >> $GITHUB_OUTPUT + echo "SEO_SCORE=N/A" >> $GITHUB_OUTPUT + echo "REPORT_URL=Not Available" >> $GITHUB_OUTPUT + fi + + - name: Get Score Emoji + id: emoji + if: always() + run: | + get_emoji() { + score=$1 + if [ "$score" = "N/A" ]; then + echo "⚪" + elif [ "$score" -ge 90 ]; then + echo "🟢" + elif [ "$score" -ge 50 ]; then + echo "🟠" + else + echo "🔴" + fi + } + + echo "PERF_EMOJI=$(get_emoji '${{ steps.parse.outputs.PERF_SCORE }}')" >> $GITHUB_OUTPUT + echo "A11Y_EMOJI=$(get_emoji '${{ steps.parse.outputs.A11Y_SCORE }}')" >> $GITHUB_OUTPUT + echo "BP_EMOJI=$(get_emoji '${{ steps.parse.outputs.BP_SCORE }}')" >> $GITHUB_OUTPUT + echo "SEO_EMOJI=$(get_emoji '${{ steps.parse.outputs.SEO_SCORE }}')" >> $GITHUB_OUTPUT + + - name: Comment on PR + if: github.event_name == 'pull_request' + uses: thollander/actions-comment-pull-request@v3 + with: + message: | + ## ⚡ Lighthouse Performance Report + + | Category | Score | Status | + |----------|-------|--------| + | Performance | **${{ steps.parse.outputs.PERF_SCORE }}** | ${{ steps.emoji.outputs.PERF_EMOJI }} | + | Accessibility | **${{ steps.parse.outputs.A11Y_SCORE }}** | ${{ steps.emoji.outputs.A11Y_EMOJI }} | + | Best Practices | **${{ steps.parse.outputs.BP_SCORE }}** | ${{ steps.emoji.outputs.BP_EMOJI }} | + | SEO | **${{ steps.parse.outputs.SEO_SCORE }}** | ${{ steps.emoji.outputs.SEO_EMOJI }} | + + ### Score Legend + - 🟢 90–100: Excellent + - 🟠 50–89: Needs Improvement + - 🔴 0–49: Poor + + > [View Full Lighthouse Report](${{ steps.parse.outputs.REPORT_URL }}) + + _This audit ensures PRs do not negatively impact performance or accessibility._ + comment-tag: lighthouse-report + mode: recreate + pr-number: ${{ github.event.pull_request.number }} + + - name: Upload Lighthouse Reports + if: always() + uses: actions/upload-artifact@v4 + with: + name: lighthouse-reports + path: .lighthouseci/ + retention-days: 30 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 43b30532..9431ed50 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ node_modules/ # tilt tilt_config.json + +# Lighthouse CI +.lighthouseci/ diff --git a/.lighthouserc.json b/.lighthouserc.json new file mode 100644 index 00000000..a430c39c --- /dev/null +++ b/.lighthouserc.json @@ -0,0 +1,69 @@ +{ + "ci": { + "collect": { + "staticDistDir": "./dist", + "numberOfRuns": 3, + "url": [ + "http://localhost" + ], + "settings": { + "preset": "desktop", + "onlyCategories": [ + "performance", + "accessibility", + "best-practices", + "seo" + ] + } + }, + "assert": { + "assertions": { + "categories:performance": [ + "error", + { + "minScore": 0.8 + } + ], + "categories:accessibility": [ + "error", + { + "minScore": 0.8 + } + ], + "categories:best-practices": [ + "warn", + { + "minScore": 0.8 + } + ], + "categories:seo": [ + "warn", + { + "minScore": 0.8 + } + ], + "largest-contentful-paint": [ + "warn", + { + "maxNumericValue": 4000 + } + ], + "cumulative-layout-shift": [ + "error", + { + "maxNumericValue": 0.1 + } + ], + "total-blocking-time": [ + "warn", + { + "maxNumericValue": 400 + } + ] + } + }, + "upload": { + "target": "temporary-public-storage" + } + } +} \ No newline at end of file From d4e6aa8e705d4a2310c32bfb243978e73feba4b2 Mon Sep 17 00:00:00 2001 From: Jetshree Date: Sun, 22 Feb 2026 01:58:22 +0530 Subject: [PATCH 2/2] fix filename Signed-off-by: Jetshree --- .github/workflows/lighthouse-ci.yml | 2 +- .lighthouserc.json => lighthouserc.json | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename .lighthouserc.json => lighthouserc.json (100%) diff --git a/.github/workflows/lighthouse-ci.yml b/.github/workflows/lighthouse-ci.yml index 2e349d6d..0697bba8 100644 --- a/.github/workflows/lighthouse-ci.yml +++ b/.github/workflows/lighthouse-ci.yml @@ -41,7 +41,7 @@ jobs: - name: Run Lighthouse CI id: lighthouse - run: npx @lhci/cli@0.14.x autorun --config=./.lighthouserc.json + run: npx @lhci/cli@0.14.x autorun --config=./lighthouserc.json - name: Parse Lighthouse Results id: parse diff --git a/.lighthouserc.json b/lighthouserc.json similarity index 100% rename from .lighthouserc.json rename to lighthouserc.json