@@ -24,16 +24,15 @@ const { setFailed, startGroup, endGroup, debug } = require("@actions/core");
24
24
const { GitHub, context } = require ( "@actions/github" ) ;
25
25
const { exec } = require ( "@actions/exec" ) ;
26
26
const {
27
- getInput ,
27
+ config ,
28
28
runBenchmark,
29
29
averageBenchmarks,
30
30
toDiff,
31
31
diffTable,
32
- toBool,
33
32
} = require ( "./utils.js" ) ;
34
33
35
- const benchmarkParallel = 2 ;
36
- const benchmarkSerial = 2 ;
34
+ const benchmarkParallel = 4 ;
35
+ const benchmarkSerial = 4 ;
37
36
const runBenchmarks = async ( ) => {
38
37
let results = [ ] ;
39
38
for ( let i = 0 ; i < benchmarkSerial ; i ++ ) {
@@ -44,7 +43,10 @@ const runBenchmarks = async () => {
44
43
return averageBenchmarks ( results ) ;
45
44
} ;
46
45
47
- async function run ( octokit , context , token ) {
46
+ const perfActionComment =
47
+ "<!-- this-is-an-automated-performance-comment-do-not-edit -->" ;
48
+
49
+ async function run ( octokit , context ) {
48
50
const { number : pull_number } = context . issue ;
49
51
50
52
const pr = context . payload . pull_request ;
@@ -61,9 +63,8 @@ async function run(octokit, context, token) {
61
63
`PR #${ pull_number } is targetted at ${ pr . base . ref } (${ pr . base . sha } )`
62
64
) ;
63
65
64
- const buildScript = getInput ( "build-script" ) ;
65
- startGroup ( `[current] Build using '${ buildScript } '` ) ;
66
- await exec ( buildScript ) ;
66
+ startGroup ( `[current] Build using '${ config . buildScript } '` ) ;
67
+ await exec ( config . buildScript ) ;
67
68
endGroup ( ) ;
68
69
69
70
startGroup ( `[current] Running benchmark` ) ;
@@ -104,8 +105,8 @@ async function run(octokit, context, token) {
104
105
}
105
106
endGroup ( ) ;
106
107
107
- startGroup ( `[base] Build using '${ buildScript } '` ) ;
108
- await exec ( buildScript ) ;
108
+ startGroup ( `[base] Build using '${ config . buildScript } '` ) ;
109
+ await exec ( config . buildScript ) ;
109
110
endGroup ( ) ;
110
111
111
112
startGroup ( `[base] Running benchmark` ) ;
@@ -118,10 +119,7 @@ async function run(octokit, context, token) {
118
119
collapseUnchanged : true ,
119
120
omitUnchanged : false ,
120
121
showTotal : true ,
121
- minimumChangeThreshold : parseInt (
122
- getInput ( "minimum-change-threshold" ) ,
123
- 10
124
- ) ,
122
+ minimumChangeThreshold : config . minimumChangeThreshold ,
125
123
} ) ;
126
124
127
125
let outputRawMarkdown = false ;
@@ -133,79 +131,58 @@ async function run(octokit, context, token) {
133
131
134
132
const comment = {
135
133
...commentInfo ,
136
- body :
137
- markdownDiff +
138
- '\n\n<a href="https://github.com/j-f1/performance-action"><sub>performance-action</sub></a>' ,
134
+ body : markdownDiff + "\n\n" + perfActionComment ,
139
135
} ;
140
136
141
- if ( toBool ( getInput ( "use-check" ) ) ) {
142
- if ( token ) {
143
- const finish = await createCheck ( octokit , context ) ;
144
- await finish ( {
145
- conclusion : "success" ,
146
- output : {
147
- title : `Compressed Size Action` ,
148
- summary : markdownDiff ,
149
- } ,
150
- } ) ;
151
- } else {
152
- outputRawMarkdown = true ;
137
+ startGroup ( `Updating stats PR comment` ) ;
138
+ let commentId ;
139
+ try {
140
+ const comments = ( await octokit . issues . listComments ( commentInfo ) ) . data ;
141
+ for ( let i = comments . length ; i -- ; ) {
142
+ const c = comments [ i ] ;
143
+ if ( c . user . type === "Bot" && c . body . includes ( perfActionComment ) ) {
144
+ commentId = c . id ;
145
+ break ;
146
+ }
153
147
}
154
- } else {
155
- startGroup ( `Updating stats PR comment` ) ;
156
- let commentId ;
148
+ } catch ( e ) {
149
+ console . log ( "Error checking for previous comments: " + e . message ) ;
150
+ }
151
+
152
+ if ( commentId ) {
153
+ console . log ( `Updating previous comment #${ commentId } ` ) ;
157
154
try {
158
- const comments = ( await octokit . issues . listComments ( commentInfo ) )
159
- . data ;
160
- for ( let i = comments . length ; i -- ; ) {
161
- const c = comments [ i ] ;
162
- if (
163
- c . user . type === "Bot" &&
164
- / < s u b > [ \s \n ] * p e r f o r m a n c e - a c t i o n / . test ( c . body )
165
- ) {
166
- commentId = c . id ;
167
- break ;
168
- }
169
- }
155
+ await octokit . issues . updateComment ( {
156
+ ...context . repo ,
157
+ comment_id : commentId ,
158
+ body : comment . body ,
159
+ } ) ;
170
160
} catch ( e ) {
171
- console . log ( "Error checking for previous comments: " + e . message ) ;
161
+ console . log ( "Error editing previous comment: " + e . message ) ;
162
+ commentId = null ;
172
163
}
164
+ }
173
165
174
- if ( commentId ) {
175
- console . log ( `Updating previous comment #${ commentId } ` ) ;
166
+ // no previous or edit failed
167
+ if ( ! commentId ) {
168
+ console . log ( "Creating new comment" ) ;
169
+ try {
170
+ await octokit . issues . createComment ( comment ) ;
171
+ } catch ( e ) {
172
+ console . log ( `Error creating comment: ${ e . message } ` ) ;
173
+ console . log ( `Submitting a PR review comment instead...` ) ;
176
174
try {
177
- await octokit . issues . updateComment ( {
178
- ...context . repo ,
179
- comment_id : commentId ,
175
+ const issue = context . issue || pr ;
176
+ await octokit . pulls . createReview ( {
177
+ owner : issue . owner ,
178
+ repo : issue . repo ,
179
+ pull_number : issue . number ,
180
+ event : "COMMENT" ,
180
181
body : comment . body ,
181
182
} ) ;
182
183
} catch ( e ) {
183
- console . log ( "Error editing previous comment: " + e . message ) ;
184
- commentId = null ;
185
- }
186
- }
187
-
188
- // no previous or edit failed
189
- if ( ! commentId ) {
190
- console . log ( "Creating new comment" ) ;
191
- try {
192
- await octokit . issues . createComment ( comment ) ;
193
- } catch ( e ) {
194
- console . log ( `Error creating comment: ${ e . message } ` ) ;
195
- console . log ( `Submitting a PR review comment instead...` ) ;
196
- try {
197
- const issue = context . issue || pr ;
198
- await octokit . pulls . createReview ( {
199
- owner : issue . owner ,
200
- repo : issue . repo ,
201
- pull_number : issue . number ,
202
- event : "COMMENT" ,
203
- body : comment . body ,
204
- } ) ;
205
- } catch ( e ) {
206
- console . log ( "Error creating PR review." ) ;
207
- outputRawMarkdown = true ;
208
- }
184
+ console . log ( "Error creating PR review." ) ;
185
+ outputRawMarkdown = true ;
209
186
}
210
187
}
211
188
endGroup ( ) ;
@@ -225,31 +202,10 @@ async function run(octokit, context, token) {
225
202
console . log ( "All done!" ) ;
226
203
}
227
204
228
- // create a check and return a function that updates (completes) it
229
- async function createCheck ( octokit , context ) {
230
- const check = await octokit . checks . create ( {
231
- ...context . repo ,
232
- name : "Compressed Size" ,
233
- head_sha : context . payload . pull_request . head . sha ,
234
- status : "in_progress" ,
235
- } ) ;
236
-
237
- return async ( details ) => {
238
- await octokit . checks . update ( {
239
- ...context . repo ,
240
- check_run_id : check . data . id ,
241
- completed_at : new Date ( ) . toISOString ( ) ,
242
- status : "completed" ,
243
- ...details ,
244
- } ) ;
245
- } ;
246
- }
247
-
248
205
( async ( ) => {
249
206
try {
250
- const token = getInput ( "repo-token" , { required : true } ) ;
251
- const octokit = new GitHub ( token ) ;
252
- await run ( octokit , context , token ) ;
207
+ const octokit = new GitHub ( process . env . GITHUB_TOKEN ) ;
208
+ await run ( octokit , context ) ;
253
209
} catch ( e ) {
254
210
setFailed ( e . message ) ;
255
211
}
0 commit comments