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

Revert "wolfictl update: transform-version needs to run before versio… #415

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
5 changes: 0 additions & 5 deletions pkg/update/githubReleases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 0 additions & 8 deletions pkg/update/githubReleases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 0 additions & 8 deletions pkg/update/releaseMonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
41 changes: 26 additions & 15 deletions pkg/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"strings"
"time"

"chainguard.dev/melange/pkg/config"

wolfiversions "github.com/wolfi-dev/wolfictl/pkg/versions"

"github.com/fatih/color"
Expand Down Expand Up @@ -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
Expand Down