From 7e60c80eb7dc5fdb31fcf6d5da125c1c426d79bd Mon Sep 17 00:00:00 2001 From: iam-karan-suresh Date: Sun, 24 May 2026 08:56:37 +0530 Subject: [PATCH] fix(tools): respect manual major version bumps in go.mod Signed-off-by: iam-karan-suresh --- cmd/internal/module_bump.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/internal/module_bump.go b/cmd/internal/module_bump.go index c9a11b3e5..c83d8b59b 100644 --- a/cmd/internal/module_bump.go +++ b/cmd/internal/module_bump.go @@ -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 { + 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 {