Skip to content

Commit 268dab1

Browse files
authored
Merge pull request #210 from nicholasSUSE/bump-version-override
Feature: Version override to auto-chart-bumps
2 parents f5575af + 5da43d0 commit 268dab1

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func main() {
441441
`,
442442
Action: chartBump,
443443
Before: setupCache,
444-
Flags: []cli.Flag{packageFlag, branchFlag},
444+
Flags: []cli.Flag{packageFlag, branchFlag, chartVersionFlag},
445445
},
446446
}
447447

@@ -986,7 +986,7 @@ func chartBump(c *cli.Context) {
986986
}
987987

988988
logger.Log(ctx, slog.LevelInfo, "start auto-chart-bump")
989-
if err := bump.BumpChart(ctx); err != nil {
989+
if err := bump.BumpChart(ctx, ChartVersion); err != nil {
990990
logger.Fatal(ctx, fmt.Errorf("failed to bump: %w", err).Error())
991991
}
992992
}

pkg/auto/chart_bump.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func checkUpstreamOptions(options *options.UpstreamOptions) error {
218218

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

274274
// Calculate the next version to release
275-
if err := b.calculateNextVersion(ctx); err != nil {
275+
if err := b.calculateNextVersion(ctx, versionOverride); err != nil {
276276
return err
277277
}
278278

pkg/auto/chart_bump_versions.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,34 @@ func (v *version) updateTxt() {
3838
// if the chart had a patch bump, it will increment the patch version for the repoPrefixVersion
3939
// if the chart had a minor or major bump, it will increment the minor version for the repoPrefixVersion
4040
// the major repoPrefixVersion is only bumped when Rancher version is bumped.
41-
func (b *Bump) calculateNextVersion(ctx context.Context) error {
41+
func (b *Bump) calculateNextVersion(ctx context.Context, versionOverride string) error {
4242
logger.Log(ctx, slog.LevelInfo, "calculate next version")
4343

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

49-
// check and parse the versions before building the new version
50-
if err := b.applyVersionRules(); err != nil {
51-
return err
52-
}
49+
if versionOverride == "" {
50+
// check and parse the versions before building the new version
51+
if err := b.applyVersionRules(); err != nil {
52+
return err
53+
}
5354

54-
// build: toRelease full version
55-
targetVersion := b.versions.toReleaseRepoPrefix.txt + "+up" + b.versions.toRelease.txt
56-
targetSemver := semver.MustParse(targetVersion)
57-
b.releaseYaml.ChartVersion = targetVersion
58-
b.Pkg.AutoGeneratedBumpVersion = &targetSemver
55+
// build: toRelease full version
56+
targetVersion := b.versions.toReleaseRepoPrefix.txt + "+up" + b.versions.toRelease.txt
57+
targetSemver := semver.MustParse(targetVersion)
58+
b.releaseYaml.ChartVersion = targetVersion
59+
b.Pkg.AutoGeneratedBumpVersion = &targetSemver
60+
} else {
61+
semverOverride, err := semver.Make(versionOverride)
62+
if err != nil {
63+
logger.Log(ctx, slog.LevelError, "invalid version override", slog.String("version", versionOverride), logger.Err(err))
64+
return err
65+
}
66+
b.releaseYaml.ChartVersion = versionOverride
67+
b.Pkg.AutoGeneratedBumpVersion = &semverOverride
68+
}
5969

6070
logger.Log(ctx, slog.LevelDebug, "", slog.String("latestVersion", b.versions.latest.txt))
6171
logger.Log(ctx, slog.LevelDebug, "", slog.String("latestRepoVersion", b.versions.latestRepoPrefix.txt))

pkg/auto/chart_bump_versions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func Test_calculateNextVersion(t *testing.T) {
320320

321321
for _, tc := range tests {
322322
t.Run(tc.name, func(t *testing.T) {
323-
err := tc.input.b.calculateNextVersion(context.Background())
323+
err := tc.input.b.calculateNextVersion(context.Background(), "")
324324
assertError(t, err, tc.expected.err)
325325
if tc.expected.err == nil {
326326
assert.Equal(t, tc.expected.b.releaseYaml.ChartVersion, tc.input.b.releaseYaml.ChartVersion)

0 commit comments

Comments
 (0)