Skip to content

Commit

Permalink
feat: lighthouse ci 다시 세팅
Browse files Browse the repository at this point in the history
  • Loading branch information
SEOKKAMONI committed Oct 17, 2023
1 parent 7fee35c commit 657eb1a
Showing 1 changed file with 9 additions and 61 deletions.
70 changes: 9 additions & 61 deletions .github/workflows/lighthouse-ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: Lighthouse CI

on:
push:

name: Run Lighthouse CI When Push
on: [push]
jobs:
lhci:
name: Lighthouse CI
Expand All @@ -11,75 +8,26 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Use Node.js 17.3.1 and pnpm
- name: Use Node.js 17.3.1
uses: actions/setup-node@v1
with:
node-version: 17.3.1
run: |
npm install -g pnpm

- name: Install packages with pnpm
- name: Install packages
run: |
npm install -g pnpm
pnpm install
- name: Build
run: |
pnpm run build
- name: Install Lighthouse CLI
run: |
npm install -g @lhci/cli
- name: Run Lighthouse CI
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
run: |
npm install -g @lhci/cli
lhci autorun || echo "Fail to Run Lighthouse CI!"
- 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("/{Github Actions runner directory}/lhci_reports/manifest.json"));
let comments = "";
results.forEach((result) => {
const { summary, jsonPath } = result;
const { audits } = details;
const details = JSON.parse(fs.readFileSync(jsonPath));
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} |`,
{ ... }
].join("\n");
const detail = [
`| Category | Score |`,
`| --- | --- |`,
`| ${score(
audits["first-contentful-paint"].score * 100
)} First Contentful Paint | ${
audits["first-contentful-paint"].displayValue
} |`,
{ ... }
].join("\n");
comments += comment + "\n" + detail + "\n";
});
core.setOutput('comments', comments)
- name: comment PR
uses: unsplash/comment-on-pr@v1.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: msg

0 comments on commit 657eb1a

Please sign in to comment.