diff --git a/pkg/update/githubReleases.go b/pkg/update/githubReleases.go index e310ebc9c..f79a8fdb5 100644 --- a/pkg/update/githubReleases.go +++ b/pkg/update/githubReleases.go @@ -624,11 +624,6 @@ func (o GitHubReleaseOptions) prepareVersion(nameHash, v, id string) (string, er return "", nil } - v, err := transformVersion(c.Update, v) - if err != nil { - return "", errors.Wrapf(err, "failed to transform version %s", v) - } - return v, nil } diff --git a/pkg/update/githubReleases_test.go b/pkg/update/githubReleases_test.go index ef43871a2..6b009eaae 100644 --- a/pkg/update/githubReleases_test.go +++ b/pkg/update/githubReleases_test.go @@ -304,14 +304,6 @@ func TestGitHubReleaseOptions_prepareVersion(t *testing.T) { }, }, }, version: "v1.2.3", want: "v1.2.3", wantErr: assert.NoError}, - {name: "transform-version", melangeConfig: config.Configuration{ - Update: config.Update{ - VersionTransform: []config.VersionTransform{ - {Match: "_", Replace: "."}, - }, - GitHubMonitor: &config.GitHubMonitor{}, - }, - }, version: "1_2_3", want: "1.2.3", wantErr: assert.NoError}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/update/releaseMonitor.go b/pkg/update/releaseMonitor.go index 56fcdd072..b80a61ac1 100644 --- a/pkg/update/releaseMonitor.go +++ b/pkg/update/releaseMonitor.go @@ -115,14 +115,6 @@ func (m MonitorService) getLatestReleaseMonitorVersions(melangePackages map[stri latestVersion = strings.TrimSuffix(latestVersion, p.Config.Update.ReleaseMonitor.StripSuffix) } - latestVersion, err = transformVersion(p.Config.Update, latestVersion) - if err != nil { - errorMessages[p.Config.Package.Name] = fmt.Sprintf( - "failed to apply version transforms to %s for package %s. Error: %s", - latestVersion, p.Config.Package.Name, err, - ) - } - latestVersionSemver, err := version.NewVersion(latestVersion) if err != nil { errorMessages[p.Config.Package.Name] = fmt.Sprintf( diff --git a/pkg/update/update.go b/pkg/update/update.go index 29ec60fc9..1e6407b4a 100644 --- a/pkg/update/update.go +++ b/pkg/update/update.go @@ -13,8 +13,6 @@ import ( "strings" "time" - "chainguard.dev/melange/pkg/config" - wolfiversions "github.com/wolfi-dev/wolfictl/pkg/versions" "github.com/fatih/color" @@ -256,27 +254,40 @@ func (o *Options) GetLatestVersions(dir string, packageNames []string) (map[stri maps.Copy(latestVersions, v) } - return latestVersions, nil + return o.mutatePackageVersions(latestVersions) } -// if provided, transform the version using the update config -func transformVersion(c config.Update, v string) (string, error) { - if len(c.VersionTransform) == 0 { - return v, nil - } +// Apply any post-process version-transforms to the detected update versions. +func (o *Options) mutatePackageVersions(packageVersions map[string]NewVersionResults) (map[string]NewVersionResults, error) { + mutatedPackageVersions := map[string]NewVersionResults{} - mutatedVersion := v + for k, nv := range packageVersions { + pc, ok := o.PackageConfigs[k] + if !ok { + return map[string]NewVersionResults{}, fmt.Errorf("package %s not found in PackageConfigs", k) + } - for _, tf := range c.VersionTransform { - matcher, err := regexp.Compile(tf.Match) - if err != nil { - return v, fmt.Errorf("unable to compile version transform regex: %w", err) + if len(pc.Config.Update.VersionTransform) == 0 { + mutatedPackageVersions[k] = nv + continue + } + + scratchVersion := nv.Version + + for _, tf := range pc.Config.Update.VersionTransform { + matcher, err := regexp.Compile(tf.Match) + if err != nil { + return map[string]NewVersionResults{}, fmt.Errorf("unable to compile version transform regex: %w", err) + } + + scratchVersion = matcher.ReplaceAllString(scratchVersion, tf.Replace) } - mutatedVersion = matcher.ReplaceAllString(mutatedVersion, tf.Replace) + nv.Version = scratchVersion + mutatedPackageVersions[k] = nv } - return mutatedVersion, nil + return mutatedPackageVersions, nil } // function will iterate over all packages that need to be updated and create a pull request for each change by default unless batch mode which creates a single pull request