-
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.
chore: lighthouse 체크 github actions 추가
- Loading branch information
Showing
1 changed file
with
125 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,125 @@ | ||
name: Run lighthouse CI When PR | ||
on: | ||
pull_request: | ||
types: [opened, reopened] | ||
jobs: | ||
lhci: | ||
name: Lighthouse CI | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Time Zone Setting | ||
run: sudo timedatectl set-timezone Asia/Seoul | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: '.nvmrc' | ||
cache: npm | ||
|
||
- name: Use Cache | ||
uses: actions/cache@v3 | ||
id: npm-cache | ||
with: | ||
path: | | ||
**/node_modules | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
${{ runner.os }} | ||
- name: Install packages | ||
run: | | ||
npm install | ||
- name: Build | ||
run: | | ||
npm run build | ||
- name: Run Lighthouse CI | ||
run: | | ||
npm install -g @lhci/cli | ||
lhci autorun || echo "Fail to Run Lighthouse CI!" | ||
- name: Format lighthouse score | ||
uses: actions/github-script@v6 | ||
id: format_lighthouse_score | ||
with: | ||
result-encoding: string | ||
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} |`, | ||
// practices 라는 단어가 예약어인가봄. | ||
// `| ${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["interactive"].score * 100 | ||
)} Time To Interactive | ${ | ||
audits["interactive"].displayValue | ||
} |`, | ||
`| ${score( | ||
audits["speed-index"].score * 100 | ||
)} Speed Index | ${ | ||
audits["speed-index"].displayValue | ||
} |`, | ||
`| ${score( | ||
audits["total-blocking-time"].score * 100 | ||
)} Total Blocking Time | ${ | ||
audits["total-blocking-time"].displayValue | ||
} |`, | ||
`| ${score( | ||
audits["largest-contentful-paint"].score * 100 | ||
)} Largest Contentful Paint | ${ | ||
audits["largest-contentful-paint"].displayValue | ||
} |`, | ||
`| ${score( | ||
audits["cumulative-layout-shift"].score * 100 | ||
)} Cumulative Layout Shift | ${ | ||
audits["cumulative-layout-shift"].displayValue | ||
} |`, | ||
].join("\n"); | ||
comments += comment + "\n" + detail + "\n"; | ||
}); | ||
return comments; | ||
- name: Get result | ||
run: echo "${{steps.format_lighthouse_score.outputs.result}}" | ||
|
||
- name: comment PR | ||
uses: thollander/actions-comment-pull-request@v2 | ||
with: | ||
message: ${{ steps.format_lighthouse_score.outputs.result }} |