@@ -321,4 +321,59 @@ jobs:
321321 HOSTING_EXPIRATION_DATE=$(npx firebase hosting:channel:list | grep ${{ inputs.PREVIEW_HOST_NAME }} | awk '{printf "%s %s\n",$9,$10;}')
322322 echo "hosting_url=$HOSTING_URL" >> "$GITHUB_OUTPUT"
323323 echo "hosting_expiration_date=$HOSTING_EXPIRATION_DATE" >> "$GITHUB_OUTPUT"
324+
325+ - name : Lighthouse Check
326+ id : lighthouse-check
327+ if : ${{ inputs.PREVIEW_DEPLOYMENT }}
328+ uses : treosh/lighthouse-ci-action@v12
329+ # Runs on: Homepage, Search page, GTFS page, GTFS-RT page, and GBFS page
330+ with :
331+ configPath : ./.github/lighthouserc.js
332+ temporaryPublicStorage : true
333+ env :
334+ LHCI_PREVIEW_URL_BASE64 : ${{ steps.deploy-preview.outputs.hosting_url }}
335+
336+
337+ - name : Format lighthouse score
338+ id : format_lighthouse_score
339+ if : ${{ inputs.PREVIEW_DEPLOYMENT }}
340+ uses : actions/github-script@v3
341+ with :
342+ github-token : ${{secrets.GITHUB_TOKEN}}
343+ script : |
344+ const results = ${{ steps.lighthouse-check.outputs.manifest }}
345+ const links = ${{ steps.lighthouse-check.outputs.links }}
346+ let comment = []
347+ results.forEach((resultData, index) => {
348+ const result = resultData.summary;
349+
350+ const formatResult = (res) => Math.round((res * 100))
351+ Object.keys(result).forEach(key => result[key] = formatResult(result[key]))
352+
353+ const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴'
354+ const link = Object.keys(links)[index] ?? 'Unknown URL';
355+ const linkUrl = links[link] ?? '#';
356+ comment = comment.concat(...[
357+ `*Lighthouse ran on ${link} * (Desktop)`,
358+ `⚡️ HTML Report [Lighthouse report](${linkUrl}) for the changes in this PR:`,
359+ '| Performance | Accessibility | Best Practices | SEO |',
360+ '| --- | --- | --- | --- |',
361+ `| ${score(result.performance)} ${result.performance} | ${score(result.accessibility)} ${result.accessibility} | ${score(result['best-practices'])} ${result['best-practices']} | ${score(result.seo)} ${result.seo} |`,
362+ ' ',
363+ ' ',
364+ ])
365+ })
366+ const finalComment = comment.join('\n')
367+ core.setOutput("comment", finalComment);
368+
369+ - name : Add lighthouse comment to PR
370+ id : comment_to_pr
371+ if : ${{ inputs.PREVIEW_DEPLOYMENT }}
372+ uses : marocchino/sticky-pull-request-comment@v1
373+ with :
374+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
375+ number : ${{ github.event.issue.number }}
376+ header : lighthouse
377+ message : |
378+ ${{ steps.format_lighthouse_score.outputs.comment }}
324379
0 commit comments