Skip to content
Open
Changes from all 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
15 changes: 14 additions & 1 deletion cmd/internal/module_bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,22 @@ func (m *ModuleBump) apply(ctx context.Context, targetModule string, dryRun bool
return false, fmt.Errorf("failed to read %s: %w", gomod, err)
}
oldContent := string(b)
if !m.regex.MatchString(oldContent) {
// Extract current version from the go.mod line and compare with the computed new version.
matches := m.regex.FindStringSubmatch(oldContent)
if len(matches) == 0 {
return false, nil
}
if len(matches) > 1 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can len(matches) == 1?

if currentVer, err := semver.NewVersion(matches[1]); err == nil {
if newVer, err := semver.NewVersion(m.newVersion); err == nil {
if currentVer.GreaterThan(newVer) {
// Use the higher version already present (e.g., a manual major bump).
m.newVersion = currentVer.String()
}
}
}
}

bumpString := fmt.Sprintf("github.com/fluxcd/pkg/%s v%s", m.module, m.newVersion)
newContent := m.regex.ReplaceAllString(oldContent, bumpString)
if oldContent == newContent {
Expand Down
Loading