Feature/q page #20
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: Run lighthouse CI When Push | |
on: [pull_request] | |
jobs: | |
lhci: | |
name: Lighthouse CI | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: "18" | |
- name: Install packages | |
run: | | |
yarn install | |
- name: Build | |
run: CI=false yarn build | |
- name: Run Lighthouse CI | |
env: | |
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} | |
run: | | |
npm install -g @lhci/cli | |
lhci autorun || true | |
- name: Format lighthouse score | |
id: format_lighthouse_score | |
uses: actions/github-script@v3 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const results = JSON.parse(fs.readFileSync('./lhci_reports/manifest.json')); | |
let comments = ""; | |
results.forEach((result) => { | |
const { | |
summary, | |
jsonPath | |
} = result; | |
const details = JSON.parse(fs.readFileSync(jsonPath)); | |
const { | |
audits | |
} = details; | |
const formatResult = (res) => Math.round(res * 100); | |
Object.keys(summary).forEach( | |
(key) => (summary[key] = formatResult(summary[key])) | |
); | |
const score = (res) => (res >= 90 ? "🟢" : res >= 50 ? "🟠" : "🔴"); | |
const comment = [ | |
`⚡️ Lighthouse report!`, | |
`| Category | Score |`, | |
`| --- | --- |`, | |
`| ${score(summary.performance)} Performance | ${summary.performance} |`, | |
`| ${score(summary.accessibility)} Accessibility | ${summary.accessibility} |`, | |
`| ${score(summary["best-practices"])} Best Practices | ${summary["best-practices"]} |`, | |
`| ${score(summary.seo)} SEO | ${summary.seo} |`, | |
`| ${score(summary.pwa)} PWA | ${summary.pwa} |`, | |
].join("\n"); | |
const detail = [ | |
`| Category | Score |`, | |
`| --- | --- |`, | |
`| ${score( | |
audits["first-contentful-paint"].score * 100 | |
)} First Contentful Paint | ${ | |
audits["first-contentful-paint"].displayValue | |
} |`, | |
`| ${score( | |
audits["largest-contentful-paint"].score * 100 | |
)} Largest Contentful Paint | ${ | |
audits["largest-contentful-paint"].displayValue | |
} |`, | |
].join("\n"); | |
comments += comment + "\n" + detail + "\n"; | |
}); | |
core.setOutput('comments', comments) | |
- name: comment PR | |
uses: unsplash/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
msg: ${{ steps.format_lighthouse_score.outputs.comments}} |