Skip to content

Commit

Permalink
feat: allow forcing upgrade
Browse files Browse the repository at this point in the history
Release-As: 1.10.2
  • Loading branch information
majori committed Jun 13, 2024
1 parent 8388919 commit 1492cb1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions internal/cli/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type checkOptions struct {
RecipeName string
UseDetailedExitCode bool
Upgrade bool
ForceUpgrade bool

option.Common
option.OCIRepository
Expand Down Expand Up @@ -63,6 +64,7 @@ jalapeno check --recipe my-recipe --from oci://my-registry.com/my-recipe`,
cmd.Flags().StringVarP(&opts.RecipeName, "recipe", "r", "", "Name of the recipe to check for new versions")
cmd.Flags().StringVar(&opts.CheckFrom, "from", "", "Add or override the URL used for checking updates for the recipe. Works only with --recipe flag")
cmd.Flags().BoolVar(&opts.Upgrade, "upgrade", false, "Upgrade recipes to the latest version if new versions are found")
cmd.Flags().BoolVar(&opts.ForceUpgrade, "force-upgrade", false, "If upgrading, overwrite manual changes in the files with the new versions without prompting")
cmd.Flags().BoolVar(
&opts.UseDetailedExitCode,
"detailed-exitcode",
Expand Down Expand Up @@ -175,6 +177,7 @@ func runCheck(cmd *cobra.Command, opts checkOptions) error {
RecipeURL: fmt.Sprintf("%s:%s", sauce.CheckFrom, latestSauceVersions[sauce]),
TargetSauceID: sauce.ID.String(),
ReuseOldValues: true,
Force: opts.ForceUpgrade,
Common: opts.Common,
OCIRepository: opts.OCIRepository,
WorkingDirectory: opts.WorkingDirectory,
Expand Down
9 changes: 8 additions & 1 deletion internal/cli/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type upgradeOptions struct {
RecipeURL string
ReuseOldValues bool
TargetSauceID string
Force bool

option.Common
option.OCIRepository
Expand Down Expand Up @@ -71,6 +72,7 @@ jalapeno upgrade path/to/recipe --set NEW_VAR=foo`,

cmd.Flags().StringVar(&opts.TargetSauceID, "sauce-id", "", "If the project contains multiple sauces with the same recipe, specify the ID of the sauce to be upgraded")
cmd.Flags().BoolVar(&opts.ReuseOldValues, "reuse-old-values", true, "Automatically set values for variables which already have a value in the existing sauce")
cmd.Flags().BoolVarP(&opts.Force, "force", "f", false, "Overwrite manual changes in the files with the new versions without prompting")

if err := option.ApplyFlags(&opts, cmd.Flags()); err != nil {
return nil
Expand Down Expand Up @@ -308,7 +310,7 @@ func runUpgrade(cmd *cobra.Command, opts upgradeOptions) error {
// Check if the file from previous recipe version has been modified manually
prevFile, exists := oldSauce.Files[path]
if exists {
if !prevFile.HasBeenModifiedByUser() {
if !prevFile.HasBeenModifiedByUser() || opts.Force {
if prevFile.Checksum == newSauce.Files[path].Checksum {
fileStatuses[path] = recipeutil.FileUnchanged
} else {
Expand All @@ -327,6 +329,11 @@ func runUpgrade(cmd *cobra.Command, opts upgradeOptions) error {
return err
}

if opts.Force {
fileStatuses[path] = recipeutil.FileModified
continue
}

prevFile = recipe.NewFile(existingFileContent)
}

Expand Down

0 comments on commit 1492cb1

Please sign in to comment.