Skip to content

feat: lighthouse setting #32

feat: lighthouse setting

feat: lighthouse setting #32

Workflow file for this run

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@v4
- 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: Build the project
env:
AUTH_KAKAO_ID: ${{ secrets.AUTH_KAKAO_ID }}
AUTH_KAKAO_SECRET: ${{ secrets.AUTH_KAKAO_SECRET }}
AUTH_SECRET: ${{ secrets.AUTH_SECRET }}
AUTH_URL: ${{ secrets.AUTH_URL }}
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }}
NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL }}
NEXT_PUBLIC_NEXTAUTH_SECRET: ${{ secrets.NEXT_PUBLIC_NEXTAUTH_SECRET }}
NEXT_PUBLIC_GOOGLE_SITE_VERIFICATION: ${{ secrets.NEXT_PUBLIC_GOOGLE_SITE_VERIFICATION }}
NEXT_PUBLIC_METADATABASE: ${{ secrets.NEXT_PUBLIC_METADATABASE }}
NEXT_PUBLIC_OPENGRAPH_URL: ${{ secrets.NEXT_PUBLIC_OPENGRAPH_URL }}
run: pnpm run build
- 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: 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');
console.log(`Looking for results in ${resultsPath}`);
const results = JSON.parse(fs.readFileSync(resultsPath));
let comments = ""
results.forEach((result,index) => {
const { summary } = result;
const formatResult = (res) => Math.round(res * 100);
Object.keys(summary).forEach(
(key) => (summary[key] = formatResult(summary[key]))
);
const score = (res) => (res >= 90 ? "🟢" : res >= 70 ? "🟠" : "🔴");
const comment = [
`⚡️ **Lighthouse report ${index + 1}**`,
`| 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} |`,
`| ${score(summary.pwa)} PWA | ${summary.pwa} |`,
`\n`,
].join("\n");
comments += comment + "\n";
});
core.setOutput('comments', comments)
- name: comment PR
uses: unsplash/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: ${{ steps.format_lighthouse_score.outputs.comments }}