From d2055d9fb0d773c0f796a48bd42ed413f44b70bf Mon Sep 17 00:00:00 2001 From: Mike Han <56001373+mhan83@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:57:14 -0700 Subject: [PATCH] fix: Don't try to download assets and logs if none are available (#889) * define assets field in the Runner struct * just make status a string * Pass the asset status to the results * Don't download logs and such if none were ever uploaded * Update internal/saucecloud/imagerunner.go Co-authored-by: Alex Plischke --------- Co-authored-by: Alex Plischke --- internal/imagerunner/imagerunner.go | 22 +++++++++---- internal/saucecloud/imagerunner.go | 51 ++++++++++++++++------------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/internal/imagerunner/imagerunner.go b/internal/imagerunner/imagerunner.go index ef9b45e1a..80b9b5dcd 100644 --- a/internal/imagerunner/imagerunner.go +++ b/internal/imagerunner/imagerunner.go @@ -79,13 +79,23 @@ type FileData struct { Data string `json:"data,omitempty"` } +const ( + RunnerAssetStateWaiting = "Waiting" + RunnerAssetStateErrored = "Errored" +) + +type RunnerAssets struct { + Status string `json:"status,omitempty"` +} + type Runner struct { - ID string `json:"id,omitempty"` - Status string `json:"status,omitempty"` - Image string `json:"image,omitempty"` - CreationTime int64 `json:"creation_time,omitempty"` - TerminationTime int64 `json:"termination_time,omitempty"` - TerminationReason string `json:"termination_reason,omitempty"` + ID string `json:"id,omitempty"` + Status string `json:"status,omitempty"` + Image string `json:"image,omitempty"` + CreationTime int64 `json:"creation_time,omitempty"` + TerminationTime int64 `json:"termination_time,omitempty"` + TerminationReason string `json:"termination_reason,omitempty"` + Assets RunnerAssets `json:"assets,omitempty"` } type ArtifactList struct { diff --git a/internal/saucecloud/imagerunner.go b/internal/saucecloud/imagerunner.go index e7bb0fd59..616560eec 100644 --- a/internal/saucecloud/imagerunner.go +++ b/internal/saucecloud/imagerunner.go @@ -72,14 +72,15 @@ func NewImgRunner(project imagerunner.Project, runnerService ImageRunner, tunnel } type execResult struct { - name string - runID string - status string - err error - duration time.Duration - startTime time.Time - endTime time.Time - attempts []report.Attempt + name string + runID string + status string + assetsStatus string + err error + duration time.Duration + startTime time.Time + endTime time.Time + attempts []report.Attempt } func (r *ImgRunner) RunProject() (int, error) { @@ -169,13 +170,14 @@ func (r *ImgRunner) runSuites(suites chan imagerunner.Suite, results chan<- exec duration := time.Since(startTime) results <- execResult{ - name: suite.Name, - runID: run.ID, - status: run.Status, - err: err, - startTime: startTime, - endTime: endTime, - duration: duration, + name: suite.Name, + runID: run.ID, + status: run.Status, + assetsStatus: run.Assets.Status, + err: err, + startTime: startTime, + endTime: endTime, + duration: duration, attempts: []report.Attempt{{ ID: run.ID, Duration: duration, @@ -364,14 +366,19 @@ func (r *ImgRunner) collectResults(results chan execResult, expected int) bool { } r.PrintResult(res) - if !r.Project.LiveLogs { - // only print logs if live logs are disabled - r.PrintLogs(res.runID, res.name) - } - files := r.DownloadArtifacts(res.runID, res.name, res.status, res.err != nil) + var artifacts []report.Artifact - for _, f := range files { - artifacts = append(artifacts, report.Artifact{FilePath: f}) + if res.assetsStatus == imagerunner.RunnerAssetStateErrored { + log.Warn().Msg("Logs and artifacts are not available due to an error.") + } else { + if !r.Project.LiveLogs { + // only print logs if live logs are disabled + r.PrintLogs(res.runID, res.name) + } + files := r.DownloadArtifacts(res.runID, res.name, res.status, res.err != nil) + for _, f := range files { + artifacts = append(artifacts, report.Artifact{FilePath: f}) + } } for _, r := range r.Reporters {