chore: update work content #261
This file contains 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
name: Lighthouse CI | |
on: [push] | |
jobs: | |
lighthouse: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@master | |
- name: Waiting for Vercel Preview | |
uses: patrickedqvist/[email protected] | |
id: vercelPreview | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
check_interval: 30 | |
max_timeout: 180 | |
- name: Lighthouse | |
uses: treosh/lighthouse-ci-action@v9 | |
id: lighthouse_audit | |
with: | |
urls: ${{steps.vercelPreview.outputs.url}} | |
configPath: "./lighthouserc.json" | |
uploadArtifacts: true | |
temporaryPublicStorage: true | |
# Step copied from - https://github.com/OskarAhl/Lighthouse-github-action-comment | |
- name: Format lighthouse score | |
id: format_lighthouse_score | |
uses: actions/github-script@v3 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const result = ${{ steps.lighthouse_audit.outputs.manifest }}[0].summary | |
const links = ${{ steps.lighthouse_audit.outputs.links }} | |
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 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') | |
core.setOutput("comment", comment); | |
- uses: mshick/add-pr-comment@v1 | |
with: | |
message: ${{ steps.format_lighthouse_score.outputs.comment }} | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
repo-token-user-login: "github-actions[bot]" |