diff --git a/README.md b/README.md index 60f60b3..3945320 100644 --- a/README.md +++ b/README.md @@ -360,9 +360,13 @@ actions: # By convention, the "uninstall" action is in charge of removing the project from infra uninstall: - # Here the "exec" step is invoked multiple times, each executing a single command - - exec: remove-docker-repo - - exec: remove-cicd-triggers + # The "confirm" step is similar to "if", however it prompts user with given message and + # only upon confirmation executes steps in the "then" clause. + - confirm: Are you sure you want to completely uninstall project {{.PROJECT}} from infrastructure? + then: + # Here the "exec" step is invoked multiple times, each executing a single command + - exec: remove-docker-repo + - exec: remove-cicd-triggers ``` # Templates @@ -474,7 +478,6 @@ To associate a template with an existing project that was not initially generate # Wishlist -- Allow `do` step to define multiple actions to call. - Add reusable modules (including both templates and scripts). - Add support for injecting snippets in specific sections of files in a second time (ie: adding multiple endpoints to an existing service). - Add `set` step to set multiple variables. diff --git a/src/internal/spec/spec.go b/src/internal/spec/spec.go index 809dc7b..927a2bf 100644 --- a/src/internal/spec/spec.go +++ b/src/internal/spec/spec.go @@ -153,7 +153,7 @@ func loadExecutable(node yaml.Node, templateDir string) (exec.Executable, error) }, { name: "do", - defaultSubKey: "action", + defaultSubKey: "actions", fct: loadDoStep, }, } @@ -361,12 +361,12 @@ func loadExecStep(_map yaml.Map, templateDir string) (exec.Executable, error) { } func loadDoStep(_map yaml.Map, templateDir string) (exec.Executable, error) { - action, err := getRequiredStringFromMap(_map, "action") + actions, err := getRequiredStringsOrStringFromMap(_map, "actions") if err != nil { return nil, err } return do.Do{ - Action: action, + Actions: actions, }, nil } diff --git a/src/internal/spec/spec_test.go b/src/internal/spec/spec_test.go index f63f98e..968f77c 100644 --- a/src/internal/spec/spec_test.go +++ b/src/internal/spec/spec_test.go @@ -252,6 +252,19 @@ exec: }, }, }, + { + Name: "exec step multiple child strings", + Buffer: ` +exec: + - Command 1 + - Command 2`, + Expected: execstep.Exec{ + Commands: []string{ + "Command 1", + "Command 2", + }, + }, + }, { Name: "exec step short-hand", Buffer: ` @@ -264,9 +277,21 @@ exec: Command 1`, Name: "do step long-hand", Buffer: ` do: - action: Action`, + actions: + - Action 1 + - Action 2`, + Expected: do.Do{ + Actions: []string{"Action 1", "Action 2"}, + }, + }, + { + Name: "do step multiple child strings", + Buffer: ` +do: + - Action 1 + - Action 2`, Expected: do.Do{ - Action: "Action", + Actions: []string{"Action 1", "Action 2"}, }, }, { @@ -274,7 +299,7 @@ do: Buffer: ` do: Action`, Expected: do.Do{ - Action: "Action", + Actions: []string{"Action"}, }, }, } diff --git a/src/internal/steps/do/do.go b/src/internal/steps/do/do.go index 9928a58..bfa20fe 100644 --- a/src/internal/steps/do/do.go +++ b/src/internal/steps/do/do.go @@ -9,7 +9,7 @@ import ( // Do represents a reference to another action within same spec file to which // execution will be delegated type Do struct { - Action string + Actions []string } func (d Do) String() string { @@ -18,9 +18,15 @@ func (d Do) String() string { // Execute executes another action with given name within same spec file func (d Do) Execute(context exec.Context) error { - action := context.GetAction(d.Action) - if action == nil { - return fmt.Errorf("action %q not found for do step", d.Action) + for _, action := range d.Actions { + action := context.GetAction(action) + if action == nil { + return fmt.Errorf("action %q not found for do step", action) + } + err := action.Execute(context) + if err != nil { + return err + } } - return action.Execute(context) + return nil }