-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: lighthouse | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- "main" | ||
- "develop" | ||
types: | ||
- opened | ||
- synchronize | ||
jobs: | ||
lighthouseci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Run lighthouse | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20.11.0 | ||
- run: | | ||
npm install -g pnpm | ||
pnpm install && pnpm add -g @lhci/cli | ||
pnpm run build | ||
lhci autorun | ||
env: | ||
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} | ||
- name: Format lighthouse score | ||
id: format_lighthouse_score | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const script = require('./scripts/lhciFormat.js') | ||
await script({core}) | ||
- name: comment result | ||
uses: unsplash/[email protected] | ||
with: | ||
msg: ${{ steps.format_lighthouse_score.outputs.comments}} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const fs = require("fs") | ||
|
||
const workspace = process.env.GITHUB_WORKSPACE | ||
|
||
const results = JSON.parse( | ||
fs.readFileSync(path.join(workspace, "lhci_reports", "manifest.json")) | ||
) | ||
const categories = [ | ||
"first-contentful-paint", | ||
"interactive", | ||
"speed-index", | ||
"total-blocking-time", | ||
"largest-contentful-paint", | ||
"cumulative-layout-shift", | ||
] | ||
|
||
const formatResult = (res) => Math.round(res * 100) | ||
const score = (res) => (res >= 90 ? "🟢" : res >= 50 ? "🟠" : "🔴") | ||
const detailRow = (category, audits) => | ||
`| ${score(audits[category].score * 100)} ${category} | ${ | ||
audits[category].displayValue | ||
} |` | ||
const getComment = (performance) => | ||
[ | ||
`⚡️ Lighthouse report!`, | ||
`| Summary | Score |`, | ||
`| --- | --- |`, | ||
`| ${score(performance)} Performance | ${performance} |`, | ||
].join("\n") | ||
|
||
module.exports = async ({ core }) => { | ||
let comments = "" | ||
|
||
results.forEach((result) => { | ||
const { summary, jsonPath } = result | ||
const details = JSON.parse(fs.readFileSync(jsonPath)) | ||
const { audits } = details | ||
const summaryEntries = Object.entries(summary).map(([key, value]) => [ | ||
key, | ||
formatResult(value), | ||
]) | ||
const { performance } = Object.fromEntries(summaryEntries) | ||
const comment = getComment(performance) | ||
const detailRows = categories | ||
.map((category) => detailRow(category, audits)) | ||
.join("\n") | ||
const detail = [`| Category | Score |`, detailRows].join("\n") | ||
comments += comment + "\n" + detail + "\n\n" | ||
}) | ||
|
||
core.setOutput("comments", comments) | ||
} |