feature: Arguments are now also passed as ENV variables (#296)

This commit is contained in:
James Read
2024-04-26 23:03:17 +00:00
committed by GitHub
parent 6a16a7c6c2
commit a783fc8cd4
+13
View File
@@ -14,8 +14,10 @@ import (
"context"
"fmt"
"io"
"os"
"os/exec"
"runtime"
"strings"
"sync"
"time"
)
@@ -352,6 +354,16 @@ func appendErrorToStderr(err error, logEntry *InternalLogEntry) {
}
}
func buildEnv(req *ExecutionRequest) []string {
ret := append(os.Environ(), "OLIVETIN=1")
for k, v := range req.Arguments {
ret = append(ret, fmt.Sprintf("%v=%v", strings.ToUpper(k), v))
}
return ret
}
func stepExec(req *ExecutionRequest) bool {
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(req.Action.Timeout)*time.Second)
defer cancel()
@@ -360,6 +372,7 @@ func stepExec(req *ExecutionRequest) bool {
var stderr bytes.Buffer
cmd := wrapCommandInShell(ctx, req.finalParsedCommand)
cmd.Env = buildEnv(req)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
req.logEntry.StdoutBuffer, _ = cmd.StdoutPipe()