/
worflow_utils.go
66 lines (53 loc) 路 1.9 KB
/
worflow_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package exec
import (
"fmt"
"strings"
cfg "github.com/cloudposse/atmos/pkg/config"
u "github.com/cloudposse/atmos/pkg/utils"
)
func executeWorkflowSteps(workflow string, workflowDefinition cfg.WorkflowDefinition, dryRun bool, commandLineStack string) error {
var steps = workflowDefinition.Steps
for stepIdx, step := range steps {
var command = strings.TrimSpace(step.Command)
var commandType = strings.TrimSpace(step.Type)
u.PrintInfo(fmt.Sprintf("Executing workflow step: %s", command))
if commandType == "" {
commandType = "atmos"
}
if commandType == "shell" {
commandName := fmt.Sprintf("%s-step-%d", workflow, stepIdx)
if err := ExecuteShell(command, commandName, ".", []string{}, dryRun, true); err != nil {
return err
}
} else if commandType == "atmos" {
args := strings.Fields(command)
var workflowStack = strings.TrimSpace(workflowDefinition.Stack)
var stepStack = strings.TrimSpace(step.Stack)
var finalStack = ""
// The workflow `stack` attribute overrides the stack in the `command` (if specified)
// The step `stack` attribute overrides the stack in the `command` and the workflow `stack` attribute
// The stack defined on the command line (`atmos workflow <name> -f <file> -s <stack>`) has the highest priority,
// it overrides all other stacks attributes
if workflowStack != "" {
finalStack = workflowStack
}
if stepStack != "" {
finalStack = stepStack
}
if commandLineStack != "" {
finalStack = commandLineStack
}
if finalStack != "" {
args = append(args, []string{"-s", finalStack}...)
u.PrintInfo(fmt.Sprintf("Stack: %s", finalStack))
}
if err := ExecuteShellCommand("atmos", args, ".", []string{}, dryRun, true); err != nil {
return err
}
} else {
return fmt.Errorf("invalid workflow step type '%s'. Supported types are 'atmos' and 'shell'", commandType)
}
fmt.Println()
}
return nil
}