@@ -450,46 +450,51 @@ async function main(): Promise<void> {
450
450
const octokit = github . getOctokit ( token )
451
451
452
452
// Get and parse the current workflow run.
453
- const { data : workflowRun } = await octokit . rest . actions . getWorkflowRun ( {
453
+ const { data : apiCurrentRun } = await octokit . rest . actions . getWorkflowRun ( {
454
454
...repo ,
455
455
run_id : github . context . runId
456
456
} )
457
- const treeHash = workflowRun . head_commit ?. tree_id
458
- if ( ! treeHash ) {
457
+ const currentTreeHash = apiCurrentRun . head_commit ?. tree_id
458
+ if ( ! currentTreeHash ) {
459
459
exitFail ( `
460
- Could not find the tree hash of run ${ workflowRun . id } (Workflow ID: ${ workflowRun . workflow_id } ,
461
- Name: ${ workflowRun . name } , Head Branch: ${ workflowRun . head_branch } , Head SHA: ${ workflowRun . head_sha } ).
460
+ Could not find the tree hash of run ${ apiCurrentRun . id } (Workflow ID: ${ apiCurrentRun . workflow_id } ,
461
+ Name: ${ apiCurrentRun . name } , Head Branch: ${ apiCurrentRun . head_branch } , Head SHA: ${ apiCurrentRun . head_sha } ).
462
462
This might be a run associated with a headless or removed commit.
463
463
` )
464
464
}
465
- const currentRun = mapWorkflowRun ( workflowRun , treeHash )
465
+ const currentRun = mapWorkflowRun ( apiCurrentRun , currentTreeHash )
466
466
467
467
// Fetch list of runs for current workflow.
468
468
const {
469
- data : { workflow_runs : workflowRuns }
469
+ data : { workflow_runs : apiAllRuns }
470
470
} = await octokit . rest . actions . listWorkflowRuns ( {
471
471
...repo ,
472
472
workflow_id : currentRun . workflowId ,
473
473
per_page : 100
474
474
} )
475
475
476
+ // List with all workflow runs.
477
+ const allRuns = [ ]
478
+ // List with older workflow runs only (used to prevent some nasty race conditions and edge cases).
479
+ const olderRuns = [ ]
480
+
476
481
// Check and map all runs.
477
- const allRuns = workflowRuns . reduce ( ( result : WorkflowRun [ ] , run ) => {
482
+ for ( const run of apiAllRuns ) {
478
483
// Filter out current run and runs that lack 'head_commit' (most likely runs associated with a headless or removed commit).
479
484
// See https://github.com/fkirc/skip-duplicate-actions/pull/178.
480
485
if ( run . id !== currentRun . id && run . head_commit ) {
481
- result . push ( mapWorkflowRun ( run , run . head_commit . tree_id ) )
486
+ const mappedRun = mapWorkflowRun ( run , run . head_commit . tree_id )
487
+ // Add to list of all runs.
488
+ allRuns . push ( mappedRun )
489
+ // Check if run can be added to list of older runs.
490
+ if (
491
+ new Date ( mappedRun . createdAt ) . getTime ( ) <
492
+ new Date ( currentRun . createdAt ) . getTime ( )
493
+ ) {
494
+ olderRuns . push ( mappedRun )
495
+ }
482
496
}
483
- return result
484
- } , [ ] )
485
-
486
- // List with older workflow runs only (used to prevent some nasty race conditions and edge cases).
487
- const olderRuns = allRuns . filter ( run => {
488
- return (
489
- new Date ( run . createdAt ) . getTime ( ) <
490
- new Date ( currentRun . createdAt ) . getTime ( )
491
- )
492
- } )
497
+ }
493
498
494
499
const skipDuplicateActions = new SkipDuplicateActions ( inputs , {
495
500
repo,
0 commit comments