From b55398b7ad5e241009acad849088eb12b1bbfb45 Mon Sep 17 00:00:00 2001 From: Bryce Lampe Date: Thu, 19 Dec 2024 10:26:05 -0800 Subject: [PATCH] Handle workspaces --- provider-ci/internal/pkg/migrations/consolidate_modules.go | 5 +++++ provider-ci/internal/pkg/migrations/migrations_test.go | 2 +- .../pkg/migrations/testdata/modules/vMajor/GIVEN/go.work | 7 +++++++ .../pkg/migrations/testdata/modules/vMajor/WANT/go.work | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 provider-ci/internal/pkg/migrations/testdata/modules/vMajor/GIVEN/go.work create mode 100644 provider-ci/internal/pkg/migrations/testdata/modules/vMajor/WANT/go.work diff --git a/provider-ci/internal/pkg/migrations/consolidate_modules.go b/provider-ci/internal/pkg/migrations/consolidate_modules.go index 8f0497a9ef..494d56e94c 100644 --- a/provider-ci/internal/pkg/migrations/consolidate_modules.go +++ b/provider-ci/internal/pkg/migrations/consolidate_modules.go @@ -51,6 +51,9 @@ func (consolidateModules) Migrate(_, outDir string) error { if _, err := run("git", "mv", "-f", "provider/go.sum", "go.sum"); err != nil { return fmt.Errorf("moving provider/go.sum: %w", err) } + // Update our workspace, if it exists. It's OK if these fail. + _, _ = run("go", "work", "edit", "-dropuse=./provider") + _, _ = run("go", "work", "edit", "-use=./") // Load the module as JSON. out, err := run("go", "mod", "edit", "-json", "go.mod") @@ -91,6 +94,8 @@ func (consolidateModules) Migrate(_, outDir string) error { _, _ = run("git", "rm", "examples/go.sum") _, _ = run("git", "rm", "tests/go.mod") _, _ = run("git", "rm", "tests/go.sum") + _, _ = run("go", "work", "edit", "-dropuse=./examples") + _, _ = run("go", "work", "edit", "-dropuse=./tests") // Rewrite our module path and determine our new import, if it's changed. // diff --git a/provider-ci/internal/pkg/migrations/migrations_test.go b/provider-ci/internal/pkg/migrations/migrations_test.go index 5ff097f0f1..527d135b5d 100644 --- a/provider-ci/internal/pkg/migrations/migrations_test.go +++ b/provider-ci/internal/pkg/migrations/migrations_test.go @@ -63,7 +63,7 @@ func assertDirectoryContains(t *testing.T, dir1, dir2 string) { } stat, err := os.Stat(filepath.Join(dir1, entry.Name())) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, entry.IsDir(), stat.IsDir()) subPath1 := filepath.Join(dir1, entry.Name()) diff --git a/provider-ci/internal/pkg/migrations/testdata/modules/vMajor/GIVEN/go.work b/provider-ci/internal/pkg/migrations/testdata/modules/vMajor/GIVEN/go.work new file mode 100644 index 0000000000..b373142538 --- /dev/null +++ b/provider-ci/internal/pkg/migrations/testdata/modules/vMajor/GIVEN/go.work @@ -0,0 +1,7 @@ +go 1.23.3 + +use ( + ./examples + ./provider + ./tests +) diff --git a/provider-ci/internal/pkg/migrations/testdata/modules/vMajor/WANT/go.work b/provider-ci/internal/pkg/migrations/testdata/modules/vMajor/WANT/go.work new file mode 100644 index 0000000000..8ac335f30f --- /dev/null +++ b/provider-ci/internal/pkg/migrations/testdata/modules/vMajor/WANT/go.work @@ -0,0 +1,3 @@ +go 1.23.3 + +use ./