Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lighthouse setting #82

Open
wants to merge 41 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
529c38a
feat: lighthouse setting
minsu-zip Aug 11, 2024
985500e
chore: branch name μˆ˜μ •
minsu-zip Aug 11, 2024
6de9436
chore: npm으둜 λ³€κ²½
minsu-zip Aug 11, 2024
01a82a9
chore: pnpm setting
minsu-zip Aug 11, 2024
7c9b281
chore: action μΆ”κ°€
minsu-zip Aug 11, 2024
d2a6ba6
chore: 폴더 넀이밍 λ³€κ²½
minsu-zip Aug 11, 2024
90ba8c0
chore: path module import
minsu-zip Aug 11, 2024
d4ec2d3
chore: lhci 경둜 좜λ ₯을 μœ„ν•œ ν…ŒμŠ€νŠΈ
minsu-zip Aug 12, 2024
61e0497
chore: 경둜 μ •μ˜λ₯Ό μœ„ν•œ μ„€μ • 파일 μΆ”κ°€
minsu-zip Aug 12, 2024
6cb9111
chore: build 슀크립트 μΆ”κ°€
minsu-zip Aug 12, 2024
a40642b
chore: env μΆ”κ°€
minsu-zip Aug 12, 2024
8d6791c
chore: λΉŒλ“œ 경둜 λ³€κ²½
minsu-zip Aug 12, 2024
40b1623
chore: λ‘œμ»¬μ— μ €μž₯ν•˜μ§€ μ•Šκ³  λ°”λ‘œ pull request에 μž‘μ„±
minsu-zip Aug 12, 2024
3ac3c8b
fix: results λ³€μˆ˜λ₯Ό μ •μ˜ν•˜μ§€ μ•Šκ³  μ‚¬μš©ν•˜λ €κ³  ν•΄μ„œ λ°œμƒν•œ μ—λŸ¬ μˆ˜μ •
minsu-zip Aug 12, 2024
599b4e7
chore: setting
minsu-zip Aug 13, 2024
050be82
chore
minsu-zip Aug 13, 2024
ff4cee6
chore: await 제거
minsu-zip Aug 13, 2024
2b2e4a7
chore: yml μˆ˜μ •
minsu-zip Aug 13, 2024
e55908a
chore: 경둜 μˆ˜μ •
minsu-zip Aug 13, 2024
5c23299
chore: console
minsu-zip Aug 13, 2024
d271967
chore: μ„œλ²„ μ‹€ν–‰ 둜직 μΆ”κ°€
minsu-zip Aug 13, 2024
735cffd
chore: 토큰 μ£Όμž…
minsu-zip Aug 13, 2024
414ff7c
chore: μ„œλ²„ μ‹€ν–‰ μ½”λ“œ 제거
minsu-zip Aug 13, 2024
4a1d388
chore: μ£Όμ†Œ λ³€κ²½
minsu-zip Aug 14, 2024
5ea7d57
chore: 포트번호 제거 ν…ŒμŠ€νŠΈ
minsu-zip Aug 14, 2024
4f4828e
chore: url protocol 제거
minsu-zip Aug 14, 2024
cf396d2
chore: chrome flag μΆ”κ°€
minsu-zip Aug 14, 2024
0cdb80d
chore: flag μΆ”κ°€
minsu-zip Aug 14, 2024
15f3819
chore: test
minsu-zip Aug 14, 2024
03bc18e
chore: env μΆ”κ°€
minsu-zip Aug 14, 2024
0915b21
chore: report 제거
minsu-zip Aug 14, 2024
4d4d0b3
chore
minsu-zip Aug 14, 2024
d2fd5f2
setting: lhci/cli
minsu-zip Aug 14, 2024
98f20c7
chore: remove
minsu-zip Aug 14, 2024
3ffe5c5
Merge branch 'dev' into feat/MAFOO-84
minsu-zip Aug 14, 2024
4452f0a
setting
minsu-zip Aug 14, 2024
fe0bd99
chore
minsu-zip Aug 14, 2024
3692ba0
chore
minsu-zip Aug 14, 2024
9acfb17
chore
minsu-zip Aug 23, 2024
705060d
chore
minsu-zip Aug 23, 2024
17495bf
chore
minsu-zip Aug 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: lighthouse

on:
workflow_dispatch:
pull_request:
branches:
- "main"
- "dev"
types:
- opened
- synchronize

jobs:
lighthouseci:
runs-on: ubuntu-latest
steps:
- name: Checkout repository // μ €μž₯μ†Œ 체크아웃
uses: actions/checkout@v3

- name: Install pnpm // pnpm μ„€μΉ˜
uses: pnpm/action-setup@v3
with:
version: 9.7.0
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install

- name: Run Lighthouse CI // Lighthouse μ‹€ν–‰
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
run: |
pnpm i -g @lhci/cli
lhci autorun || echo "Fail to Run Lighthouse CI!"

- name: Generate and Upload Lighthouse Report // 레포트 생성
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
run: |
lhci collect --additive
lhci upload --target=filesystem --outputDir=./lighthouse-reports
lhci upload --target=temporary-public-storage

