Skip to content

Commit

Permalink
pre-run shell scripts
Browse files Browse the repository at this point in the history
This avoid to run multiple times the same script

Signed-off-by: Yves Brissaud <[email protected]>
  • Loading branch information
eunomie committed Oct 11, 2024
1 parent 6b979e7 commit aa97885
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions runkit/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ func (r *Runnable) cleanup() func() {
}

func (r *Runnable) compute() error {
shells := map[string]string{}
for k, v := range r.Action.Shell {
out, err := sh(context.Background(), v)
if err != nil {
return fmt.Errorf("could not run shell script %s: %w", k, err)
}
shells[k] = out
}

tmpl, err := template.New("runx").Funcs(template.FuncMap{
"env": func(envName string) string {
return r.data.Env[envName]
Expand All @@ -110,11 +119,11 @@ func (r *Runnable) compute() error {
return r.data.Opts[optName]
},
"sh": func(cmdName string) (string, error) {
cmd, ok := r.Action.Shell[cmdName]
v, ok := shells[cmdName]
if !ok {
return "", fmt.Errorf("shell command %q not found", cmdName)
}
return sh(context.Background(), cmd)
return v, nil
},
}).Parse(r.Action.Command)
if err != nil {
Expand Down

0 comments on commit aa97885

Please sign in to comment.