Skip to content

Commit

Permalink
fix: allow same recipe to be executed twice
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Jul 11, 2024
1 parent 2194bf4 commit 330e6d0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 56 deletions.
25 changes: 4 additions & 21 deletions internal/cli/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/futurice/jalapeno/pkg/ui/survey"
"github.com/gofrs/uuid"
"github.com/spf13/cobra"
"golang.org/x/mod/semver"
)

type executeOptions struct {
Expand All @@ -30,10 +29,6 @@ type executeOptions struct {
option.Timeout
}

var (
ErrAlreadyExecuted = errors.New("recipe has been already executed")
)

func NewExecuteCmd() *cobra.Command {
var opts executeOptions
var cmd = &cobra.Command{
Expand Down Expand Up @@ -149,14 +144,6 @@ func executeRecipe(cmd *cobra.Command, opts executeOptions, re *recipe.Recipe) e
return err
}

for _, sauce := range existingSauces {
if sauce.Recipe.Name == re.Name &&
semver.Compare(sauce.Recipe.Metadata.Version, re.Metadata.Version) == 0 &&
sauce.SubPath == opts.Subpath {
return fmt.Errorf("recipe '%s@%s': %w. If you want to re-execute the recipe with different values, use `upgrade` command with `--reuse-old-values=false` flag", re.Name, re.Metadata.Version, ErrAlreadyExecuted)
}
}

reusedValues := make(recipe.VariableValues)
if opts.ReuseOtherSauceValues && len(existingSauces) > 0 {
for _, sauce := range existingSauces {
Expand Down Expand Up @@ -237,7 +224,7 @@ func executeRecipe(cmd *cobra.Command, opts executeOptions, re *recipe.Recipe) e
for _, s := range existingSauces {
if conflicts := s.Conflicts(sauce); conflicts != nil {
retryMessage := cliutil.MakeRetryMessage(os.Args, values)
return fmt.Errorf("conflict in recipe '%s': file '%s' was already created by recipe '%s'.\n\n%s", re.Name, conflicts[0].Path, s.Recipe.Name, retryMessage)
return fmt.Errorf("conflict in recipe '%s': file '%s' was already created by other recipe '%s' (sauce ID: %s).\n\n%s", re.Name, conflicts[0].Path, s.Recipe.Name, s.ID, retryMessage)
}
}

Expand Down Expand Up @@ -313,18 +300,14 @@ func executeManifest(cmd *cobra.Command, opts executeOptions, manifest *recipe.M

opts.Values.Flags = valueFlags

err = executeRecipe(cmd, opts, re)
if err != nil {
if errors.Is(err, ErrAlreadyExecuted) {
cmd.Printf("Recipe '%s@%s' has already been executed, skipping...\n", re.Name, re.Version)
} else {
return err
}
if err := executeRecipe(cmd, opts, re); err != nil {
return err
}

if i < len(manifest.Recipes)-1 {
cmd.Print("\n- - - - - - - - - -\n\n")
}
}

return nil
}
4 changes: 0 additions & 4 deletions pkg/recipe/variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ func TestVariableValidation(t *testing.T) {

func TestVariableRegExpValidation(t *testing.T) {
variable := &Variable{
Name: "foo",
Description: "foo description",
Validators: []VariableValidator{
{
Pattern: "^[a-zA-Z0-9_.()-]{0,89}[a-zA-Z0-9_()-]$",
Expand Down Expand Up @@ -117,8 +115,6 @@ func TestVariableRegExpValidation(t *testing.T) {

func TestUniqueColumnValidation(t *testing.T) {
variable := &Variable{
Name: "foo",
Description: "foo description",
Validators: []VariableValidator{
{
Unique: true,
Expand Down
22 changes: 1 addition & 21 deletions test/features/execute-manifest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,4 @@ Feature: Execute manifests
| foo |
| conflicts-with-foo |
When I execute the manifest file
Then CLI produced an error "^Error: conflict in recipe 'conflicts-with-foo': file 'foo\.md' was already created by recipe 'foo'\."

Scenario: Already executed recipes are skipped when executing a manifest
Given a recipe "foo"
And recipe "foo" generates file "foo.md" with content "initial"
And a recipe "bar"
And recipe "bar" generates file "bar.md" with content "initial"
And a manifest file that includes recipes
| foo |
When I execute the manifest file
Then no errors were printed

Given I clear the output
And a manifest file that includes recipes
| foo |
| bar |
When I execute the manifest file
Then no errors were printed
And CLI produced an output "Recipe '[email protected]' has already been executed, skipping"
And the project directory should contain file "foo.md"
And the project directory should contain file "bar.md"
Then CLI produced an error "^Error: conflict in recipe 'conflicts-with-foo': file 'foo\.md' was already created by other recipe 'foo'"
11 changes: 1 addition & 10 deletions test/features/execute-recipes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,7 @@ Feature: Execute recipes
And no errors were printed
Then execution of the recipe has succeeded
When I execute recipe "quux"
Then CLI produced an error "file 'Taskfile.yml' was already created by recipe 'bar'"

Scenario: Same recipe is executed twice
Given a recipe "foo"
And recipe "foo" generates file "README.md" with content "initial"
When I execute recipe "foo"
And no errors were printed
Then execution of the recipe has succeeded
When I execute recipe "foo"
Then CLI produced an error "recipe 'foo@v0\.0\.1': recipe has been already executed"
Then CLI produced an error "file 'Taskfile.yml' was already created by other recipe 'bar'"

Scenario: Execute single recipe to a subpath
Given a recipe "foo"
Expand Down

0 comments on commit 330e6d0

Please sign in to comment.