Skip to content

Commit

Permalink
fix: Don't try to download assets and logs if none are available (#889)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Co-authored-by: Alex Plischke <[email protected]>
  • Loading branch information
mhan83 and alexplischke authored Feb 16, 2024
1 parent 764e9e2 commit d2055d9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 28 deletions.
22 changes: 16 additions & 6 deletions internal/imagerunner/imagerunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
51 changes: 29 additions & 22 deletions internal/saucecloud/imagerunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d2055d9

Please sign in to comment.