aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/internal/runsummary/format_execution_summary.go
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
commitdd84b9d64fb98746a230cd24233ff50a562c39c9 (patch)
treeb583261ef00b3afe72ec4d6dacb31e57779a6faf /cli/internal/runsummary/format_execution_summary.go
parent0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff)
downloadHydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz
HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip
Diffstat (limited to 'cli/internal/runsummary/format_execution_summary.go')
-rw-r--r--cli/internal/runsummary/format_execution_summary.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/cli/internal/runsummary/format_execution_summary.go b/cli/internal/runsummary/format_execution_summary.go
new file mode 100644
index 0000000..37092be
--- /dev/null
+++ b/cli/internal/runsummary/format_execution_summary.go
@@ -0,0 +1,70 @@
+package runsummary
+
+import (
+ "os"
+ "time"
+
+ "github.com/fatih/color"
+ internalUI "github.com/vercel/turbo/cli/internal/ui"
+ "github.com/vercel/turbo/cli/internal/util"
+)
+
+func (rsm *Meta) printExecutionSummary() {
+ maybeFullTurbo := ""
+ summary := rsm.RunSummary
+ ui := rsm.ui
+
+ attempted := summary.ExecutionSummary.attempted
+ successful := summary.ExecutionSummary.cached + summary.ExecutionSummary.success
+ cached := summary.ExecutionSummary.cached
+ // TODO: can we use a method on ExecutionSummary here?
+ duration := time.Since(summary.ExecutionSummary.startedAt).Truncate(time.Millisecond)
+
+ if cached == attempted && attempted > 0 {
+ terminalProgram := os.Getenv("TERM_PROGRAM")
+ // On the macOS Terminal, the rainbow colors show up as a magenta background
+ // with a gray background on a single letter. Instead, we print in bold magenta
+ if terminalProgram == "Apple_Terminal" {
+ fallbackTurboColor := color.New(color.FgHiMagenta, color.Bold).SprintFunc()
+ maybeFullTurbo = fallbackTurboColor(">>> FULL TURBO")
+ } else {
+ maybeFullTurbo = internalUI.Rainbow(">>> FULL TURBO")
+ }
+ }
+
+ if attempted == 0 {
+ ui.Output("") // Clear the line
+ ui.Warn("No tasks were executed as part of this run.")
+ }
+
+ 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()),
+ }
+ } else {
+ 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),
+ }
+ }
+
+ // Print the real thing
+ for _, line := range lines {
+ ui.Output(line)
+ }
+
+ ui.Output("")
+}