Skip to content

Commit aa97885

Browse files
committed
pre-run shell scripts
This avoid to run multiple times the same script Signed-off-by: Yves Brissaud <[email protected]>
1 parent 6b979e7 commit aa97885

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

runkit/run.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ func (r *Runnable) cleanup() func() {
102102
}
103103

104104
func (r *Runnable) compute() error {
105+
shells := map[string]string{}
106+
for k, v := range r.Action.Shell {
107+
out, err := sh(context.Background(), v)
108+
if err != nil {
109+
return fmt.Errorf("could not run shell script %s: %w", k, err)
110+
}
111+
shells[k] = out
112+
}
113+
105114
tmpl, err := template.New("runx").Funcs(template.FuncMap{
106115
"env": func(envName string) string {
107116
return r.data.Env[envName]
@@ -110,11 +119,11 @@ func (r *Runnable) compute() error {
110119
return r.data.Opts[optName]
111120
},
112121
"sh": func(cmdName string) (string, error) {
113-
cmd, ok := r.Action.Shell[cmdName]
122+
v, ok := shells[cmdName]
114123
if !ok {
115124
return "", fmt.Errorf("shell command %q not found", cmdName)
116125
}
117-
return sh(context.Background(), cmd)
126+
return v, nil
118127
},
119128
}).Parse(r.Action.Command)
120129
if err != nil {

0 commit comments

Comments
 (0)