66// ----------------------------------------------------------------------------
77
88import * as core from '@actions/core'
9- import * as github from '@actions/github'
10- import { formatDuration , getArgs , isTimedOut , sleep } from './utils' ;
11- import { WorkflowHandler , WorkflowRunConclusion , WorkflowRunResult , WorkflowRunStatus } from './workflow-handler' ;
12- import { handleWorkflowLogsPerJob } from './workflow-logs-handler' ;
9+ import { formatDuration , getArgs , isTimedOut , sleep } from './utils'
10+ import { WorkflowHandler , WorkflowRunConclusion , WorkflowRunResult , WorkflowRunStatus } from './workflow-handler'
11+ import { handleWorkflowLogsPerJob } from './workflow-logs-handler'
1312
1413
1514
1615async function getFollowUrl ( workflowHandler : WorkflowHandler , interval : number , timeout : number ) {
17- const start = Date . now ( ) ;
18- let url ;
16+ const start = Date . now ( )
17+ let url
1918 do {
20- await sleep ( interval ) ;
19+ await sleep ( interval )
2120 try {
22- const result = await workflowHandler . getWorkflowRunStatus ( ) ;
23- url = result . url ;
21+ const result = await workflowHandler . getWorkflowRunStatus ( )
22+ url = result . url
2423 } catch ( e : any ) {
25- core . debug ( `Failed to get workflow url: ${ e . message } ` ) ;
24+ core . debug ( `Failed to get workflow url: ${ e . message } ` )
2625 }
27- } while ( ! url && ! isTimedOut ( start , timeout ) ) ;
28- return url ;
26+ } while ( ! url && ! isTimedOut ( start , timeout ) )
27+ return url
2928}
3029
3130async function waitForCompletionOrTimeout ( workflowHandler : WorkflowHandler , checkStatusInterval : number , waitForCompletionTimeout : number ) {
32- const start = Date . now ( ) ;
33- let status ;
34- let result ;
31+ const start = Date . now ( )
32+ let status
33+ let result
3534 do {
36- await sleep ( checkStatusInterval ) ;
35+ await sleep ( checkStatusInterval )
3736 try {
38- result = await workflowHandler . getWorkflowRunStatus ( ) ;
39- status = result . status ;
37+ result = await workflowHandler . getWorkflowRunStatus ( )
38+ status = result . status
4039 core . debug ( `Worflow is running for ${ formatDuration ( Date . now ( ) - start ) } . Current status=${ status } ` )
4140 } catch ( e : any ) {
42- core . warning ( `Failed to get workflow status: ${ e . message } ` ) ;
41+ core . warning ( `Failed to get workflow status: ${ e . message } ` )
4342 }
44- } while ( status !== WorkflowRunStatus . COMPLETED && ! isTimedOut ( start , waitForCompletionTimeout ) ) ;
43+ } while ( status !== WorkflowRunStatus . COMPLETED && ! isTimedOut ( start , waitForCompletionTimeout ) )
4544 return { result, start }
4645}
4746
4847function computeConclusion ( start : number , waitForCompletionTimeout : number , result ?: WorkflowRunResult ) {
4948 if ( isTimedOut ( start , waitForCompletionTimeout ) ) {
50- core . info ( ` Workflow wait timed out` ) ;
51- core . setOutput ( 'workflow-conclusion' , WorkflowRunConclusion . TIMED_OUT ) ;
52- throw new Error ( 'Workflow run has failed due to timeout' ) ;
49+ core . info ( ' Workflow wait timed out' )
50+ core . setOutput ( 'workflow-conclusion' , WorkflowRunConclusion . TIMED_OUT )
51+ throw new Error ( 'Workflow run has failed due to timeout' )
5352 }
5453
55- core . info ( `Workflow completed with conclusion=${ result ?. conclusion } ` ) ;
56- const conclusion = result ?. conclusion ;
57- core . setOutput ( 'workflow-conclusion' , conclusion ) ;
54+ core . info ( `Workflow completed with conclusion=${ result ?. conclusion } ` )
55+ const conclusion = result ?. conclusion
56+ core . setOutput ( 'workflow-conclusion' , conclusion )
5857
59- if ( conclusion === WorkflowRunConclusion . FAILURE ) throw new Error ( 'Workflow run has failed' ) ;
60- if ( conclusion === WorkflowRunConclusion . CANCELLED ) throw new Error ( 'Workflow run was cancelled' ) ;
61- if ( conclusion === WorkflowRunConclusion . TIMED_OUT ) throw new Error ( 'Workflow run has failed due to timeout' ) ;
58+ if ( conclusion === WorkflowRunConclusion . FAILURE ) throw new Error ( 'Workflow run has failed' )
59+ if ( conclusion === WorkflowRunConclusion . CANCELLED ) throw new Error ( 'Workflow run was cancelled' )
60+ if ( conclusion === WorkflowRunConclusion . TIMED_OUT ) throw new Error ( 'Workflow run has failed due to timeout' )
6261}
6362
6463async function handleLogs ( args : any , workflowHandler : WorkflowHandler ) {
6564 try {
6665 const workflowRunId = await workflowHandler . getWorkflowRunId ( )
67- await handleWorkflowLogsPerJob ( args , workflowRunId ) ;
66+ await handleWorkflowLogsPerJob ( args , workflowRunId )
6867 } catch ( e : any ) {
69- core . error ( `Failed to handle logs of triggered workflow. Cause: ${ e } ` ) ;
68+ core . error ( `Failed to handle logs of triggered workflow. Cause: ${ e } ` )
7069 }
7170}
7271
@@ -75,34 +74,34 @@ async function handleLogs(args: any, workflowHandler: WorkflowHandler) {
7574//
7675async function run ( ) : Promise < void > {
7776 try {
78- const args = getArgs ( ) ;
79- const workflowHandler = new WorkflowHandler ( args . token , args . workflowRef , args . owner , args . repo , args . ref , args . runName ) ;
77+ const args = getArgs ( )
78+ const workflowHandler = new WorkflowHandler ( args . token , args . workflowRef , args . owner , args . repo , args . ref , args . runName )
8079
8180 // Trigger workflow run
82- await workflowHandler . triggerWorkflow ( args . inputs ) ;
83- core . info ( ` Workflow triggered 🚀` ) ;
81+ await workflowHandler . triggerWorkflow ( args . inputs )
82+ core . info ( ' Workflow triggered 🚀' )
8483
8584 if ( args . displayWorkflowUrl ) {
8685 const url = await getFollowUrl ( workflowHandler , args . displayWorkflowUrlInterval , args . displayWorkflowUrlTimeout )
87- core . info ( `You can follow the running workflow here: ${ url } ` ) ;
88- core . setOutput ( 'workflow-url' , url ) ;
86+ core . info ( `You can follow the running workflow here: ${ url } ` )
87+ core . setOutput ( 'workflow-url' , url )
8988 }
9089
9190 if ( ! args . waitForCompletion ) {
92- return ;
91+ return
9392 }
9493
95- core . info ( ` Waiting for workflow completion` ) ;
96- const { result, start } = await waitForCompletionOrTimeout ( workflowHandler , args . checkStatusInterval , args . waitForCompletionTimeout ) ;
94+ core . info ( ' Waiting for workflow completion' )
95+ const { result, start } = await waitForCompletionOrTimeout ( workflowHandler , args . checkStatusInterval , args . waitForCompletionTimeout )
9796
98- await handleLogs ( args , workflowHandler ) ;
97+ await handleLogs ( args , workflowHandler )
9998
100- core . setOutput ( 'workflow-id' , result ?. id ) ;
101- core . setOutput ( 'workflow-url' , result ?. url ) ;
102- computeConclusion ( start , args . waitForCompletionTimeout , result ) ;
99+ core . setOutput ( 'workflow-id' , result ?. id )
100+ core . setOutput ( 'workflow-url' , result ?. url )
101+ computeConclusion ( start , args . waitForCompletionTimeout , result )
103102
104103 } catch ( error : any ) {
105- core . setFailed ( error . message ) ;
104+ core . setFailed ( error . message )
106105 }
107106}
108107
0 commit comments