Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow up to a fix for #492 #494

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions internal/cmd/run_locally.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion internal/command/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/runner/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sourishkrout this is an only place that could cause some issues in the future. The rest in internal/runner is clean up.

})
}

Expand Down
2 changes: 0 additions & 2 deletions internal/runner/client/client_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions internal/runner/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ type command struct {
Stdout io.Writer
Stderr io.Writer

PreEnv []string
PostEnv []string

cmd *exec.Cmd
cmdDone uint32

Expand Down Expand Up @@ -94,9 +91,6 @@ type commandConfig struct {
Stdout io.Writer
Stderr io.Writer

PreEnv []string
PostEnv []string

Commands []string
Script string

Expand Down Expand Up @@ -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,
Expand Down
14 changes: 0 additions & 14 deletions internal/runner/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions internal/runner/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down
2 changes: 0 additions & 2 deletions internal/runner/shellraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 0 additions & 2 deletions internal/runner/tempfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions testdata/script/dotenv.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Loading