|
| 1 | +name: Lighthouse CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +jobs: |
| 10 | + lighthouse: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Setup Node.js |
| 18 | + uses: actions/setup-node@v4 |
| 19 | + with: |
| 20 | + node-version: '18' |
| 21 | + |
| 22 | + - name: Setup pnpm |
| 23 | + uses: pnpm/action-setup@v4 |
| 24 | + with: |
| 25 | + version: 8 |
| 26 | + |
| 27 | + - name: Get pnpm store directory |
| 28 | + shell: bash |
| 29 | + run: | |
| 30 | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV |
| 31 | +
|
| 32 | + - name: Setup pnpm cache |
| 33 | + uses: actions/cache@v4 |
| 34 | + with: |
| 35 | + path: ${{ env.STORE_PATH }} |
| 36 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 37 | + restore-keys: | |
| 38 | + ${{ runner.os }}-pnpm-store- |
| 39 | +
|
| 40 | + - name: Install dependencies |
| 41 | + run: pnpm install --frozen-lockfile |
| 42 | + |
| 43 | + - name: Run Lighthouse CI |
| 44 | + run: pnpm lighthouse:ci |
| 45 | + |
| 46 | + - name: Upload Lighthouse results |
| 47 | + uses: actions/upload-artifact@v4 |
| 48 | + if: always() |
| 49 | + with: |
| 50 | + name: lighthouse-results |
| 51 | + path: .lighthouseci/ |
| 52 | + retention-days: 30 |
| 53 | + |
| 54 | + - name: Comment PR with Lighthouse results |
| 55 | + if: github.event_name == 'pull_request' |
| 56 | + uses: actions/github-script@v7 |
| 57 | + with: |
| 58 | + script: | |
| 59 | + const fs = require('fs'); |
| 60 | + const path = require('path'); |
| 61 | +
|
| 62 | + try { |
| 63 | + const resultsPath = '.lighthouseci/assertion-results.json'; |
| 64 | + if (fs.existsSync(resultsPath)) { |
| 65 | + const results = JSON.parse(fs.readFileSync(resultsPath, 'utf8')); |
| 66 | + |
| 67 | + let comment = '## 🚀 Lighthouse CI Results\n\n'; |
| 68 | + |
| 69 | + if (results.length === 0) { |
| 70 | + comment += '✅ All Lighthouse checks passed!\n'; |
| 71 | + } else { |
| 72 | + comment += '⚠️ Some Lighthouse checks failed:\n\n'; |
| 73 | + results.forEach(result => { |
| 74 | + const status = result.passed ? '✅' : '❌'; |
| 75 | + comment += `${status} **${result.auditTitle}**: ${result.actual}ms (기준: ${result.expected}ms)\n`; |
| 76 | + }); |
| 77 | + } |
| 78 | + |
| 79 | + comment += '\n📊 [View detailed report](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})'; |
| 80 | + |
| 81 | + github.rest.issues.createComment({ |
| 82 | + issue_number: context.issue.number, |
| 83 | + owner: context.repo.owner, |
| 84 | + repo: context.repo.repo, |
| 85 | + body: comment |
| 86 | + }); |
| 87 | + } |
| 88 | + } catch (error) { |
| 89 | + console.log('Error creating comment:', error); |
| 90 | + } |
0 commit comments