@@ -210,6 +210,7 @@ async function run() {
210
210
// Else, we run size limit for the current branch, AND fetch it for the comparison branch
211
211
let base ;
212
212
let current ;
213
+ let baseIsNotLatest = false ;
213
214
214
215
try {
215
216
const artifacts = await getArtifactsForBranchAndWorkflow ( octokit , {
@@ -231,6 +232,11 @@ async function run() {
231
232
} ) ;
232
233
233
234
base = JSON . parse ( await fs . readFile ( resultsFilePath , { encoding : 'utf8' } ) ) ;
235
+
236
+ if ( ! artifacts . isLatest ) {
237
+ baseIsNotLatest = true ;
238
+ core . info ( 'Base artifact is not the latest one. This may lead to incorrect results.' ) ;
239
+ }
234
240
} catch ( error ) {
235
241
core . startGroup ( 'Warning, unable to find base results' ) ;
236
242
core . error ( error ) ;
@@ -254,7 +260,17 @@ async function run() {
254
260
isNaN ( thresholdNumber ) || limit . hasSizeChanges ( base , current , thresholdNumber ) || sizeLimitComment ;
255
261
256
262
if ( shouldComment ) {
257
- const body = [ SIZE_LIMIT_HEADING , markdownTable ( limit . formatResults ( base , current ) ) ] . join ( '\r\n' ) ;
263
+ const bodyParts = [ SIZE_LIMIT_HEADING ] ;
264
+
265
+ if ( baseIsNotLatest ) {
266
+ bodyParts . push (
267
+ '⚠️ **Warning:** Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results.' ,
268
+ ) ;
269
+ }
270
+
271
+ bodyParts . push ( markdownTable ( limit . formatResults ( base , current ) ) ) ;
272
+
273
+ const body = bodyParts . join ( '\r\n' ) ;
258
274
259
275
try {
260
276
if ( ! sizeLimitComment ) {
@@ -303,7 +319,7 @@ const DEFAULT_PAGE_LIMIT = 10;
303
319
* This is a bit hacky since GitHub Actions currently does not directly
304
320
* support downloading artifacts from other workflows
305
321
*/
306
- export async function getArtifactsForBranchAndWorkflow ( octokit , { owner, repo, workflowName, branch, artifactName } ) {
322
+ async function getArtifactsForBranchAndWorkflow ( octokit , { owner, repo, workflowName, branch, artifactName } ) {
307
323
core . startGroup ( `getArtifactsForBranchAndWorkflow - workflow:"${ workflowName } ", branch:"${ branch } "` ) ;
308
324
309
325
let repositoryWorkflow = null ;
@@ -344,14 +360,13 @@ export async function getArtifactsForBranchAndWorkflow(octokit, { owner, repo, w
344
360
const workflow_id = repositoryWorkflow . id ;
345
361
346
362
let currentPage = 0 ;
347
- const completedWorkflowRuns = [ ] ;
363
+ let latestWorkflowRun = null ;
348
364
349
365
for await ( const response of octokit . paginate . iterator ( octokit . rest . actions . listWorkflowRuns , {
350
366
owner,
351
367
repo,
352
368
workflow_id,
353
369
branch,
354
- status : 'completed' ,
355
370
per_page : DEFAULT_PAGE_LIMIT ,
356
371
event : 'push' ,
357
372
} ) ) {
@@ -364,12 +379,38 @@ export async function getArtifactsForBranchAndWorkflow(octokit, { owner, repo, w
364
379
// Do not allow downloading artifacts from a fork.
365
380
const filtered = response . data . filter ( workflowRun => workflowRun . head_repository . full_name === `${ owner } /${ repo } ` ) ;
366
381
367
- console . log ( JSON . stringify ( filtered , null , 2 ) ) ;
382
+ // Store the first workflow run, to determine if this is the latest one...
383
+ if ( ! latestWorkflowRun ) {
384
+ latestWorkflowRun = filtered [ 0 ] ;
385
+ }
368
386
369
- completedWorkflowRuns . push ( ...filtered ) ;
387
+ // Search through workflow artifacts until we find a workflow run w/ artifact name that we are looking for
388
+ for ( const workflowRun of filtered ) {
389
+ core . info ( `Checking artifacts for workflow run: ${ workflowRun . html_url } ` ) ;
370
390
371
- if ( completedWorkflowRuns . length ) {
372
- break ;
391
+ const {
392
+ data : { artifacts } ,
393
+ } = await octokit . rest . actions . listWorkflowRunArtifacts ( {
394
+ owner,
395
+ repo,
396
+ run_id : workflowRun . id ,
397
+ } ) ;
398
+
399
+ if ( ! artifacts ) {
400
+ core . warning (
401
+ `Unable to fetch artifacts for branch: ${ branch } , workflow: ${ workflow_id } , workflowRunId: ${ workflowRun . id } ` ,
402
+ ) ;
403
+ } else {
404
+ const foundArtifact = artifacts . find ( ( { name } ) => name === artifactName ) ;
405
+ if ( foundArtifact ) {
406
+ core . info ( `Found suitable artifact: ${ foundArtifact . url } ` ) ;
407
+ return {
408
+ artifact : foundArtifact ,
409
+ workflowRun,
410
+ isLatest : latestWorkflowRun . id === workflowRun . id ,
411
+ } ;
412
+ }
413
+ }
373
414
}
374
415
375
416
if ( currentPage > DEFAULT_MAX_PAGES ) {
@@ -381,34 +422,6 @@ export async function getArtifactsForBranchAndWorkflow(octokit, { owner, repo, w
381
422
currentPage ++ ;
382
423
}
383
424
384
- // Search through workflow artifacts until we find a workflow run w/ artifact name that we are looking for
385
- for ( const workflowRun of completedWorkflowRuns ) {
386
- core . info ( `Checking artifacts for workflow run: ${ workflowRun . html_url } ` ) ;
387
-
388
- const {
389
- data : { artifacts } ,
390
- } = await octokit . rest . actions . listWorkflowRunArtifacts ( {
391
- owner,
392
- repo,
393
- run_id : workflowRun . id ,
394
- } ) ;
395
-
396
- if ( ! artifacts ) {
397
- core . warning (
398
- `Unable to fetch artifacts for branch: ${ branch } , workflow: ${ workflow_id } , workflowRunId: ${ workflowRun . id } ` ,
399
- ) ;
400
- } else {
401
- const foundArtifact = artifacts . find ( ( { name } ) => name === artifactName ) ;
402
- if ( foundArtifact ) {
403
- core . info ( `Found suitable artifact: ${ foundArtifact . url } ` ) ;
404
- return {
405
- artifact : foundArtifact ,
406
- workflowRun,
407
- } ;
408
- }
409
- }
410
- }
411
-
412
425
core . warning ( `Artifact not found: ${ artifactName } ` ) ;
413
426
core . endGroup ( ) ;
414
427
return null ;
0 commit comments