From 88c230daf250687880fdfa9127f5250b8fc9aa5c Mon Sep 17 00:00:00 2001 From: Gabo Esquivel Date: Sat, 6 Apr 2024 01:49:05 -0600 Subject: [PATCH] devops: run lhci on bot and user landings (#75) * devops: debug github actions * devops: run lhci on bot and user landings --- .github/workflows/lighthouse.yml | 38 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 82617342..98f1f3ec 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -35,6 +35,9 @@ jobs: with: urls: | "https://${{ steps.vercel_preview_url.outputs.preview_url }}" + "https://${{ steps.vercel_preview_url.outputs.preview_url }}/b/moneybot" + "https://${{ steps.vercel_preview_url.outputs.preview_url }}/u/slug-1" + "https://${{ steps.vercel_preview_url.outputs.preview_url }}/p" # budgetPath: '.github/lighthouse/budget.json' uploadArtifacts: true temporaryPublicStorage: true @@ -44,28 +47,27 @@ jobs: with: github-token: ${{secrets.GITHUB_TOKEN}} script: | - const result = ${{ steps.lighthouse_audit.outputs.manifest }}[0].summary - const links = ${{ steps.lighthouse_audit.outputs.links }} + const manifest = ${{ toJSON(steps.lighthouse_audit.outputs.manifest) }}; + const links = ${{ toJSON(steps.lighthouse_audit.outputs.links) }}; - const formatResult = (res) => Math.round((res * 100)) - Object.keys(result).forEach(key => result[key] = formatResult(result[key])) + const formatResult = (res) => Math.round((res * 100)); + const score = (res) => (res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴'); - const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴' + let comment = `⚡️ [Lighthouse report](${Object.values(links)[0]}) for the changes in this PR:\n`; + comment += '| Category | Score |\n'; + comment += '| --- | --- |\n'; - const comment = [ - `⚡️ [Lighthouse report](${Object.values(links)[0]}) for the changes in this PR:`, - '| Category | Score |', - '| --- | --- |', - `| ${score(result.performance)} Performance | ${result.performance} |`, - `| ${score(result.accessibility)} Accessibility | ${result.accessibility} |`, - `| ${score(result['best-practices'])} Best practices | ${result['best-practices']} |`, - `| ${score(result.seo)} SEO | ${result.seo} |`, - `| ${score(result.pwa)} PWA | ${result.pwa} |`, - ' ', - `*Lighthouse ran on [${Object.keys(links)[0]}](${Object.keys(links)[0]})*` - ].join('\n') + Object.keys(manifest).forEach((page) => { + const result = manifest[page].summary; + const pageLink = manifest[page].url; + Object.keys(result).forEach((key) => { + const formattedScore = formatResult(result[key]); + comment += `| ${score(result[key])} ${key} | ${formattedScore} |\n`; + }); + comment += `*Lighthouse ran on [${pageLink}](${pageLink})*\n\n`; + }); - core.setOutput("comment", comment); + core.setOutput('comment', comment); - name: Add comment to PR id: comment_to_pr uses: marocchino/sticky-pull-request-comment@v2.9.0