Skip to content

Feature: Version override to auto-chart-bumps #210

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

Merged
merged 2 commits into from
Apr 9, 2025
Merged
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
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func main() {
`,
Action: chartBump,
Before: setupCache,
Flags: []cli.Flag{packageFlag, branchFlag},
Flags: []cli.Flag{packageFlag, branchFlag, chartVersionFlag},
},
}

Expand Down Expand Up @@ -986,7 +986,7 @@ func chartBump(c *cli.Context) {
}

logger.Log(ctx, slog.LevelInfo, "start auto-chart-bump")
if err := bump.BumpChart(ctx); err != nil {
if err := bump.BumpChart(ctx, ChartVersion); err != nil {
logger.Fatal(ctx, fmt.Errorf("failed to bump: %w", err).Error())
}
}
4 changes: 2 additions & 2 deletions pkg/auto/chart_bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func checkUpstreamOptions(options *options.UpstreamOptions) error {

// BumpChart will execute a similar approach as the defined development workflow for chartowners.
// The main difference is that between the steps: (make prepare and make patch) we will calculate the next version to release.
func (b *Bump) BumpChart(ctx context.Context) error {
func (b *Bump) BumpChart(ctx context.Context, versionOverride string) error {
// List the possible target charts
targetCharts, err := chartsTargets(b.targetChart)
if err != nil {
Expand Down Expand Up @@ -272,7 +272,7 @@ func (b *Bump) BumpChart(ctx context.Context) error {
}

// Calculate the next version to release
if err := b.calculateNextVersion(ctx); err != nil {
if err := b.calculateNextVersion(ctx, versionOverride); err != nil {
return err
}

Expand Down
30 changes: 20 additions & 10 deletions pkg/auto/chart_bump_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,34 @@ func (v *version) updateTxt() {
// if the chart had a patch bump, it will increment the patch version for the repoPrefixVersion
// if the chart had a minor or major bump, it will increment the minor version for the repoPrefixVersion
// the major repoPrefixVersion is only bumped when Rancher version is bumped.
func (b *Bump) calculateNextVersion(ctx context.Context) error {
func (b *Bump) calculateNextVersion(ctx context.Context, versionOverride string) error {
logger.Log(ctx, slog.LevelInfo, "calculate next version")

// load versions and parse the repository prefix versions from them
if err := b.loadVersions(); err != nil {
return err
}

// check and parse the versions before building the new version
if err := b.applyVersionRules(); err != nil {
return err
}
if versionOverride == "" {
// check and parse the versions before building the new version
if err := b.applyVersionRules(); err != nil {
return err
}

// build: toRelease full version
targetVersion := b.versions.toReleaseRepoPrefix.txt + "+up" + b.versions.toRelease.txt
targetSemver := semver.MustParse(targetVersion)
b.releaseYaml.ChartVersion = targetVersion
b.Pkg.AutoGeneratedBumpVersion = &targetSemver
// build: toRelease full version
targetVersion := b.versions.toReleaseRepoPrefix.txt + "+up" + b.versions.toRelease.txt
targetSemver := semver.MustParse(targetVersion)
b.releaseYaml.ChartVersion = targetVersion
b.Pkg.AutoGeneratedBumpVersion = &targetSemver
} else {
semverOverride, err := semver.Make(versionOverride)
if err != nil {
logger.Log(ctx, slog.LevelError, "invalid version override", slog.String("version", versionOverride), logger.Err(err))
return err
}
b.releaseYaml.ChartVersion = versionOverride
b.Pkg.AutoGeneratedBumpVersion = &semverOverride
}

logger.Log(ctx, slog.LevelDebug, "", slog.String("latestVersion", b.versions.latest.txt))
logger.Log(ctx, slog.LevelDebug, "", slog.String("latestRepoVersion", b.versions.latestRepoPrefix.txt))
Expand Down
2 changes: 1 addition & 1 deletion pkg/auto/chart_bump_versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func Test_calculateNextVersion(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
err := tc.input.b.calculateNextVersion(context.Background())
err := tc.input.b.calculateNextVersion(context.Background(), "")
assertError(t, err, tc.expected.err)
if tc.expected.err == nil {
assert.Equal(t, tc.expected.b.releaseYaml.ChartVersion, tc.input.b.releaseYaml.ChartVersion)
Expand Down
Loading