Skip to content

Commit 11928e2

Browse files
authored
Merge pull request #214 from nicholasSUSE/check-to-bump-version
check upstream app version
2 parents 4072f57 + f640e78 commit 11928e2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pkg/auto/chart_bump.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@ func (b *Bump) BumpChart(ctx context.Context, versionOverride string) error {
245245
return err
246246
}
247247

248+
// check if the version to bump does not already exists
249+
alreadyExist, err := checkBumpAppVersion(ctx, b.Pkg.UpstreamChartVersion, b.assetsVersionsMap[b.targetChart])
250+
if err != nil {
251+
return err
252+
}
253+
if alreadyExist {
254+
git.FullReset() // quitting the job regardless if this works or not
255+
return errors.New("version to bump already exists: " + *b.Pkg.UpstreamChartVersion)
256+
}
257+
248258
if err := git.AddAndCommit("make prepare"); err != nil {
249259
logger.Log(ctx, slog.LevelError, "error while adding and committing after make prepare", logger.Err(err))
250260
return err
@@ -507,3 +517,23 @@ func writeBumpJSON(targetCharts []string, bumpVersion string) error {
507517

508518
return nil
509519
}
520+
521+
// checkBumpAppVersion checks if the bumpAppVersion already exists in the repository
522+
func checkBumpAppVersion(ctx context.Context, bumpAppVersion *string, versions []lifecycle.Asset) (bool, error) {
523+
if bumpAppVersion == nil {
524+
logger.Log(ctx, slog.LevelError, "upstreamVersion is nil for chart, abnormal behavior")
525+
return false, errors.New("upstreamVersion is nil for chart, abnormal behavior")
526+
}
527+
528+
for _, version := range versions {
529+
parts := strings.Split(version.Version, "+up")
530+
if len(parts) != 2 {
531+
continue
532+
}
533+
if parts[1] == *bumpAppVersion {
534+
return true, nil
535+
}
536+
}
537+
538+
return false, nil
539+
}

0 commit comments

Comments
 (0)