@@ -245,6 +245,16 @@ func (b *Bump) BumpChart(ctx context.Context, versionOverride string) error {
245
245
return err
246
246
}
247
247
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
+
248
258
if err := git .AddAndCommit ("make prepare" ); err != nil {
249
259
logger .Log (ctx , slog .LevelError , "error while adding and committing after make prepare" , logger .Err (err ))
250
260
return err
@@ -507,3 +517,23 @@ func writeBumpJSON(targetCharts []string, bumpVersion string) error {
507
517
508
518
return nil
509
519
}
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