From c77c83eaeb2900b76bc7979bd79439ce7c40c8a5 Mon Sep 17 00:00:00 2001 From: Jade Guiton Date: Wed, 15 Jan 2025 11:21:52 +0100 Subject: [PATCH] Add `--skip` flag to `crosslink tidylist` (#662) --- .chloggen/crosslink-tidy-v2.yaml | 16 ++++++++++++++++ crosslink/cmd/root.go | 2 ++ .../mock_test_data/testTidyListOrder/gomod | 3 +++ .../mock_test_data/testTidyListOrder/testA/gomod | 5 +++++ .../mock_test_data/testTidyListOrder/testB/gomod | 3 +++ .../mock_test_data/testTidyListOrder/testC/gomod | 3 +++ crosslink/internal/tidylist_test.go | 16 ++++++++++++++++ 7 files changed, 48 insertions(+) create mode 100644 .chloggen/crosslink-tidy-v2.yaml create mode 100644 crosslink/internal/mock_test_data/testTidyListOrder/gomod create mode 100644 crosslink/internal/mock_test_data/testTidyListOrder/testA/gomod create mode 100644 crosslink/internal/mock_test_data/testTidyListOrder/testB/gomod create mode 100644 crosslink/internal/mock_test_data/testTidyListOrder/testC/gomod diff --git a/.chloggen/crosslink-tidy-v2.yaml b/.chloggen/crosslink-tidy-v2.yaml new file mode 100644 index 00000000..081a686d --- /dev/null +++ b/.chloggen/crosslink-tidy-v2.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'enhancement' + +# The name of the component, or a single word describing the area of concern, (e.g. crosslink) +component: crosslink + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Added `--skip` flag to `crosslink tidylist` subcommand + +# One or more tracking issues related to the change +issues: [662] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/crosslink/cmd/root.go b/crosslink/cmd/root.go index 4f67251c..b150e6cf 100644 --- a/crosslink/cmd/root.go +++ b/crosslink/cmd/root.go @@ -166,6 +166,8 @@ func init() { comCfg.workCommand.Flags().StringVar(&comCfg.runConfig.GoVersion, "go", "1.22", "Go version applied when new go.work file is created") comCfg.tidyListCommand.Flags().StringVar(&comCfg.runConfig.AllowCircular, "allow-circular", "", "path to list of go modules that are allowed to have circular dependencies") comCfg.tidyListCommand.Flags().BoolVar(&comCfg.runConfig.Validate, "validate", false, "enables brute force validation of the tidy schedule") + comCfg.tidyListCommand.Flags().StringSliceVar(&comCfg.skipFlags, "skip", []string{}, "list of comma separated go.mod files that will be ignored by crosslink. "+ + "multiple calls of --skip can be made") } // transform array slice into map diff --git a/crosslink/internal/mock_test_data/testTidyListOrder/gomod b/crosslink/internal/mock_test_data/testTidyListOrder/gomod new file mode 100644 index 00000000..3b5442d6 --- /dev/null +++ b/crosslink/internal/mock_test_data/testTidyListOrder/gomod @@ -0,0 +1,3 @@ +module go.opentelemetry.io/build-tools/crosslink/testroot + +go 1.20 diff --git a/crosslink/internal/mock_test_data/testTidyListOrder/testA/gomod b/crosslink/internal/mock_test_data/testTidyListOrder/testA/gomod new file mode 100644 index 00000000..c7e77532 --- /dev/null +++ b/crosslink/internal/mock_test_data/testTidyListOrder/testA/gomod @@ -0,0 +1,5 @@ +module go.opentelemetry.io/build-tools/crosslink/testroot/testA + +go 1.20 + +require go.opentelemetry.io/build-tools/crosslink/testroot/testC v1.0.0 diff --git a/crosslink/internal/mock_test_data/testTidyListOrder/testB/gomod b/crosslink/internal/mock_test_data/testTidyListOrder/testB/gomod new file mode 100644 index 00000000..113775e6 --- /dev/null +++ b/crosslink/internal/mock_test_data/testTidyListOrder/testB/gomod @@ -0,0 +1,3 @@ +module go.opentelemetry.io/build-tools/crosslink/testroot/testB + +go 1.20 diff --git a/crosslink/internal/mock_test_data/testTidyListOrder/testC/gomod b/crosslink/internal/mock_test_data/testTidyListOrder/testC/gomod new file mode 100644 index 00000000..93ca41cd --- /dev/null +++ b/crosslink/internal/mock_test_data/testTidyListOrder/testC/gomod @@ -0,0 +1,3 @@ +module go.opentelemetry.io/build-tools/crosslink/testroot/testC + +go 1.20 diff --git a/crosslink/internal/tidylist_test.go b/crosslink/internal/tidylist_test.go index 8fe20128..bedcaf7f 100644 --- a/crosslink/internal/tidylist_test.go +++ b/crosslink/internal/tidylist_test.go @@ -65,6 +65,22 @@ func TestTidy(t *testing.T) { }, expSched: []string{".", "testC", "testB", "testA", "testB"}, }, + { // A -> C, B should give CAB (default to alphabetical order when no contraint) + name: "testTidyListOrder", + mock: "testTidyListOrder", + config: func(*RunConfig) {}, + expSched: []string{".", "testC", "testA", "testB"}, + }, + { // A -> C, B with A skipped should give BC (prune the graph, not just filter the output) + name: "testTidyListSkip", + mock: "testTidyListOrder", + config: func(config *RunConfig) { + config.SkippedPaths = map[string]struct{}{ + "testA/go.mod": {}, + } + }, + expSched: []string{".", "testB", "testC"}, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) {