-
Notifications
You must be signed in to change notification settings - Fork 6
feat: lighthouse report on frontend PRs #1203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
d271d07
test light house github action
Alessandro100 f75cb75
syntax change
Alessandro100 ee7fedb
syntax
Alessandro100 c63cb9b
syntax
Alessandro100 acafdd0
test
Alessandro100 8d949d3
lighthouse check on local build
Alessandro100 5c82a22
server contine
Alessandro100 e066b51
syntax
Alessandro100 c87481e
seo score adjust
Alessandro100 48e3878
flaky test
Alessandro100 4e2afb2
configs
Alessandro100 c08b2e8
cleanup
Alessandro100 7e3374b
test
Alessandro100 b496575
test 2
Alessandro100 7ea3089
fix path
Alessandro100 ed5f944
test
Alessandro100 fcfe847
test
Alessandro100 c1ca341
syntax
Alessandro100 357e2d8
format fix
Alessandro100 b8fe475
syntax
Alessandro100 0e515d6
back to preview url
Alessandro100 18f3453
throttle
Alessandro100 d998b73
syntax
Alessandro100 da65f73
t
Alessandro100 983dce3
run once + seo accuracy
Alessandro100 f0b1493
js syntax
Alessandro100 52b557f
t
Alessandro100 97c9e0d
cleanup
Alessandro100 421ab49
spacing
Alessandro100 8011ea5
conditional statments on lighthouse check
Alessandro100 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| let previewBaseUrl = ''; | ||
| try { | ||
| const previewUrlBase64 = process.env.LHCI_PREVIEW_URL_BASE64; | ||
| console.log("environemtnt variable LHCI_PREVIEW_URL:", previewUrlBase64); | ||
| if (previewUrlBase64) { | ||
| const decodedUrl = Buffer.from(previewUrlBase64, 'base64').toString('utf-8'); | ||
| console.log("Decoded preview URL:", decodedUrl); | ||
| previewBaseUrl = decodedUrl; | ||
| } else { | ||
| console.error("LHCI_PREVIEW_URL_BASE64 environment variable is not set."); | ||
| } | ||
| } catch (error) { | ||
| console.error("Error decoding LHCI_PREVIEW_URL_BASE64:", error); | ||
| } | ||
|
|
||
| module.exports = { | ||
| ci: { | ||
| collect: { | ||
| url: [ | ||
| `${previewBaseUrl}/`, | ||
| `${previewBaseUrl}/feeds`, | ||
| `${previewBaseUrl}/feeds/gtfs/mdb-2126`, | ||
| `${previewBaseUrl}/feeds/gtfs_rt/mdb-2585`, | ||
| `${previewBaseUrl}/gbfs/gbfs-flamingo_porirua` | ||
| ], | ||
| numberOfRuns: 1, // 1 to speed up the CI process but can be increased for more reliable results | ||
| settings: { | ||
| formFactor: 'desktop', | ||
| throttlingMethod: 'provided', | ||
| skipAudits: ['robots-txt', 'is-crawlable'], | ||
| screenEmulation: { | ||
| mobile: false, | ||
| width: 1350, | ||
| height: 940, | ||
| deviceScaleRatio: 1, | ||
| disabled: false | ||
| } | ||
| } | ||
| }, | ||
| upload: { | ||
| target: 'temporary-public-storage' | ||
| } | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -321,4 +321,59 @@ jobs: | |
| HOSTING_EXPIRATION_DATE=$(npx firebase hosting:channel:list | grep ${{ inputs.PREVIEW_HOST_NAME }} | awk '{printf "%s %s\n",$9,$10;}') | ||
| echo "hosting_url=$HOSTING_URL" >> "$GITHUB_OUTPUT" | ||
| echo "hosting_expiration_date=$HOSTING_EXPIRATION_DATE" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Lighthouse Check | ||
| id: lighthouse-check | ||
| if: ${{ inputs.PREVIEW_DEPLOYMENT }} | ||
| uses: treosh/lighthouse-ci-action@v12 | ||
| # Runs on: Homepage, Search page, GTFS page, GTFS-RT page, and GBFS page | ||
| with: | ||
| configPath: ./.github/lighthouserc.js | ||
| temporaryPublicStorage: true | ||
| env: | ||
| LHCI_PREVIEW_URL_BASE64: ${{ steps.deploy-preview.outputs.hosting_url }} | ||
|
|
||
|
|
||
| - name: Format lighthouse score | ||
| id: format_lighthouse_score | ||
| if: ${{ inputs.PREVIEW_DEPLOYMENT }} | ||
| uses: actions/github-script@v3 | ||
| with: | ||
| github-token: ${{secrets.GITHUB_TOKEN}} | ||
| script: | | ||
| const results = ${{ steps.lighthouse-check.outputs.manifest }} | ||
| const links = ${{ steps.lighthouse-check.outputs.links }} | ||
| let comment = [] | ||
| results.forEach((resultData, index) => { | ||
| const result = resultData.summary; | ||
|
|
||
| const formatResult = (res) => Math.round((res * 100)) | ||
| Object.keys(result).forEach(key => result[key] = formatResult(result[key])) | ||
|
|
||
| const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴' | ||
| const link = Object.keys(links)[index] ?? 'Unknown URL'; | ||
| const linkUrl = links[link] ?? '#'; | ||
| comment = comment.concat(...[ | ||
| `*Lighthouse ran on ${link} * (Desktop)`, | ||
| `⚡️ HTML Report [Lighthouse report](${linkUrl}) for the changes in this PR:`, | ||
| '| Performance | Accessibility | Best Practices | SEO |', | ||
| '| --- | --- | --- | --- |', | ||
| `| ${score(result.performance)} ${result.performance} | ${score(result.accessibility)} ${result.accessibility} | ${score(result['best-practices'])} ${result['best-practices']} | ${score(result.seo)} ${result.seo} |`, | ||
| ' ', | ||
| ' ', | ||
| ]) | ||
| }) | ||
| const finalComment = comment.join('\n') | ||
| core.setOutput("comment", finalComment); | ||
|
|
||
| - name: Add lighthouse comment to PR | ||
| id: comment_to_pr | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need: |
||
| if: ${{ inputs.PREVIEW_DEPLOYMENT }} | ||
| uses: marocchino/sticky-pull-request-comment@v1 | ||
| with: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| number: ${{ github.event.issue.number }} | ||
| header: lighthouse | ||
| message: | | ||
| ${{ steps.format_lighthouse_score.outputs.comment }} | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need:
if: ${{ inputs.PREVIEW_DEPLOYMENT }}here?