@@ -31,14 +31,15 @@ type githubActionsConfigProvider struct {
3131
3232type run struct {
3333 fetched bool
34- Status string `json:"status"`
3534 StartedAt time.Time `json:"run_started_at"`
3635}
3736
37+ // used to unmarshal list jobs of the current workflow run into []job
3838type job struct {
39- ID int64 `json:"id"`
40- Name string `json:"name"`
41- HtmlURL string `json:"html_url"`
39+ ID int64 `json:"id"`
40+ Name string `json:"name"`
41+ HtmlURL string `json:"html_url"`
42+ Conclusion string `json:"conclusion"`
4243}
4344
4445type fullLog struct {
@@ -75,19 +76,26 @@ func (g *githubActionsConfigProvider) OrchestratorType() string {
7576 return "GitHubActions"
7677}
7778
78- // BuildStatus returns current run status
79+ // BuildStatus returns current run status by looking at all jobs of the current workflow run
80+ // if any job has conclusion "failure" the whole run is considered failed
81+ // if any job has conclusion "cancelled" the whole run is considered aborted
82+ // otherwise the run is considered successful
7983func (g * githubActionsConfigProvider ) BuildStatus () string {
80- g .fetchRunData ()
81- switch g .runData .Status {
82- case "success" :
83- return BuildStatusSuccess
84- case "cancelled" :
85- return BuildStatusAborted
86- case "in_progress" :
87- return BuildStatusInProgress
88- default :
84+ if err := g .fetchJobs (); err != nil {
85+ log .Entry ().Debugf ("fetching jobs: %s" , err )
8986 return BuildStatusFailure
9087 }
88+
89+ for _ , j := range g .jobs {
90+ switch j .Conclusion {
91+ case "failure" :
92+ return BuildStatusFailure
93+ case "cancelled" :
94+ return BuildStatusAborted
95+ }
96+ }
97+
98+ return BuildStatusSuccess
9199}
92100
93101// FullLogs returns the whole logfile for the current pipeline run
@@ -261,12 +269,7 @@ func (g *githubActionsConfigProvider) fetchRunData() {
261269 return
262270 }
263271
264- runId , err := g .runIdInt64 ()
265- if err != nil {
266- log .Entry ().Errorf ("fetchRunData: %s" , err )
267- }
268-
269- runData , resp , err := g .client .Actions .GetWorkflowRunByID (g .ctx , g .owner , g .repo , runId )
272+ runData , resp , err := g .client .Actions .GetWorkflowRunByID (g .ctx , g .owner , g .repo , g .runIdInt64 ())
270273 if err != nil || resp .StatusCode != 200 {
271274 log .Entry ().Errorf ("failed to get API data: %s" , err )
272275 return
@@ -279,7 +282,6 @@ func (g *githubActionsConfigProvider) fetchRunData() {
279282func convertRunData (runData * github.WorkflowRun ) run {
280283 startedAtTs := piperutils .SafeDereference (runData .RunStartedAt )
281284 return run {
282- Status : piperutils .SafeDereference (runData .Status ),
283285 StartedAt : startedAtTs .Time ,
284286 }
285287}
@@ -289,12 +291,7 @@ func (g *githubActionsConfigProvider) fetchJobs() error {
289291 return nil
290292 }
291293
292- runId , err := g .runIdInt64 ()
293- if err != nil {
294- return err
295- }
296-
297- jobs , resp , err := g .client .Actions .ListWorkflowJobs (g .ctx , g .owner , g .repo , runId , nil )
294+ jobs , resp , err := g .client .Actions .ListWorkflowJobs (g .ctx , g .owner , g .repo , g .runIdInt64 (), nil )
298295 if err != nil || resp .StatusCode != 200 {
299296 return errors .Wrap (err , "failed to get API data" )
300297 }
@@ -312,22 +309,24 @@ func convertJobs(jobs []*github.WorkflowJob) []job {
312309 result := make ([]job , 0 , len (jobs ))
313310 for _ , j := range jobs {
314311 result = append (result , job {
315- ID : j .GetID (),
316- Name : j .GetName (),
317- HtmlURL : j .GetHTMLURL (),
312+ ID : j .GetID (),
313+ Name : j .GetName (),
314+ HtmlURL : j .GetHTMLURL (),
315+ Conclusion : j .GetConclusion (),
318316 })
319317 }
320318 return result
321319}
322320
323- func (g * githubActionsConfigProvider ) runIdInt64 () ( int64 , error ) {
321+ func (g * githubActionsConfigProvider ) runIdInt64 () int64 {
324322 strRunId := g .BuildID ()
325323 runId , err := strconv .ParseInt (strRunId , 10 , 64 )
326324 if err != nil {
327- return 0 , errors .Wrapf (err , "invalid GITHUB_RUN_ID value %s: %s" , strRunId , err )
325+ log .Entry ().Debugf ("invalid GITHUB_RUN_ID value %s: %s" , strRunId , err )
326+ return 0
328327 }
329328
330- return runId , nil
329+ return runId
331330}
332331
333332func getOwnerAndRepoNames () (string , string ) {
0 commit comments