From 27a9babc8bcb60e3ffcca1fc2864ab7cf4b19bab Mon Sep 17 00:00:00 2001 From: Adam Babik Date: Mon, 12 Feb 2024 14:33:39 +0100 Subject: [PATCH] Follow up to a fix for #492 (#494) --- internal/cmd/run_locally.go | 12 ++++++++++-- internal/command/session.go | 10 +++++++++- internal/runner/client/client.go | 2 +- internal/runner/client/client_local.go | 2 -- internal/runner/command.go | 8 -------- internal/runner/service.go | 14 -------------- internal/runner/shell.go | 2 -- internal/runner/shellraw.go | 2 -- internal/runner/tempfile.go | 2 -- testdata/script/dotenv.txtar | 4 ++++ 10 files changed, 24 insertions(+), 34 deletions(-) diff --git a/internal/cmd/run_locally.go b/internal/cmd/run_locally.go index 221023b2e..f5e87f3d3 100644 --- a/internal/cmd/run_locally.go +++ b/internal/cmd/run_locally.go @@ -32,13 +32,21 @@ The --category option additionally filters the list of tasks to execute.`, } defer logger.Sync() - session := command.NewSession() - proj, err := getProject() if err != nil { return err } + projEnv, err := proj.LoadEnv() + if err != nil { + return err + } + + session, err := command.NewSessionWithEnv(projEnv...) + if err != nil { + return err + } + tasks, err := project.LoadTasks(cmd.Context(), proj) if err != nil { return err diff --git a/internal/command/session.go b/internal/command/session.go index ea88e3a02..c653c6af2 100644 --- a/internal/command/session.go +++ b/internal/command/session.go @@ -23,9 +23,17 @@ func NewSession() *Session { } } -func MustNewSessionWithEnv(env ...string) *Session { +func NewSessionWithEnv(env ...string) (*Session, error) { s := NewSession() if err := s.SetEnv(env...); err != nil { + return nil, err + } + return s, nil +} + +func MustNewSessionWithEnv(env ...string) *Session { + s, err := NewSessionWithEnv(env...) + if err != nil { panic(err) } return s diff --git a/internal/runner/client/client.go b/internal/runner/client/client.go index 5744174b3..0d1639655 100644 --- a/internal/runner/client/client.go +++ b/internal/runner/client/client.go @@ -191,7 +191,7 @@ func WithEnableBackgroundProcesses(enableBackground bool) RunnerOption { func WithEnvs(envs []string) RunnerOption { return withSettings(func(rs *RunnerSettings) { - rs.envs = envs + rs.envs = append(rs.envs, envs...) }) } diff --git a/internal/runner/client/client_local.go b/internal/runner/client/client_local.go index e0a055f99..cad22a2ab 100644 --- a/internal/runner/client/client_local.go +++ b/internal/runner/client/client_local.go @@ -83,8 +83,6 @@ func (r *LocalRunner) newExecutable(task project.Task) (runner.Executable, error programName, _ := runner.GetCellProgram(block.Language(), customShell, block) - r.session.AddEnvs(r.envs) - cfg := &runner.ExecutableConfig{ Name: block.Name(), Dir: r.dir, diff --git a/internal/runner/command.go b/internal/runner/command.go index 59f46cb84..6a128e3da 100644 --- a/internal/runner/command.go +++ b/internal/runner/command.go @@ -37,9 +37,6 @@ type command struct { Stdout io.Writer Stderr io.Writer - PreEnv []string - PostEnv []string - cmd *exec.Cmd cmdDone uint32 @@ -94,9 +91,6 @@ type commandConfig struct { Stdout io.Writer Stderr io.Writer - PreEnv []string - PostEnv []string - Commands []string Script string @@ -243,8 +237,6 @@ func newCommand(cfg *commandConfig) (*command, error) { Stdin: cfg.Stdin, Stdout: cfg.Stdout, Stderr: cfg.Stderr, - PreEnv: cfg.PreEnv, - PostEnv: cfg.PostEnv, logger: cfg.Logger, tempScriptFile: tempScriptFile, tmpEnvDir: tmpEnvDir, diff --git a/internal/runner/service.go b/internal/runner/service.go index 9bb75f180..2700f08b0 100644 --- a/internal/runner/service.go +++ b/internal/runner/service.go @@ -253,20 +253,6 @@ func (r *runnerService) Execute(srv runnerv1.RunnerService_ExecuteServer) error cfg.CommandMode = CommandModeTempFile } - if req.Project != nil { - proj, err := ConvertRunnerProject(req.Project) - if err != nil { - return err - } - - projEnvs, err := proj.LoadEnv() - if err != nil { - return err - } - - cfg.PreEnv = append(cfg.PreEnv, projEnvs...) - } - logger.Debug("command config", zap.Any("cfg", cfg)) cmd, err := newCommand(cfg) if err != nil { diff --git a/internal/runner/shell.go b/internal/runner/shell.go index 314df5085..e27b15065 100644 --- a/internal/runner/shell.go +++ b/internal/runner/shell.go @@ -57,8 +57,6 @@ func (s *Shell) Run(ctx context.Context) error { Stdin: s.Stdin, Stdout: s.Stdout, Stderr: s.Stderr, - PreEnv: s.PreEnv, - PostEnv: s.PostEnv, CommandMode: CommandModeInlineShell, Commands: s.Cmds, Script: "", diff --git a/internal/runner/shellraw.go b/internal/runner/shellraw.go index bdd16d2e6..a6ed882c5 100644 --- a/internal/runner/shellraw.go +++ b/internal/runner/shellraw.go @@ -38,8 +38,6 @@ func (s ShellRaw) Run(ctx context.Context) error { Stdin: s.Stdin, Stdout: s.Stdout, Stderr: s.Stderr, - PreEnv: s.PreEnv, - PostEnv: s.PostEnv, CommandMode: CommandModeInlineShell, Commands: nil, Script: strings.Join(s.Cmds, "\n"), diff --git a/internal/runner/tempfile.go b/internal/runner/tempfile.go index 82d673c2d..d83f8d2bd 100644 --- a/internal/runner/tempfile.go +++ b/internal/runner/tempfile.go @@ -41,8 +41,6 @@ func (s *TempFile) Run(ctx context.Context) error { Stdin: s.Stdin, Stdout: s.Stdout, Stderr: s.Stderr, - PreEnv: s.PreEnv, - PostEnv: s.PostEnv, CommandMode: CommandModeTempFile, Script: s.Script, Logger: s.Logger, diff --git a/testdata/script/dotenv.txtar b/testdata/script/dotenv.txtar index d6fcf6de1..09cef38b3 100644 --- a/testdata/script/dotenv.txtar +++ b/testdata/script/dotenv.txtar @@ -2,6 +2,10 @@ exec runme run env1 stdout 'SOMETHING=in-my-dot-env' ! stderr . +exec runme run-locally env1 +stdout 'SOMETHING=in-my-dot-env' +! stderr . + -- .env -- SOMETHING="in-my-dot-env"