Skip to content

Commit

Permalink
Fix .env which broke as part of moving cmds to the project service (#493
Browse files Browse the repository at this point in the history
)

* Fix .env* loading

* Compact logic

* Don't use present progressive

* Load envs when options are applied
  • Loading branch information
sourishkrout authored Feb 9, 2024
1 parent ae426f6 commit c6b7703
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
8 changes: 7 additions & 1 deletion internal/runner/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/go-git/go-billy/v5/osfs"
"github.com/muesli/cancelreader"
"github.com/pkg/errors"
"github.com/stateful/runme/internal/document"
runnerv1 "github.com/stateful/runme/internal/gen/proto/go/runme/runner/v1"
"github.com/stateful/runme/internal/project"
Expand Down Expand Up @@ -88,8 +89,13 @@ func WithSessionID(id string) RunnerOption {
}

func WithProject(proj *project.Project) RunnerOption {
return withSettings(func(rs *RunnerSettings) {
return withSettingsErr(func(rs *RunnerSettings) error {
rs.project = proj

projEnvs, err := rs.project.LoadEnv()
rs.envs = append(rs.envs, projEnvs...)

return errors.Wrap(err, "failed to apply project envs")
})
}

Expand Down
1 change: 0 additions & 1 deletion internal/runner/client/client_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (r *LocalRunner) newExecutable(task project.Task) (runner.Executable, error
Logger: r.logger,
}

// TODO(adamb): what about `r.envs`?
cfg.PreEnv, err = r.project.LoadEnv()
if err != nil {
return nil, err
Expand Down
15 changes: 15 additions & 0 deletions testdata/script/dotenv.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exec runme run env1
stdout 'SOMETHING=in-my-dot-env'
! stderr .

-- .env --
SOMETHING="in-my-dot-env"

-- README.md --
---
shell: bash
---

```sh {"name":"env1"}
echo SOMETHING=${SOMETHING}
```

0 comments on commit c6b7703

Please sign in to comment.