@@ -14,44 +14,42 @@ permissions:
1414 contents : read
1515
1616jobs :
17- performance-check :
17+ regression :
18+ if : github.event_name == 'pull_request'
1819 runs-on : ubuntu-latest
1920
2021 steps :
21- - name : Checkout PR
22- uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
22+ - name : Checkout repository
23+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2324 with :
24- persist-credentials : false
25+ persist-credentials : true
2526
2627 - name : Setup Node.js
27- uses : actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
28+ uses : actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
2829 with :
2930 node-version : ' 20'
3031
32+ - name : Enable Corepack
33+ run : corepack enable
34+
3135 - name : Setup pnpm
3236 uses : pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
3337 with :
3438 version : 10.17.1
39+ run_install : false
3540
3641 - name : Install dependencies
3742 run : pnpm install --frozen-lockfile
3843
3944 - name : Build project
4045 run : pnpm build
4146
42- - name : Checkout main branch baseline
43- if : github.event_name == 'pull_request'
47+ - name : Restore main baseline
4448 run : |
45- git fetch origin main
49+ git fetch origin main --depth=1
4650 git checkout origin/main -- bench/.baseline/performance-baseline.json || true
47- git checkout -
48-
49- - name : Capture baseline (main branch only)
50- if : github.ref == 'refs/heads/main'
51- run : node bench/capture-baseline.js
5251
5352 - name : Check for regressions
54- if : github.event_name == 'pull_request'
5553 id : regression-check
5654 run : |
5755 if node bench/check-regression.js; then
@@ -61,59 +59,58 @@ jobs:
6159 fi
6260
6361 - name : Upload regression report
64- if : github.event_name == 'pull_request' && always()
62+ if : always()
6563 uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
6664 with :
6765 name : regression-report
6866 path : bench/.results/regression-report.md
67+ if-no-files-found : ignore
6968
7069 - name : Comment PR with results
71- if : github.event_name == 'pull_request' && always()
72- uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
70+ if : always()
71+ uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
7372 with :
7473 script : |
7574 const fs = require('fs');
7675 const path = require('path');
76+ const reportPath = path.join(process.env.GITHUB_WORKSPACE, 'bench', '.results', 'regression-report.md');
7777
78- try {
79- const reportPath = path.join(process.env.GITHUB_WORKSPACE, 'bench', '.results', 'regression-report.md');
80- if (fs.existsSync(reportPath)) {
81- const report = fs.readFileSync(reportPath, 'utf8');
82-
83- // Find existing comment
84- const { data: comments } = await github.rest.issues.listComments({
85- owner: context.repo.owner,
86- repo: context.repo.repo,
87- issue_number: context.issue.number,
88- });
89-
90- const botComment = comments.find(comment =>
91- comment.user.type === 'Bot' &&
92- comment.body.includes('Performance Regression Report')
93- );
94-
95- const body = `🤖 **Performance Check Results**\n\n${report}`;
96-
97- if (botComment) {
98- // Update existing comment
99- await github.rest.issues.updateComment({
100- owner: context.repo.owner,
101- repo: context.repo.repo,
102- comment_id: botComment.id,
103- body
104- });
105- } else {
106- // Create new comment
107- await github.rest.issues.createComment({
108- owner: context.repo.owner,
109- repo: context.repo.repo,
110- issue_number: context.issue.number,
111- body
112- });
113- }
114- }
115- } catch (error) {
116- console.error('Failed to comment on PR:', error);
78+ if (!fs.existsSync(reportPath)) {
79+ return;
80+ }
81+
82+ const report = fs.readFileSync(reportPath, 'utf8');
83+ const body = `🤖 **Performance Check Results**
84+
85+ ${report}`;
86+
87+ const response = await github.rest.issues.listComments({
88+ owner: context.repo.owner,
89+ repo: context.repo.repo,
90+ issue_number: context.issue.number,
91+ });
92+
93+ const comments = response.data;
94+
95+ const botComment = comments.find(comment =>
96+ comment.user.type === 'Bot' &&
97+ comment.body.includes('Performance Check Results')
98+ );
99+
100+ if (botComment) {
101+ await github.rest.issues.updateComment({
102+ owner: context.repo.owner,
103+ repo: context.repo.repo,
104+ comment_id: botComment.id,
105+ body,
106+ });
107+ } else {
108+ await github.rest.issues.createComment({
109+ owner: context.repo.owner,
110+ repo: context.repo.repo,
111+ issue_number: context.issue.number,
112+ body,
113+ });
117114 }
118115
119116 - name : Fail if regression detected
@@ -122,8 +119,41 @@ jobs:
122119 echo "❌ Performance regression detected! See report above."
123120 exit 1
124121
125- - name : Commit baseline updates (main branch only)
126- if : github.ref == 'refs/heads/main'
122+ update-baseline :
123+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
124+ runs-on : ubuntu-latest
125+
126+ steps :
127+ - name : Checkout repository
128+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
129+ with :
130+ fetch-depth : 0
131+ persist-credentials : true
132+
133+ - name : Setup Node.js
134+ uses : actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
135+ with :
136+ node-version : ' 20'
137+
138+ - name : Enable Corepack
139+ run : corepack enable
140+
141+ - name : Setup pnpm
142+ uses : pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
143+ with :
144+ version : 10.17.1
145+ run_install : false
146+
147+ - name : Install dependencies
148+ run : pnpm install --frozen-lockfile
149+
150+ - name : Build project
151+ run : pnpm build
152+
153+ - name : Capture baseline
154+ run : node bench/capture-baseline.js
155+
156+ - name : Commit baseline updates
127157 run : |
128158 git config --local user.email "action@github.com"
129159 git config --local user.name "GitHub Action"
0 commit comments