From 705b3851c3702206561b4ccc1c6159d0a408a9fa Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Wed, 10 May 2023 08:16:06 -0700 Subject: [PATCH] fix: sort tasks in run summary output by task id (#4837) ### Description Was using `--summarize` to debug a run and got annoyed that tasks were getting reordered. ### Testing Instructions Inspect output of a summary json and verify that tasks no longer have a random order. --- cli/internal/runsummary/format_json.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cli/internal/runsummary/format_json.go b/cli/internal/runsummary/format_json.go index 1acf1edc2065a..e7530949c6aa7 100644 --- a/cli/internal/runsummary/format_json.go +++ b/cli/internal/runsummary/format_json.go @@ -2,6 +2,7 @@ package runsummary import ( "encoding/json" + "sort" "github.com/pkg/errors" "github.com/segmentio/ksuid" @@ -47,8 +48,16 @@ func (rsm *Meta) normalize() { task.cleanForSinglePackage() } } + + sort.Sort(byTaskID(rsm.RunSummary.Tasks)) } +type byTaskID []*TaskSummary + +func (a byTaskID) Len() int { return len(a) } +func (a byTaskID) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a byTaskID) Less(i, j int) bool { return a[i].TaskID < a[j].TaskID } + // nonMonorepoRunSummary is an exact copy of RunSummary, but the JSON tags are structured // for rendering a single-package run of turbo. Notably, we want to always omit packages // since there is no concept of packages in a single-workspace repo.