Skip to content

Commit

Permalink
[multimod] Resolve version for commit per module instead of per modul…
Browse files Browse the repository at this point in the history
…e set (#582)

* [multimod] Resolve version for commit per module instead of per module set

* Add issue number to changelog

* Update comment
  • Loading branch information
mx-psi authored Jul 9, 2024
1 parent 78f03ee commit af03a26
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 23 deletions.
16 changes: 16 additions & 0 deletions .chloggen/mx-psi_multimod-modref.yaml
Original file line number Diff line number Diff line change
@@ -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: [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.
# Use pipe (|) for multiline entries.
subtext:
15 changes: 7 additions & 8 deletions multimod/internal/common/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ 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 {
// 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")
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions multimod/internal/common/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions multimod/internal/common/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion multimod/internal/prerelease/prerelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
21 changes: 12 additions & 9 deletions multimod/internal/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit af03a26

Please sign in to comment.