-
Notifications
You must be signed in to change notification settings - Fork 14
/
task.go
68 lines (59 loc) · 1.87 KB
/
task.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
67
68
package executors
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/go-cmd/cmd"
"github.com/lunarway/shuttle/pkg/config"
"github.com/lunarway/shuttle/pkg/executors/golang/executer"
"github.com/lunarway/shuttle/pkg/ui"
)
func TaskExecutor(action config.ShuttleAction) (Executor, bool) {
return executeTask, action.Task != ""
}
func executeTask(ctx context.Context, ui *ui.UI, context ActionExecutionContext) error {
context.ScriptContext.Project.UI.Verboseln("Starting task command: %s", context.Action.Task)
args := make([]string, 0)
args = append(args, context.Action.Task)
for name, value := range context.ScriptContext.Args {
args = append(args, fmt.Sprintf("--%s", name))
args = append(args, value)
}
err := executer.Run(ctx, ui, &context.ScriptContext.Project, fmt.Sprintf("%s/shuttle.yaml", context.ScriptContext.Project.ProjectPath), args...)
if err != nil {
return err
}
return nil
}
func setupTaskCommandEnvironmentVariables(execCmd *cmd.Cmd, context ActionExecutionContext) {
shuttlePath, _ := filepath.Abs(filepath.Dir(os.Args[0]))
execCmd.Env = os.Environ()
for name, value := range context.ScriptContext.Args {
execCmd.Env = append(execCmd.Env, fmt.Sprintf("%s=%s", name, value))
}
execCmd.Env = append(
execCmd.Env,
fmt.Sprintf("plan=%s", context.ScriptContext.Project.LocalPlanPath),
)
execCmd.Env = append(
execCmd.Env,
fmt.Sprintf("tmp=%s", context.ScriptContext.Project.TempDirectoryPath),
)
execCmd.Env = append(
execCmd.Env,
fmt.Sprintf("project=%s", context.ScriptContext.Project.ProjectPath),
)
// TODO: Add project path as a shuttle specific ENV
execCmd.Env = append(
execCmd.Env,
fmt.Sprintf("PATH=%s", shuttlePath+string(os.PathListSeparator)+os.Getenv("PATH")),
)
execCmd.Env = append(
execCmd.Env,
fmt.Sprintf(
"SHUTTLE_PLANS_ALREADY_VALIDATED=%s",
context.ScriptContext.Project.LocalPlanPath,
),
)
}