Skip to content

2 feature/GitHub action lighthouse #3

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

Merged
merged 30 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
86ae45c
✨ Feat: Github Action lighthouse
shlee9999 Nov 16, 2024
91a7a34
✨ Feat: vite plugin compression 최적화
shlee9999 Nov 16, 2024
c5a2d3b
🔧 Chore: .gitignore lighthouse 관련 파일 추가
shlee9999 Nov 16, 2024
30b60b6
🔨 Setting: update lighthouse configuration
shlee9999 Nov 16, 2024
a28078f
🐛 Fix: lighthouserc ouputDir 설정
shlee9999 Nov 16, 2024
47e1c72
🐛 Fix: Vite에 맞춰 lighthouse 관련 수정
shlee9999 Nov 16, 2024
6bab92a
🐛 Fix: outputDir 경로 수정
shlee9999 Nov 16, 2024
b4c2caa
🐛 Fix: 개발 환경에서만 https 사용 -> lighthouse는 http에서 동작하도록 적용 완료
shlee9999 Nov 16, 2024
9a6dad1
🐛 Fix: numberOfRuns 5
shlee9999 Nov 16, 2024
5ffe9d1
✨ Feat: React Helmet and Routes
shlee9999 Nov 17, 2024
75bf4ab
✨ Feat: vite plugin legacy 적용
shlee9999 Nov 17, 2024
88cde10
✨ Feat: robots.txt
shlee9999 Nov 17, 2024
2398281
✨ Feat: lazy import
shlee9999 Nov 17, 2024
0669643
✨ Feat: chunk splitting을 통한 번들 사이즈 최적화
shlee9999 Nov 17, 2024
86e9e31
Chore: @vitejs/plugin-legacy 제거
shlee9999 Nov 17, 2024
4c60f19
🚚 Rename: Unit Test & Lighthouse CI -> Lighthouse CI
shlee9999 Nov 17, 2024
cddf14d
✨ Feat: react-helmet-async and CSP meta tag
shlee9999 Nov 17, 2024
6a2b8a7
✨ Feat: CSP 개선
shlee9999 Nov 17, 2024
fa1f631
🐛 Fix: CSP index.html에 적용
shlee9999 Nov 17, 2024
27902ef
🐛 Fix: csp-xss 오류 report only 설정
shlee9999 Nov 17, 2024
593406f
Merge branch '2-feature/github-action-lighthouse' of https://github.c…
shlee9999 Nov 17, 2024
e07b387
🐛 Fix: index.html CSP 제거
shlee9999 Nov 17, 2024
60173a4
✨ Feat: CSP-XSS 정보도 댓글에 추가
shlee9999 Nov 17, 2024
1a8186a
🐛 Fix: 댓글 report 중앙값 사용하도록 수정
shlee9999 Nov 17, 2024
9ebf6e2
✨ Feat: App.tsx meta description
shlee9999 Nov 17, 2024
3f5caa6
🐛Fix: HomaPage meta description
shlee9999 Nov 17, 2024
dd568cb
🔧Chore: move devDependencies from dependencies
shlee9999 Nov 17, 2024
09bda94
🐛Fix: Upload Lighthouse results
shlee9999 Nov 17, 2024
4ee7fe8
🐛Fix: Lighthouse assert 해제
shlee9999 Nov 18, 2024
e0e9664
🐛Fix: Lighthouse numberOfRuns 5로 설정
shlee9999 Nov 18, 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
15 changes: 4 additions & 11 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
env: { browser: true, es2020: true, node: true },
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:react-hooks/recommended'],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
},
};
}
127 changes: 127 additions & 0 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Lighthouse CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]

permissions:
contents: read
pull-requests: write

jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Configure npm registry
run: |
echo "Configuring npm to use public registry"
npm config set registry https://registry.npmjs.org/

- name: Clear npm cache
run: npm cache clean --force

- name: Remove package-lock.json
run: rm -f package-lock.json

- name: Install dependencies
run: npm install --registry=https://registry.npmjs.org/
env:
NODE_AUTH_TOKEN: ''

- name: Build project
run: npm run build

- name: Run Lighthouse CI
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
NODE_TLS_REJECT_UNAUTHORIZED: '0' # SSL 검증 비활성화
run: |
npm install -g @lhci/[email protected]
lhci autorun || echo "Lighthouse CI failed, but continuing"

- name: Upload Lighthouse results
uses: actions/upload-artifact@v4
with:
name: lighthouse-results
path: .lighthouseci
include-hidden-files: 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 reportPath = './lhci_reports/manifest.json';

if (!fs.existsSync(reportPath)) {
console.log('No Lighthouse report found');
return;
}

const results = JSON.parse(fs.readFileSync(reportPath));
// 중앙값 결과 찾기
const medianResult = results.find(entry => entry.isRepresentativeRun);
const details = JSON.parse(fs.readFileSync(medianResult.jsonPath));
const { summary } = medianResult;
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 performanceMetrics = [
`# ⚡ 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} |`
].join('\n');

// 상세 메트릭
const detailedMetrics = [
`\n### Detailed Metrics`,
`| Metric | Value |`,
`| --- | --- |`,
`| ${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} |`,
`| ${score(audits['total-blocking-time'].score * 100)} Total Blocking Time | ${audits['total-blocking-time'].displayValue} |`,
`| ${score(audits['cumulative-layout-shift'].score * 100)} Cumulative Layout Shift | ${audits['cumulative-layout-shift'].displayValue} |`,
`| ${score(audits['speed-index'].score * 100)} Speed Index | ${audits['speed-index'].displayValue} |`
].join('\n');

// 보안 검사 결과
const securityChecks = [
`\n### Security Checks`,
`| Check | Status | Details |`,
`| --- | --- | --- |`,
`| CSP-XSS | ${audits['csp-xss'] ? (audits['csp-xss'].score === 1 ? '✅' : '⚠️') : '❓'} | ${audits['csp-xss'] ? audits['csp-xss'].title : 'Not available'} |`
].join('\n');

const comments = performanceMetrics + '\n' + detailedMetrics + '\n' + securityChecks;
core.setOutput('comments', comments);

- name: Comment PR
if: github.event_name == 'pull_request'
uses: unsplash/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: ${{ steps.format_lighthouse_score.outputs.comments}}
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@ dev-dist
*.sw?

# .env
.env
.env

#lighthouse
.lighthouseci/
**/lighthouse-report.html
**/lighthouse.report.html
**/lighthouse/
.lighthouseci/*.html
.lighthouseci/*.json
lhci_reports
11 changes: 3 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DDang + TS</title>
<title>DDang | 반려견 산책 서비스</title>
<link rel="icon" href="/favicon.ico" />
<link
rel="apple-touch-icon"
href="/apple-touch-icon-180x180.png"
sizes="180x180"
/>
<link rel="apple-touch-icon" href="/apple-touch-icon-180x180.png" sizes="180x180" />
</head>
<body>
<div id="root"></div>
Expand Down
21 changes: 21 additions & 0 deletions lighthouserc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
ci: {
collect: {
startServerCommand: 'npm run preview',
url: ['http://localhost:4173'],
numberOfRuns: 5,
startServerReadyPattern: 'Local',
},
upload: {
target: 'filesystem',
outputDir: './lhci_reports',
reportFilenamePattern: '%%PATHNAME%%-%%DATETIME%%-report.%%EXTENSION%%',
},
// assert: {
// preset: 'lighthouse:recommended',
// assertions: {
// 'csp-xss': ['warn', {}],
// },
// },
},
}
Loading
Loading