From ed909bc27d74ea032831b35bc6e7e5616ad41cd1 Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Tue, 9 Jul 2024 10:29:59 +0200 Subject: [PATCH 1/3] [multimod] Resolve version for commit per module instead of per module set --- .chloggen/mx-psi_multimod-modref.yaml | 16 ++++++++++++++++ multimod/internal/common/tools.go | 13 ++++++------- multimod/internal/common/tools_test.go | 10 +++++----- multimod/internal/common/versions.go | 6 ++++++ multimod/internal/prerelease/prerelease.go | 7 ++++++- multimod/internal/sync/sync.go | 21 ++++++++++++--------- 6 files changed, 51 insertions(+), 22 deletions(-) create mode 100755 .chloggen/mx-psi_multimod-modref.yaml diff --git a/.chloggen/mx-psi_multimod-modref.yaml b/.chloggen/mx-psi_multimod-modref.yaml new file mode 100755 index 00000000..3eefc39e --- /dev/null +++ b/.chloggen/mx-psi_multimod-modref.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. crosslink) +component: multimod + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Get pseudoversion for each module in a module set separately to support moving modules between module sets. + +# One or more tracking issues related to the change +issues: [] + +# (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/multimod/internal/common/tools.go b/multimod/internal/common/tools.go index 14c78efc..02b6d21c 100644 --- a/multimod/internal/common/tools.go +++ b/multimod/internal/common/tools.go @@ -61,7 +61,7 @@ func GetModuleSet(modSetName, versioningFilename string) (ModuleSet, error) { // updateGoModVersions updates one go.mod file, given by modFilePath, by updating all modules listed in // newModPaths to use the newVersion given. -func updateGoModVersions(modFilePath ModuleFilePath, newModPaths []ModulePath, newVersion string) error { +func updateGoModVersions(modFilePath ModuleFilePath, newModRefs []ModuleRef) error { if !strings.HasSuffix(string(modFilePath), "go.mod") { return errors.New("cannot update file passed that does not end with go.mod") } @@ -71,8 +71,8 @@ func updateGoModVersions(modFilePath ModuleFilePath, newModPaths []ModulePath, n panic(err) } - for _, modPath := range newModPaths { - newGoModFile, err = replaceModVersion(modPath, newVersion, newGoModFile) + for _, modRef := range newModRefs { + newGoModFile, err = replaceModVersion(modRef.Path, modRef.Version, newGoModFile) if err != nil { return err } @@ -101,14 +101,13 @@ func replaceModVersion(modPath ModulePath, version string, newGoModFile []byte) } // UpdateGoModFiles updates the go.mod files in modFilePaths by updating all modules listed in -// newModPaths to use the newVersion given. -func UpdateGoModFiles(modFilePaths []ModuleFilePath, newModPaths []ModulePath, newVersion string) error { +// moduleRefs to use the versions given. +func UpdateGoModFiles(modFilePaths []ModuleFilePath, newModuleRefs []ModuleRef) error { log.Println("Updating all module versions in go.mod files...") for _, modFilePath := range modFilePaths { if err := updateGoModVersions( modFilePath, - newModPaths, - newVersion, + newModuleRefs, ); err != nil { return fmt.Errorf("could not update module versions in file %v: %w", modFilePath, err) } diff --git a/multimod/internal/common/tools_test.go b/multimod/internal/common/tools_test.go index caa02b64..48f892a8 100644 --- a/multimod/internal/common/tools_test.go +++ b/multimod/internal/common/tools_test.go @@ -124,13 +124,13 @@ func TestUpdateGoModVersions(t *testing.T) { ")"), } - newModPaths := []ModulePath{ - "go.opentelemetry.io/build-tools/multimod/internal/prerelease/test/test1", - "go.opentelemetry.io/build-tools/multimod/internal/prerelease/test/test2", - } newVersion := "v1.2.3-RC1+meta" + newModRefs := []ModuleRef{ + {Path: "go.opentelemetry.io/build-tools/multimod/internal/prerelease/test/test1", Version: newVersion}, + {Path: "go.opentelemetry.io/build-tools/multimod/internal/prerelease/test/test2", Version: newVersion}, + } - require.NoError(t, UpdateGoModFiles(modFilePaths, newModPaths, newVersion)) + require.NoError(t, UpdateGoModFiles(modFilePaths, newModRefs)) for modFilePath, expectedByteOutput := range expectedModFiles { actual, err := os.ReadFile(filepath.Clean(modFilePath)) require.NoError(t, err) diff --git a/multimod/internal/common/versions.go b/multimod/internal/common/versions.go index f7b0816a..04b2cd91 100644 --- a/multimod/internal/common/versions.go +++ b/multimod/internal/common/versions.go @@ -52,6 +52,12 @@ type ModuleSet struct { // ModulePath holds the module import path, such as "go.opentelemetry.io/otel". type ModulePath string +// ModuleRef holds a module import path and a version for that module. +type ModuleRef struct { + Path ModulePath + Version string +} + // ModuleInfoMap is a mapping from a module's import path to its ModuleInfo struct. type ModuleInfoMap map[ModulePath]ModuleInfo diff --git a/multimod/internal/prerelease/prerelease.go b/multimod/internal/prerelease/prerelease.go index c0bb3212..cbf75f64 100644 --- a/multimod/internal/prerelease/prerelease.go +++ b/multimod/internal/prerelease/prerelease.go @@ -194,7 +194,12 @@ func (p prerelease) updateAllGoModFiles() error { modFilePaths = append(modFilePaths, filePath) } - if err := common.UpdateGoModFiles(modFilePaths, p.ModuleSetRelease.ModSetPaths(), p.ModuleSetRelease.ModSetVersion()); err != nil { + var newModRefs []common.ModuleRef + ver := p.ModuleSetRelease.ModSetVersion() + for _, mod := range p.ModuleSetRelease.ModSetPaths() { + newModRefs = append(newModRefs, common.ModuleRef{Path: mod, Version: ver}) + } + if err := common.UpdateGoModFiles(modFilePaths, newModRefs); err != nil { return fmt.Errorf("could not update all go mod files: %w", err) } diff --git a/multimod/internal/sync/sync.go b/multimod/internal/sync/sync.go index 0cc16823..290b3640 100644 --- a/multimod/internal/sync/sync.go +++ b/multimod/internal/sync/sync.go @@ -146,20 +146,23 @@ func (s sync) updateAllGoModFiles() error { modFilePaths = append(modFilePaths, filePath) } - ver := s.OtherModuleSet.Version - if s.OtherModuleVersionCommit != "" { - version, err := s.parseVersionInfo(string(s.OtherModuleSet.Modules[0]), s.OtherModuleVersionCommit) - if err != nil { - return err + var newModRefs []common.ModuleRef + for _, mod := range s.OtherModuleSet.Modules { + ver := s.OtherModuleSet.Version + if s.OtherModuleVersionCommit != "" { + version, err := s.parseVersionInfo(string(mod), s.OtherModuleVersionCommit) + if err != nil { + return err + } + ver = version } - ver = version + log.Printf("Version for module %q: %s\n", mod, ver) + newModRefs = append(newModRefs, common.ModuleRef{Path: mod, Version: ver}) } - log.Printf("Version: %s\n", ver) if err := common.UpdateGoModFiles( modFilePaths, - s.OtherModuleSet.Modules, - ver, + newModRefs, ); err != nil { return fmt.Errorf("could not update all go mod files: %w", err) } From e27714dfddb14d1b08e11ee4e0262d1f954605b2 Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Tue, 9 Jul 2024 10:42:52 +0200 Subject: [PATCH 2/3] Add issue number to changelog --- .chloggen/mx-psi_multimod-modref.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/mx-psi_multimod-modref.yaml b/.chloggen/mx-psi_multimod-modref.yaml index 3eefc39e..876c3171 100755 --- a/.chloggen/mx-psi_multimod-modref.yaml +++ b/.chloggen/mx-psi_multimod-modref.yaml @@ -8,7 +8,7 @@ component: multimod note: Get pseudoversion for each module in a module set separately to support moving modules between module sets. # One or more tracking issues related to the change -issues: [] +issues: [582] # (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. From 60ca64dfb0a24c51fe36481c8717ef63e1d3bd25 Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Tue, 9 Jul 2024 12:34:41 +0200 Subject: [PATCH 3/3] Update comment --- multimod/internal/common/tools.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multimod/internal/common/tools.go b/multimod/internal/common/tools.go index 02b6d21c..a27e6253 100644 --- a/multimod/internal/common/tools.go +++ b/multimod/internal/common/tools.go @@ -60,7 +60,7 @@ func GetModuleSet(modSetName, versioningFilename string) (ModuleSet, error) { } // updateGoModVersions updates one go.mod file, given by modFilePath, by updating all modules listed in -// newModPaths to use the newVersion given. +// newModRefs to use the new versions given. func updateGoModVersions(modFilePath ModuleFilePath, newModRefs []ModuleRef) error { if !strings.HasSuffix(string(modFilePath), "go.mod") { return errors.New("cannot update file passed that does not end with go.mod")