- 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 path = require('path');
const resultsPath = path.join(process.env.GITHUB_WORKSPACE, 'lhci_reports', 'manifest.json');
const results = JSON.parse(fs.readFileSync(resultsPath));
const totalReports = results.length;

// best-practices은 λ¬Έμžμ—΄λ‘œ μ €μž₯ ( Lighthouse μ§€ν‘œ )
const averageScores = {
performance: 0,
accessibility: 0,
'best-practices': 0,
seo: 0,
pwa: 0
};

// Lighthouse 상세 μ§€ν‘œ
const auditSummaries = {
'first-contentful-paint': 0,
'largest-contentful-paint': 0,
'interactive': 0,
'total-blocking-time': 0,
'cumulative-layout-shift': 0
};

// 점수 평균
results.forEach(result => {
const { summary } = result;
for (const key in averageScores) {
averageScores[key] += summary[key];
}

const details = JSON.parse(fs.readFileSync(result.jsonPath));
['first-contentful-paint', 'largest-contentful-paint', 'interactive', 'total-blocking-time', 'cumulative-layout-shift'].forEach(auditName => {
if (details.audits[auditName]) {
const auditDetails = details.audits[auditName];
auditSummaries[auditName] += parseFloat(auditDetails.displayValue) || 0;
}
});
});

// μ μˆ˜μ— λ”°λ₯Έ 색상 ν‘œμ‹œ
const formatScore = res => (res >= 90 ? "🟒" : res >= 70 ? "🟠" : "πŸ”΄");

// 상세 μ§€ν‘œμ˜ ν‘œμ€€ μ μˆ˜μ— λ”°λ₯Έ 색상 ν‘œμ‹œ
const detailscore = (value, metric) => {
switch (metric) {
case 'first-contentful-paint':
return value <= 1.8 ? "🟒" : value <= 3 ? "🟠" : "πŸ”΄";
case 'largest-contentful-paint':
return value <= 2.5 ? "🟒" : value <= 4 ? "🟠" : "πŸ”΄";
case 'interactive':
return value <= 3.8 ? "🟒" : value <= 7.3 ? "🟠" : "πŸ”΄";
case 'total-blocking-time':
return value <= 300 ? "🟒" : value <= 600 ? "🟠" : "πŸ”΄";
case 'cumulative-layout-shift':
return value <= 0.1 ? "🟒" : value <= 0.25 ? "🟠" : "πŸ”΄";
default:
return "πŸ”΄"; // Default to red if metric is unknown
}
};

let comments = "⚑️ Lighthouse Average Scores Across Reports:\n| Category | Score |\n| --- | --- |\n";
Object.keys(averageScores).forEach(key => {
const avgScore = Math.round((averageScores[key] / totalReports) * 100);
comments += `| ${formatScore(avgScore)} ${key.replace(/-/g, ' ')} | ${avgScore} |\n`;
});

comments += "\n⚑️ Average Details Across All Reports:\n| Category | Score |\n| --- | --- |\n";
Object.keys(auditSummaries).forEach(auditName => {
const average = auditSummaries[auditName] / totalReports;
const formattedName = auditName.replace(/-/g, ' ');
const colorCode = detailscore(average, auditName);
const unit = (auditName === 'total-blocking-time' ? 'ms' : auditName === 'cumulative-layout-shift' ? '' : 's')
comments += `| ${colorCode} ${formattedName} | ${average.toFixed(1)}${unit} |\n`;
});

// PR 전솑
if (comments && context.issue.number) {
const issue_number = context.issue.number;
const repo = context.repo.repo;
const owner = context.repo.owner;
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: comments
});
} else {
console.log("No PR COMMENT!");
}

- name: comment PR
uses: unsplash/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: ${{ steps.format_lighthouse_score.outputs.comments }}
28 changes: 28 additions & 0 deletions .lighthouserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = {
ci: {
collect: {
startServerCommand: "pnpm run dev", // μ„œλ²„ μ‹€ν–‰
startServerReadyPattern: "ready on",
url: ["http://localhost:3000"], // μ‹€ν–‰ν•  μ£Όμ†Œ
numberOfRuns: 3, // μ‹€ν–‰ 횟수
settings: {
preset: "desktop",
},
},
upload: {
// 레포트 생성
target: "filesystem",
outputDir: "./lhci_reports",
reportFilenamePattern: "%%PATHNAME%%-%%DATETIME%%-report.%%EXTENSION%%",
},
assert: {
// 점수 κΈ°μ€€ 정리
assertions: {
"categories:performance": ["warn", { minScore: 0.8 }],
"categories:accessibility": ["warn", { minScore: 0.8 }],
"categories:best-practices": ["warn", { minScore: 0.8 }],
"categories:seo": ["warn", { minScore: 0.8 }],
},
},
},
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"zustand": "^4.5.2"
},
"devDependencies": {
"@lhci/cli": "^0.14.0",
"@types/js-cookie": "^3.0.6",
"@types/node": "^20",
"@types/react": "^18",
Expand Down
Loading
Loading