|
| 1 | +name: Performance Regression Check |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - 'src/**' |
| 7 | + - 'package.json' |
| 8 | + - 'pnpm-lock.yaml' |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + |
| 13 | +jobs: |
| 14 | + performance-check: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout PR |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Setup Node.js |
| 22 | + uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: '20' |
| 25 | + |
| 26 | + - name: Setup pnpm |
| 27 | + uses: pnpm/action-setup@v2 |
| 28 | + with: |
| 29 | + version: 8 |
| 30 | + |
| 31 | + - name: Install dependencies |
| 32 | + run: pnpm install --frozen-lockfile |
| 33 | + |
| 34 | + - name: Build project |
| 35 | + run: pnpm build |
| 36 | + |
| 37 | + - name: Checkout main branch baseline |
| 38 | + if: github.event_name == 'pull_request' |
| 39 | + run: | |
| 40 | + git fetch origin main |
| 41 | + git checkout origin/main -- bench/.baseline/performance-baseline.json || true |
| 42 | + git checkout - |
| 43 | +
|
| 44 | + - name: Capture baseline (main branch only) |
| 45 | + if: github.ref == 'refs/heads/main' |
| 46 | + run: node bench/capture-baseline.js |
| 47 | + |
| 48 | + - name: Check for regressions |
| 49 | + if: github.event_name == 'pull_request' |
| 50 | + id: regression-check |
| 51 | + run: | |
| 52 | + if node bench/check-regression.js; then |
| 53 | + echo "regression_detected=false" >> $GITHUB_OUTPUT |
| 54 | + else |
| 55 | + echo "regression_detected=true" >> $GITHUB_OUTPUT |
| 56 | + fi |
| 57 | +
|
| 58 | + - name: Upload regression report |
| 59 | + if: github.event_name == 'pull_request' && always() |
| 60 | + uses: actions/upload-artifact@v3 |
| 61 | + with: |
| 62 | + name: regression-report |
| 63 | + path: bench/.results/regression-report.md |
| 64 | + |
| 65 | + - name: Comment PR with results |
| 66 | + if: github.event_name == 'pull_request' && always() |
| 67 | + uses: actions/github-script@v7 |
| 68 | + with: |
| 69 | + script: | |
| 70 | + const fs = require('fs'); |
| 71 | + const path = require('path'); |
| 72 | +
|
| 73 | + try { |
| 74 | + const reportPath = path.join(process.env.GITHUB_WORKSPACE, 'bench', '.results', 'regression-report.md'); |
| 75 | + if (fs.existsSync(reportPath)) { |
| 76 | + const report = fs.readFileSync(reportPath, 'utf8'); |
| 77 | +
|
| 78 | + // Find existing comment |
| 79 | + const { data: comments } = await github.rest.issues.listComments({ |
| 80 | + owner: context.repo.owner, |
| 81 | + repo: context.repo.repo, |
| 82 | + issue_number: context.issue.number, |
| 83 | + }); |
| 84 | +
|
| 85 | + const botComment = comments.find(comment => |
| 86 | + comment.user.type === 'Bot' && |
| 87 | + comment.body.includes('Performance Regression Report') |
| 88 | + ); |
| 89 | +
|
| 90 | + const body = `🤖 **Performance Check Results**\n\n${report}`; |
| 91 | +
|
| 92 | + if (botComment) { |
| 93 | + // Update existing comment |
| 94 | + await github.rest.issues.updateComment({ |
| 95 | + owner: context.repo.owner, |
| 96 | + repo: context.repo.repo, |
| 97 | + comment_id: botComment.id, |
| 98 | + body |
| 99 | + }); |
| 100 | + } else { |
| 101 | + // Create new comment |
| 102 | + await github.rest.issues.createComment({ |
| 103 | + owner: context.repo.owner, |
| 104 | + repo: context.repo.repo, |
| 105 | + issue_number: context.issue.number, |
| 106 | + body |
| 107 | + }); |
| 108 | + } |
| 109 | + } |
| 110 | + } catch (error) { |
| 111 | + console.error('Failed to comment on PR:', error); |
| 112 | + } |
| 113 | +
|
| 114 | + - name: Fail if regression detected |
| 115 | + if: steps.regression-check.outputs.regression_detected == 'true' |
| 116 | + run: | |
| 117 | + echo "❌ Performance regression detected! See report above." |
| 118 | + exit 1 |
| 119 | +
|
| 120 | + - name: Commit baseline updates (main branch only) |
| 121 | + if: github.ref == 'refs/heads/main' |
| 122 | + run: | |
| 123 | + git config --local user.email "action@github.com" |
| 124 | + git config --local user.name "GitHub Action" |
| 125 | + git add bench/.baseline/performance-baseline.json |
| 126 | + git diff --staged --quiet || git commit -m "chore: update performance baseline [skip ci]" |
| 127 | + git push || true |
0 commit comments