Skip to content

Commit

Permalink
env : Lighthouse cicd 적용 (#436)
Browse files Browse the repository at this point in the history
* env : Lighthouse cli  설치

* chore : Ligthhouse 설정 적용

* chore : gitignore수정

.lighthouseci 추가

* chore : ligthhouse 성능 수정

* ci : ci name 변경

* ci : lighthouse ci 적용

* ci : ligthhouse ci 테스트

* ci : lighthouse ci 수정

* ci : ci 코멘트 작성 방식 수정

* ci : ci 테스트

* chore : ligthhouse 설정 변경

* ci : ci 수정

* ci : 평균값을 계산하도록 수정

* ci : ci 수정

* ci : 평균 구하도록 적용

* ci : ci 수정
  • Loading branch information
HelloWook authored Dec 26, 2024
1 parent 6d61cd3 commit ec3bac6
Show file tree
Hide file tree
Showing 8 changed files with 4,021 additions and 57 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ jobs:
run: yarn build

- name: Comment on PR
uses: thollander/actions-comment-pull-request@v1
uses: thollander/actions-comment-pull-request@v2
if: success() && github.event_name == 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: '**✅ Build 성공!**'
comment_tag: build
mode: upsert
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: postamn
name: deploy aws

on:
push:
Expand Down
110 changes: 110 additions & 0 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Run lighthouse

on:
pull_request:
branches: develope
push:
branches: develope

jobs:
lighthouse:
name: Lighthouse CI
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20.18.0'

- name: Install dependencies
run: yarn install

- name: Build project
run: yarn build

- name: Run Lighthouse CI
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
run: |
yarn dlx @lhci/cli autorun
- 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("./lhci_reports/manifest.json"));
const totals = {
summary: {
performance: 0,
accessibility: 0,
seo: 0,
'best-practices': 0
},
audits: {
'first-contentful-paint': { score: 0, value: 0 },
'largest-contentful-paint': { score: 0, value: 0 },
'cumulative-layout-shift': { score: 0, value: 0 }
}
};
results.forEach(result => {
const { summary } = result;
const details = JSON.parse(fs.readFileSync(result.jsonPath));
const { audits } = details;
Object.keys(totals.summary).forEach(key => {
totals.summary[key] += summary[key];
});
Object.keys(totals.audits).forEach(key => {
totals.audits[key].score += audits[key].score;
totals.audits[key].value += parseFloat(audits[key].displayValue);
});
});
const count = results.length;
Object.keys(totals.summary).forEach(key => {
totals.summary[key] = Math.round((totals.summary[key] / count) * 100);
});
Object.keys(totals.audits).forEach(key => {
totals.audits[key].score = totals.audits[key].score / count;
totals.audits[key].value = (totals.audits[key].value / count).toFixed(1);
});
const score = (res) => (res >= 90 ? "🟢" : res >= 50 ? "🟠" : "🔴");
const comment = [
`## ⚡️ Lighthouse Report (Average of ${count} runs)`,
`| Category | Score |`,
`| --- | --- |`,
`| ${score(totals.summary.performance)} Performance | ${totals.summary.performance} |`,
`| ${score(totals.summary.accessibility)} Accessibility | ${totals.summary.accessibility} |`,
`| ${score(totals.summary.seo)} SEO | ${totals.summary.seo} |`,
`| ${score(totals.summary['best-practices'])} Best Practices | ${totals.summary['best-practices']} |`,
``,
`### Core Web Vitals (Average)`,
`| Metric | Value |`,
`| --- | --- |`,
`| ${score(totals.audits['first-contentful-paint'].score * 100)} First Contentful Paint | ${totals.audits['first-contentful-paint'].value} s |`,
`| ${score(totals.audits['largest-contentful-paint'].score * 100)} Largest Contentful Paint | ${totals.audits['largest-contentful-paint'].value} s |`,
`| ${score(totals.audits['cumulative-layout-shift'].score * 100)} Cumulative Layout Shift | ${totals.audits['cumulative-layout-shift'].value} |`
].join('\n');
core.setOutput('comments', comment);
- name: Comment PR
if: github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
message: ${{ steps.format_lighthouse_score.outputs.comments }}
comment_tag: lighthouse
mode: upsert
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ vite_cache
.env
.env.local
.env.development
.env.production
.env.production


### Lighthouse
.lighthouseci
lhci_reports
30 changes: 30 additions & 0 deletions .lighthouserc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @lighthouserc.js
module.exports = {
ci: {
collect: {
staticDistDir: './dist',
url: ['http://localhost:3000'],
numberOfRuns: 5
},
assert: {
assertions: {
'categories:performance': ['warn', { minScore: 0.7 }],
'categories:accessibility': ['warn', { minScore: 0.7 }],
'categories:seo': ['warn', { minScore: 0.7 }],
'categories:best-practices': ['warn', { minScore: 0.7 }],
'first-contentful-paint': ['warn', { maxNumericValue: 2000 }],
'largest-contentful-paint': ['warn', { maxNumericValue: 2500 }],
'cumulative-layout-shift': ['warn', { maxNumericValue: 0.1 }]
}
},
upload: {
target: 'filesystem',
outputDir: './lhci_reports',
reportFilenamePattern:
'%%PATHNAME%%-%%DATETIME%%-report.%%EXTENSION%%'
},
server: {
port: 9000
}
}
};
Loading

0 comments on commit ec3bac6

Please sign in to comment.