From 5e20bdfdeefab32483704a29a80c5b5a4599da6d Mon Sep 17 00:00:00 2001 From: shubham oulkar <91728992+ShubhamOulkar@users.noreply.github.com> Date: Sun, 27 Jul 2025 15:12:22 +0530 Subject: [PATCH 1/8] unlighthouse --- .github/workflows/lighthouse.yml | 94 ++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 .github/workflows/lighthouse.yml diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml new file mode 100644 index 0000000000..31c5a407d3 --- /dev/null +++ b/.github/workflows/lighthouse.yml @@ -0,0 +1,94 @@ +name: Lighthouse report + +on: + pull_request: + types: [opened, synchronize] + +permissions: + contents: read + pull-requests: write + +jobs: + lighthouse: + if: github.actor != 'dependabot[bot]' + runs-on: ubuntu-latest + + steps: + - name: Checkout PR code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + + - name: Setup Node.js with npm cache + uses: actions/setup-node@v4 + with: + node-version: '22.x' + cache: 'npm' + + - name: Install dependencies + run: npm install @unlighthouse/cli puppeteer + + - name: Wait for Netlify preview to be live + run: | + PREVIEW_URL="https://deploy-preview-${{ github.event.pull_request.number }}--expressjscom-preview.netlify.app" + echo "PREVIEW_URL=$PREVIEW_URL" >> "$GITHUB_ENV" + for i in {1..2}; do + if curl -s --head "$PREVIEW_URL" | grep "200 OK" > /dev/null; then + echo "Preview is live!" + break + fi + echo "Waiting for Netlify to deploy... ($i/2)" + sleep 10 + done + + - name: Run Lighthouse audits + run: | + URLS=( + "$PREVIEW_URL" + "$PREVIEW_URL/en/blog/posts.html" + "$PREVIEW_URL/en/5x/api.html" + ) + + echo "## 🚦 Lighthouse Results (Mobile & Desktop)" > lighthouse-report.md + echo "| URL | Device | Perf | A11y | Best Practices | SEO |" >> lighthouse-report.md + echo "| --- | ------ | ---- | ---- | -------------- | --- |" >> lighthouse-report.md + + for device in mobile desktop; do + for url in "${URLS[@]}"; do + unlighthouse-ci --site "$url" --"$device" --output-path="lighthouse-report-${device}.json" + + report="lighthouse-report-${device}.json" + perf=$(jq '.categories | .performance.score * 100' $report) + a11y=$(jq '.categories | .accessibility.score * 100' $report) + bp=$(jq '.categories | .["best-practices"].score * 100' $report) + seo=$(jq '.categories | .seo.score * 100' $report) + + stoplight() { + if (( $(echo "$1 >= 90" | bc -l) )); then echo "🟢"; + elif (( $(echo "$1 >= 75" | bc -l) )); then echo "🟠"; + else echo "🔴"; fi + } + + perf_stoplight=$(stoplight $perf) + a11y_stoplight=$(stoplight $a11y) + bp_stoplight=$(stoplight $bp) + seo_stoplight=$(stoplight $seo) + + path=$(echo "$url" | sed "s|$PREVIEW_URL||") + if [ -z "$path" ]; then path="/"; fi + + echo "| $path | $device | $perf_stoplight $(printf "%.0f" $perf) | $a11y_stoplight $(printf "%.0f" $a11y) | $bp_stoplight $(printf "%.0f" $bp) | $seo_stoplight $(printf "%.0f" $seo) |" >> lighthouse-report.md + done + done + + - name: Log Lighthouse report + run: | + cat lighthouse-report.md + + - name: Upload Lighthouse reports as artifacts + uses: actions/upload-artifact@v4 + with: + name: lighthouse-reports + path: | + lighthouse-report.md From 4d641da439d9d838cacf67a993da51c4ff0a8a59 Mon Sep 17 00:00:00 2001 From: shubham oulkar <91728992+ShubhamOulkar@users.noreply.github.com> Date: Sun, 27 Jul 2025 15:19:00 +0530 Subject: [PATCH 2/8] test --- .github/workflows/lighthouse.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 31c5a407d3..59639da2a9 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -56,7 +56,7 @@ jobs: for device in mobile desktop; do for url in "${URLS[@]}"; do - unlighthouse-ci --site "$url" --"$device" --output-path="lighthouse-report-${device}.json" + npx unlighthouse-ci --site "$url" --"$device" --output-path="lighthouse-report-${device}.json" report="lighthouse-report-${device}.json" perf=$(jq '.categories | .performance.score * 100' $report) From d77864ec9597a379cda9e051dbcd2110e43fb609 Mon Sep 17 00:00:00 2001 From: shubham oulkar <91728992+ShubhamOulkar@users.noreply.github.com> Date: Sun, 27 Jul 2025 15:35:35 +0530 Subject: [PATCH 3/8] test --- .github/workflows/lighthouse.yml | 37 +++++++++++--------------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 59639da2a9..b8a7b480d5 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -44,44 +44,33 @@ jobs: - name: Run Lighthouse audits run: | - URLS=( - "$PREVIEW_URL" - "$PREVIEW_URL/en/blog/posts.html" - "$PREVIEW_URL/en/5x/api.html" - ) - echo "## 🚦 Lighthouse Results (Mobile & Desktop)" > lighthouse-report.md echo "| URL | Device | Perf | A11y | Best Practices | SEO |" >> lighthouse-report.md echo "| --- | ------ | ---- | ---- | -------------- | --- |" >> lighthouse-report.md + npx unlighthouse-ci --site "$PREVIEW_URL" --"$device" --output-path="lighthouse-report.json" --disable-i18n-pages - for device in mobile desktop; do - for url in "${URLS[@]}"; do - npx unlighthouse-ci --site "$url" --"$device" --output-path="lighthouse-report-${device}.json" - - report="lighthouse-report-${device}.json" - perf=$(jq '.categories | .performance.score * 100' $report) + report="lighthouse-report.json" + perf=$(jq '.categories | .performance.score * 100' $report) a11y=$(jq '.categories | .accessibility.score * 100' $report) bp=$(jq '.categories | .["best-practices"].score * 100' $report) seo=$(jq '.categories | .seo.score * 100' $report) - stoplight() { + stoplight() { if (( $(echo "$1 >= 90" | bc -l) )); then echo "🟢"; elif (( $(echo "$1 >= 75" | bc -l) )); then echo "🟠"; else echo "🔴"; fi - } + } - perf_stoplight=$(stoplight $perf) - a11y_stoplight=$(stoplight $a11y) - bp_stoplight=$(stoplight $bp) - seo_stoplight=$(stoplight $seo) + perf_stoplight=$(stoplight $perf) + a11y_stoplight=$(stoplight $a11y) + bp_stoplight=$(stoplight $bp) + seo_stoplight=$(stoplight $seo) - path=$(echo "$url" | sed "s|$PREVIEW_URL||") - if [ -z "$path" ]; then path="/"; fi - - echo "| $path | $device | $perf_stoplight $(printf "%.0f" $perf) | $a11y_stoplight $(printf "%.0f" $a11y) | $bp_stoplight $(printf "%.0f" $bp) | $seo_stoplight $(printf "%.0f" $seo) |" >> lighthouse-report.md - done - done + path=$(echo "$url" | sed "s|$PREVIEW_URL||") + if [ -z "$path" ]; then path="/"; fi + echo "| $path | $device | $perf_stoplight $(printf "%.0f" $perf) | $a11y_stoplight $(printf "%.0f" $a11y) | $bp_stoplight $(printf "%.0f" $bp) | $seo_stoplight $(printf "%.0f" $seo) |" >> lighthouse-report.md + - name: Log Lighthouse report run: | cat lighthouse-report.md From d4d38ead13214cd2b705a6e65fdacff7ed8c4329 Mon Sep 17 00:00:00 2001 From: shubham oulkar <91728992+ShubhamOulkar@users.noreply.github.com> Date: Sun, 27 Jul 2025 15:53:01 +0530 Subject: [PATCH 4/8] test --- .github/workflows/lighthouse.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index b8a7b480d5..6f2b7fb300 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -47,7 +47,7 @@ jobs: echo "## 🚦 Lighthouse Results (Mobile & Desktop)" > lighthouse-report.md echo "| URL | Device | Perf | A11y | Best Practices | SEO |" >> lighthouse-report.md echo "| --- | ------ | ---- | ---- | -------------- | --- |" >> lighthouse-report.md - npx unlighthouse-ci --site "$PREVIEW_URL" --"$device" --output-path="lighthouse-report.json" --disable-i18n-pages + npx unlighthouse-ci --site "$PREVIEW_URL" --url "/" --mobile --disable-dynamic-sampling --output-path="lighthouse-report.json" report="lighthouse-report.json" perf=$(jq '.categories | .performance.score * 100' $report) From 8f9756c592f94bdd2958fb70897af9b9e103787d Mon Sep 17 00:00:00 2001 From: shubham oulkar <91728992+ShubhamOulkar@users.noreply.github.com> Date: Sun, 27 Jul 2025 16:02:51 +0530 Subject: [PATCH 5/8] test --- .github/workflows/lighthouse.yml | 41 ++------------------------------ 1 file changed, 2 insertions(+), 39 deletions(-) diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 6f2b7fb300..16aed7a11a 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -42,42 +42,5 @@ jobs: sleep 10 done - - name: Run Lighthouse audits - run: | - echo "## 🚦 Lighthouse Results (Mobile & Desktop)" > lighthouse-report.md - echo "| URL | Device | Perf | A11y | Best Practices | SEO |" >> lighthouse-report.md - echo "| --- | ------ | ---- | ---- | -------------- | --- |" >> lighthouse-report.md - npx unlighthouse-ci --site "$PREVIEW_URL" --url "/" --mobile --disable-dynamic-sampling --output-path="lighthouse-report.json" - - report="lighthouse-report.json" - perf=$(jq '.categories | .performance.score * 100' $report) - a11y=$(jq '.categories | .accessibility.score * 100' $report) - bp=$(jq '.categories | .["best-practices"].score * 100' $report) - seo=$(jq '.categories | .seo.score * 100' $report) - - stoplight() { - if (( $(echo "$1 >= 90" | bc -l) )); then echo "🟢"; - elif (( $(echo "$1 >= 75" | bc -l) )); then echo "🟠"; - else echo "🔴"; fi - } - - perf_stoplight=$(stoplight $perf) - a11y_stoplight=$(stoplight $a11y) - bp_stoplight=$(stoplight $bp) - seo_stoplight=$(stoplight $seo) - - path=$(echo "$url" | sed "s|$PREVIEW_URL||") - if [ -z "$path" ]; then path="/"; fi - - echo "| $path | $device | $perf_stoplight $(printf "%.0f" $perf) | $a11y_stoplight $(printf "%.0f" $a11y) | $bp_stoplight $(printf "%.0f" $bp) | $seo_stoplight $(printf "%.0f" $seo) |" >> lighthouse-report.md - - - name: Log Lighthouse report - run: | - cat lighthouse-report.md - - - name: Upload Lighthouse reports as artifacts - uses: actions/upload-artifact@v4 - with: - name: lighthouse-reports - path: | - lighthouse-report.md + - name: Unlighthouse assertions and client + run: unlighthouse-ci --site "$PREVIEW_URL" --build-static --disable-i18n-pages --disable-robots-txt --disable-sitemap --disable-dynamic-sampling From bb2b46e72445e8421ea211ce84a57245f7e33001 Mon Sep 17 00:00:00 2001 From: shubham oulkar <91728992+ShubhamOulkar@users.noreply.github.com> Date: Sun, 27 Jul 2025 16:05:33 +0530 Subject: [PATCH 6/8] test --- .github/workflows/lighthouse.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 16aed7a11a..18bff427c6 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -43,4 +43,4 @@ jobs: done - name: Unlighthouse assertions and client - run: unlighthouse-ci --site "$PREVIEW_URL" --build-static --disable-i18n-pages --disable-robots-txt --disable-sitemap --disable-dynamic-sampling + run: npx unlighthouse-ci --site "$PREVIEW_URL" --build-static --disable-i18n-pages --disable-robots-txt --disable-sitemap --disable-dynamic-sampling From a4595efed4ce3fa58fba132352fa5f867419c097 Mon Sep 17 00:00:00 2001 From: shubham oulkar <91728992+ShubhamOulkar@users.noreply.github.com> Date: Sun, 27 Jul 2025 18:50:20 +0530 Subject: [PATCH 7/8] test --- .github/workflows/lighthouse.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 18bff427c6..17637d2e58 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -43,4 +43,7 @@ jobs: done - name: Unlighthouse assertions and client - run: npx unlighthouse-ci --site "$PREVIEW_URL" --build-static --disable-i18n-pages --disable-robots-txt --disable-sitemap --disable-dynamic-sampling + run: npx unlighthouse-ci --site "$PREVIEW_URL" --$device --urls /,/en/5x/api --disable-dynamic-sampling --disable-sitemap --disable-robots-txt + + - name: 📄 Log results + run: cat ./.unlighthouse/ci-result.json From 5b82da2fcd1653f7b5af113eb06abe953e09f144 Mon Sep 17 00:00:00 2001 From: shubham oulkar <91728992+ShubhamOulkar@users.noreply.github.com> Date: Sun, 27 Jul 2025 19:19:36 +0530 Subject: [PATCH 8/8] test --- .github/workflows/lighthouse.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 17637d2e58..80b8ef9f5d 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -43,7 +43,7 @@ jobs: done - name: Unlighthouse assertions and client - run: npx unlighthouse-ci --site "$PREVIEW_URL" --$device --urls /,/en/5x/api --disable-dynamic-sampling --disable-sitemap --disable-robots-txt + run: npx unlighthouse-ci --site "$PREVIEW_URL" --mobile --urls /en/5x/api --samples 1 --disable-dynamic-sampling --disable-sitemap --disable-robots-txt - name: 📄 Log results run: cat ./.unlighthouse/ci-result.json