Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
13 changes: 6 additions & 7 deletions multimod/internal/common/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
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")
}
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
Loading