Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log the location of the summary file in the execution summary #4385

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cli/integration_tests/basic_monorepo/run_summary/discovery.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Setup
$ . ${TESTDIR}/../../setup.sh
$ . ${TESTDIR}/../setup.sh $(pwd)
$ rm -rf .turbo/runs

$ ${TURBO} run build --summarize=true --filter=my-app
\xe2\x80\xa2 Packages in scope: my-app (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
my-app:build: cache miss, executing 2f192ed93e20f940
my-app:build:
my-app:build: > build
my-app:build: > echo 'building'
my-app:build:
my-app:build: building

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Time:\s*[\.0-9]+m?s (re)
Summary: .+\.turbo\/runs\/[a-zA-Z0-9]+.json (re)

2 changes: 1 addition & 1 deletion cli/internal/run/real_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func RealRun(
}
}

runSummary.Close(exitCode, base.RepoRoot)
runSummary.Close(exitCode)

if exitCode != 0 {
return &process.ChildExit{
Expand Down
1 change: 1 addition & 0 deletions cli/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ func (r *run) run(ctx gocontext.Context, targets []string) error {
summary := runsummary.NewRunSummary(
startAt,
r.base.UI,
r.base.RepoRoot,
rs.Opts.runOpts.singlePackage,
rs.Opts.runOpts.profile,
r.base.TurboVersion,
Expand Down
33 changes: 28 additions & 5 deletions cli/internal/runsummary/format_execution_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,34 @@ func (rsm *Meta) printExecutionSummary() {
ui.Warn("No tasks were executed as part of this run.")
}

ui.Output("") // Clear the line
ui.Output("") // Clear the line
spacer := " " // 4 chars

var lines []string

// The only difference between these two branches is that when there is a run summary
// we print the path to that file and we adjust the whitespace in the printed text so it aligns.
// We could just always align to account for the summary line, but that would require a whole
// bunch of test output assertions to change.
if rsm.getPath().FileExists() {
lines = []string{
util.Sprintf("${BOLD} Tasks:${BOLD_GREEN}%s%v successful${RESET}${GRAY}, %v total${RESET}", spacer, successful, attempted),
util.Sprintf("${BOLD} Cached:%s%v cached${RESET}${GRAY}, %v total${RESET}", spacer, cached, attempted),
util.Sprintf("${BOLD} Time:%s%v${RESET} %v${RESET}", spacer, duration, maybeFullTurbo),
util.Sprintf("${BOLD}Summary:%s%s${RESET}", spacer, rsm.getPath()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this is an absolute path. I considered using a relative path, but it could be confusing if running from within a subdirectory of a monorepo (with global turbo), so this makes more sense

}
} else {
lines = []string{
util.Sprintf("${BOLD} Tasks:${BOLD_GREEN} %v successful${RESET}${GRAY}, %v total${RESET}", successful, attempted),
util.Sprintf("${BOLD}Cached: %v cached${RESET}${GRAY}, %v total${RESET}", cached, attempted),
util.Sprintf("${BOLD} Time: %v${RESET} %v${RESET}", duration, maybeFullTurbo),
}
}

// Print the real thing
for _, line := range lines {
ui.Output(line)
}

// The whitespaces in the string are to align the UI in a nice way.
ui.Output(util.Sprintf("${BOLD} Tasks:${BOLD_GREEN} %v successful${RESET}${GRAY}, %v total${RESET}", successful, attempted))
ui.Output(util.Sprintf("${BOLD}Cached: %v cached${RESET}${GRAY}, %v total${RESET}", cached, attempted))
ui.Output(util.Sprintf("${BOLD} Time: %v${RESET} %v${RESET}", duration, maybeFullTurbo))
ui.Output("")
}
31 changes: 22 additions & 9 deletions cli/internal/runsummary/run_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const tasksEndpoint = "/v0/spaces/%s/runs/%s/tasks"
type Meta struct {
RunSummary *RunSummary
ui cli.Ui
repoRoot turbopath.AbsoluteSystemPath // used to write run summary
singlePackage bool
shouldSave bool
apiClient *client.APIClient
Expand Down Expand Up @@ -59,6 +60,7 @@ type singlePackageRunSummary struct {
func NewRunSummary(
startAt time.Time,
terminal cli.Ui,
repoRoot turbopath.AbsoluteSystemPath,
singlePackage bool,
profile string,
turboVersion string,
Expand All @@ -81,15 +83,24 @@ func NewRunSummary(
GlobalHashSummary: globalHashSummary,
},
ui: terminal,
repoRoot: repoRoot,
singlePackage: singlePackage,
shouldSave: shouldSave,
apiClient: apiClient,
spaceID: spaceID,
}
}

// getPath returns a path to where the runSummary is written.
// The returned path will always be relative to the dir passsed in.
// We don't do a lot of validation, so `../../` paths are allowed.
func (rsm *Meta) getPath() turbopath.AbsoluteSystemPath {
filename := fmt.Sprintf("%s.json", rsm.RunSummary.ID)
return rsm.repoRoot.UntypedJoin(filepath.Join(".turbo", "runs"), filename)
}

// Close wraps up the RunSummary at the end of a `turbo run`.
func (rsm *Meta) Close(exitCode int, dir turbopath.AbsoluteSystemPath) {
func (rsm *Meta) Close(exitCode int) {
rsm.RunSummary.ExecutionSummary.exitCode = exitCode
rsm.RunSummary.ExecutionSummary.endedAt = time.Now()

Expand All @@ -102,19 +113,24 @@ func (rsm *Meta) Close(exitCode int, dir turbopath.AbsoluteSystemPath) {
// are all the same thng, we should use a strategy similar to cache save/upload to
// do this in parallel.

rsm.printExecutionSummary()

// Otherwise, attempt to save the summary
// Warn on the error, but we don't need to throw an error
if rsm.shouldSave {
if err := rsm.save(dir); err != nil {
if err := rsm.save(); err != nil {
rsm.ui.Warn(fmt.Sprintf("Error writing run summary: %v", err))
}
}

rsm.printExecutionSummary()

if rsm.shouldSave {
if rsm.spaceID != "" && rsm.apiClient.IsLinked() {
if err := rsm.record(); err != nil {
rsm.ui.Warn(fmt.Sprintf("Error recording Run to Vercel: %v", err))
}
}
}

}

// TrackTask makes it possible for the consumer to send information about the execution of a task.
Expand All @@ -123,18 +139,15 @@ func (summary *RunSummary) TrackTask(taskID string) (func(outcome executionEvent
}

// Save saves the run summary to a file
func (rsm *Meta) save(dir turbopath.AbsoluteSystemPath) error {
func (rsm *Meta) save() error {
json, err := rsm.FormatJSON()
if err != nil {
return err
}

// summaryPath will always be relative to the dir passsed in.
// We don't do a lot of validation, so `../../` paths are allowed
summaryPath := dir.UntypedJoin(
filepath.Join(".turbo", "runs"),
fmt.Sprintf("%s.json", rsm.RunSummary.ID),
)
summaryPath := rsm.getPath()

if err := summaryPath.EnsureDir(); err != nil {
return err
Expand Down