Skip to content

Commit 579fb14

Browse files
authored
Include logs when posting task summary (vercel#4642)
1 parent 972e5f1 commit 579fb14

File tree

5 files changed

+40
-30
lines changed

5 files changed

+40
-30
lines changed

cli/internal/run/dry_run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func DryRun(
8686

8787
// The exitCode isn't really used by the Run Summary Close() method for dry runs
8888
// but we pass in a successful value to match Real Runs.
89-
return summary.Close(0, g.WorkspaceInfos)
89+
return summary.Close(ctx, 0, g.WorkspaceInfos)
9090
}
9191

9292
func populateCacheState(turboCache cache.Cache, taskSummaries []*runsummary.TaskSummary) {

cli/internal/run/real_run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func RealRun(
172172
}
173173
}
174174

175-
if err := runSummary.Close(exitCode, g.WorkspaceInfos); err != nil {
175+
if err := runSummary.Close(ctx, exitCode, g.WorkspaceInfos); err != nil {
176176
// We don't need to throw an error, but we can warn on this.
177177
// Note: this method doesn't actually return an error for Real Runs at the time of writing.
178178
base.UI.Info(fmt.Sprintf("Failed to close Run Summary %v", err))

cli/internal/runsummary/run_summary.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package runsummary
33

44
import (
5+
"context"
56
"encoding/json"
67
"fmt"
78
"path/filepath"
@@ -11,6 +12,7 @@ import (
1112
"github.com/mitchellh/cli"
1213
"github.com/segmentio/ksuid"
1314
"github.com/vercel/turbo/cli/internal/client"
15+
"github.com/vercel/turbo/cli/internal/spinner"
1416
"github.com/vercel/turbo/cli/internal/turbopath"
1517
"github.com/vercel/turbo/cli/internal/util"
1618
"github.com/vercel/turbo/cli/internal/workspace"
@@ -124,7 +126,7 @@ func (rsm *Meta) getPath() turbopath.AbsoluteSystemPath {
124126
}
125127

126128
// Close wraps up the RunSummary at the end of a `turbo run`.
127-
func (rsm *Meta) Close(exitCode int, workspaceInfos workspace.Catalog) error {
129+
func (rsm *Meta) Close(ctx context.Context, exitCode int, workspaceInfos workspace.Catalog) error {
128130
if rsm.runType == runTypeDryJSON || rsm.runType == runTypeDryText {
129131
return rsm.closeDryRun(workspaceInfos)
130132
}
@@ -161,8 +163,19 @@ func (rsm *Meta) Close(exitCode int, workspaceInfos workspace.Catalog) error {
161163
return nil
162164
}
163165

164-
url, errs := rsm.record()
166+
// Wrap the record function so we can hoist out url/errors but keep
167+
// the function signature/type the spinner.WaitFor expects.
168+
var url string
169+
var errs []error
170+
record := func() {
171+
url, errs = rsm.record()
172+
}
173+
174+
func() {
175+
_ = spinner.WaitFor(ctx, record, rsm.ui, "...sending run summary...", 1000*time.Millisecond)
176+
}()
165177

178+
// After the spinner is done
166179
if len(errs) > 0 {
167180
rsm.ui.Warn("Errors recording run to Spaces")
168181
for _, err := range errs {
@@ -234,7 +247,7 @@ func (rsm *Meta) record() (string, []error) {
234247
payload := rsm.newSpacesRunCreatePayload()
235248
if startPayload, err := json.Marshal(payload); err == nil {
236249
if resp, err := rsm.apiClient.JSONPost(createRunEndpoint, startPayload); err != nil {
237-
errs = append(errs, err)
250+
errs = append(errs, fmt.Errorf("POST %s: %w", createRunEndpoint, err))
238251
} else {
239252
if err := json.Unmarshal(resp, response); err != nil {
240253
errs = append(errs, fmt.Errorf("Error unmarshaling response: %w", err))
@@ -250,7 +263,7 @@ func (rsm *Meta) record() (string, []error) {
250263
if donePayload, err := json.Marshal(newSpacesDonePayload(rsm.RunSummary)); err == nil {
251264
patchURL := fmt.Sprintf(runsPatchEndpoint, rsm.spaceID, response.ID)
252265
if _, err := rsm.apiClient.JSONPatch(patchURL, donePayload); err != nil {
253-
errs = append(errs, fmt.Errorf("Error marking run as done: %w", err))
266+
errs = append(errs, fmt.Errorf("PATCH %s: %w", patchURL, err))
254267
}
255268
}
256269
}

cli/internal/runsummary/spaces.go

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,14 @@ type spacesRunResponse struct {
1111
}
1212

1313
type spacesRunPayload struct {
14-
// StartTime is when this run was started
15-
StartTime int64 `json:"startTime,omitempty"`
16-
17-
// EndTime is when this run ended. We will never be submitting start and endtime at the same time.
18-
EndTime int64 `json:"endTime,omitempty"`
19-
20-
// Status is
21-
Status string `json:"status,omitempty"`
22-
23-
// Type should be hardcoded to TURBO
24-
Type string `json:"type,omitempty"`
25-
26-
// ExitCode is the exit code for the full run
27-
ExitCode int `json:"exitCode,omitempty"`
28-
29-
// The command that kicked off the turbo run
30-
Command string `json:"command,omitempty"`
31-
32-
// RepositoryPath is the relative directory from the turborepo root to where
33-
// the command was invoked.
34-
RepositoryPath string `json:"repositoryPath,omitempty"`
35-
36-
// Context is the host on which this Run was executed (e.g. Github Action, Vercel, etc)
37-
Context string `json:"context,omitempty"`
14+
StartTime int64 `json:"startTime,omitempty"` // when the run was started
15+
EndTime int64 `json:"endTime,omitempty"` // when the run ended. we should never submit start and end at the same time.
16+
Status string `json:"status,omitempty"` // Status is "running" or "completed"
17+
Type string `json:"type,omitempty"` // hardcoded to "TURBO"
18+
ExitCode int `json:"exitCode,omitempty"` // exit code for the full run
19+
Command string `json:"command,omitempty"` // the thing that kicked off the turbo run
20+
RepositoryPath string `json:"repositoryPath,omitempty"` // where the command was invoked from
21+
Context string `json:"context,omitempty"` // the host on which this Run was executed (e.g. Github Action, Vercel, etc)
3822

3923
// TODO: we need to add these in
4024
// originationUser string
@@ -64,6 +48,7 @@ type spacesTask struct {
6448
ExitCode int `json:"exitCode,omitempty"`
6549
Dependencies []string `json:"dependencies,omitempty"`
6650
Dependents []string `json:"dependents,omitempty"`
51+
Logs string `json:"log"`
6752
}
6853

6954
func (rsm *Meta) newSpacesRunCreatePayload() *spacesRunPayload {
@@ -106,5 +91,6 @@ func newSpacesTaskPayload(taskSummary *TaskSummary) *spacesTask {
10691
ExitCode: *taskSummary.Execution.exitCode,
10792
Dependencies: taskSummary.Dependencies,
10893
Dependents: taskSummary.Dependents,
94+
Logs: string(taskSummary.GetLogs()),
10995
}
11096
}

cli/internal/runsummary/task_summary.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package runsummary
22

33
import (
4+
"os"
5+
46
"github.com/vercel/turbo/cli/internal/cache"
57
"github.com/vercel/turbo/cli/internal/fs"
68
"github.com/vercel/turbo/cli/internal/turbopath"
@@ -76,6 +78,15 @@ type TaskSummary struct {
7678
Execution *TaskExecutionSummary `json:"execution,omitempty"` // omit when it's not set
7779
}
7880

81+
// GetLogs reads the Logfile and returns the data
82+
func (ts *TaskSummary) GetLogs() []byte {
83+
bytes, err := os.ReadFile(ts.LogFile)
84+
if err != nil {
85+
return []byte{}
86+
}
87+
return bytes
88+
}
89+
7990
// TaskEnvVarSummary contains the environment variables that impacted a task's hash
8091
type TaskEnvVarSummary struct {
8192
Configured []string `json:"configured"`

0 commit comments

Comments
 (0)