Skip to content

Format README table for user roles and values #364

Format README table for user roles and values

Format README table for user roles and values #364

Workflow file for this run

# CI 워크플로우 이름 설정
name: CI
# 워크플로우가 실행되는 이벤트 설정 (main, dev 브랜치에 push 또는 pull_request 발생 시)
on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
# 워크플로우 내 작업 정의
jobs:
# 린트 및 타입 체크 작업
lint-and-type-check:
runs-on: ubuntu-latest
steps:
# 소스 코드 체크아웃 (저장소 코드 가져오기)
- uses: actions/checkout@v4
# pnpm 설정 (setup-node 캐시가 pnpm을 찾을 수 있도록 선행)
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.28.0
# Node.js 설정 (프로젝트에 지정된 버전 사용 및 pnpm 캐시 활성화)
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
# 의존성 설치 (pnpm install로 lockfile 기준 설치)
- name: Install dependencies
run: |
corepack enable
corepack prepare pnpm@10.28.0 --activate
pnpm install --frozen-lockfile
# ESLint 실행 (코드 스타일 및 품질 검사)
- name: Run ESLint
run: pnpm run lint
# 코드 포맷팅 검사 (포맷이 맞는지 확인)
- name: Check code formatting
run: pnpm run format:check
# 타입 검사 (TypeScript 타입 체크)
- name: Type check
run: pnpm run type-check
# 빌드 작업 (린트 및 타입 체크가 성공한 후 실행)
build:
runs-on: ubuntu-latest
needs: lint-and-type-check
steps:
# 소스 코드 체크아웃 (저장소 코드 가져오기)
- uses: actions/checkout@v4
# pnpm 설정 (setup-node 캐시가 pnpm을 찾을 수 있도록 선행)
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.28.0
# Node.js 설정 (프로젝트에 지정된 버전 사용 및 pnpm 캐시 활성화)
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
# 의존성 설치 (pnpm install로 lockfile 기준 설치)
- name: Install dependencies
run: |
corepack enable
corepack prepare pnpm@10.28.0 --activate
pnpm install --frozen-lockfile
# 프로젝트 빌드 실행
- name: Build
run: pnpm run build
lighthouse-ci:
runs-on: ubuntu-latest
needs: build # 빌드가 성공해야 성능 측정의 의미를 둔다
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.28.0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build project
run: pnpm run build
- name: Run lighthouse CI
run: |
pnpm exec lhci collect --outputDir=./.lighthouseci
pnpm exec lhci assert
# 1. 상세 리포트를 구글 서버에 업로드하고 그 결과(링크)를 로그에 남김
pnpm exec lhci upload --target=temporary-public-storage
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
- name: Format lighthouse score
id: format_lighthouse_score
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const lhciDir = './.lighthouseci';
// 1. 폴더 내 lhr-로 시작하는 json 파일들 필터링
const lhrFiles = fs.readdirSync(lhciDir).filter(file => file.startsWith('lhr-') && file.endsWith('.json'));
if (lhrFiles.length === 0) {
core.setFailed("Lighthouse report files (.json) not found in .lighthouseci directory!");
return;
}
// 2. 여러 번 실행했다면 그중 첫 번째(혹은 대표) 파일을 읽음
const rawData = fs.readFileSync(path.join(lhciDir, lhrFiles[0]));
const result = JSON.parse(rawData);
const { categories } = result;
const formatScore = (score) => Math.round(score * 100);
const getEmoji = (score) => (score >= 0.9 ? "🟢" : score >= 0.7 ? "🟠" : "🔴");
let comments = "## ⚡️ Lighthouse Report\n\n";
comments += `### 🏠 URL: ${result.requestedUrl}\n`;
comments += `| Category | Score |\n| --- | --- |\n`;
comments += `| ${getEmoji(categories.performance.score)} Performance | ${formatScore(categories.performance.score)} |\n`;
comments += `| ${getEmoji(categories.accessibility.score)} Accessibility | ${formatScore(categories.accessibility.score)} |\n`;
comments += `| ${getEmoji(categories['best-practices'].score)} Best practices | ${formatScore(categories['best-practices'].score)} |\n`;
comments += `| ${getEmoji(categories.seo.score)} SEO | ${formatScore(categories.seo.score)} |\n\n`;
comments += "> 상세 리포트는 하단의 **lhci/url** Checks 내 Details 링크를 확인해주세요! 🚀";
core.setOutput('comments', comments);
- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
if: github.event_name == 'pull_request' # PR일 때만 댓글 작성
with:
message: ${{ steps.format_lighthouse_score.outputs.comments }}