GNB, 커뮤니티, QNA 페이지 UI 구현 #164
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run lighthouse CI When Push | |
on: | |
pull_request: | |
branches-ignore: | |
- 'main' | |
jobs: | |
lhci: | |
name: Lighthouse CI | |
runs-on: ubuntu-latest | |
env: | |
working-directory: ./client | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Use Node.js | |
uses: actions/setup-node@v1 | |
with: | |
node-version: '20' | |
- name: Generate Environment Variables File for Production | |
run: echo "NEXT_PUBLIC_OPEN_API=$NEXT_PUBLIC_OPEN_API\nNEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL" >> .env.production | |
working-directory: ${{ env.working-directory }} | |
env: | |
NEXT_PUBLIC_OPEN_API: ${{ secrets.NEXT_PUBLIC_OPEN_API }} | |
NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL }} | |
- name: test | |
run: pwd | |
working-directory: ${{ env.working-directory }} | |
- name: Install packages | |
run: yarn install && yarn global add @lhci/[email protected] | |
working-directory: ${{ env.working-directory }} | |
- name: Build | |
run: yarn build | |
working-directory: ${{ env.working-directory }} | |
- name: Run Lighthouse CI | |
run: lhci autorun | |
env: | |
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} | |
working-directory: ${{ env.working-directory }} | |
- 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("${{ env.working-directory }}/lhci_reports/manifest.json")); | |
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}`, | |
`| 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}} |