Skip to content

Commit

Permalink
fix: rewrite StepContext env (#832)
Browse files Browse the repository at this point in the history
* fix: rewrite StepContext env

step env from workflow should be last one to be written
fixes #777

* test: verify env correctness

* fix: move test into existing workflow
  • Loading branch information
Ryan authored Sep 28, 2021
1 parent 6c60af7 commit a0d3602
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/runner/step_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,13 @@ func (sc *StepContext) Executor() common.Executor {
func (sc *StepContext) mergeEnv() map[string]string {
rc := sc.RunContext
job := rc.Run.Job()
step := sc.Step

var env map[string]string
c := job.Container()
if c != nil {
env = mergeMaps(rc.GetEnv(), c.Env, step.GetEnv())
env = mergeMaps(rc.GetEnv(), c.Env)
} else {
env = mergeMaps(rc.GetEnv(), step.GetEnv())
env = rc.GetEnv()
}

if env["PATH"] == "" {
Expand Down Expand Up @@ -176,6 +175,7 @@ func (sc *StepContext) setupEnv(ctx context.Context) (ExpressionEvaluator, error
return nil, err
}
}
sc.Env = mergeMaps(sc.Env, sc.Step.GetEnv()) // step env should not be overwritten
evaluator := sc.NewExpressionEvaluator()
sc.interpolateEnv(evaluator)

Expand Down
3 changes: 3 additions & 0 deletions pkg/runner/testdata/local-action-dockerfile/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ jobs:
with:
who-to-greet: 'Mona the Octocat'
- run: '[[ "${{ env.SOMEVAR }}" == "Mona the Octocat" ]]'
- run: '[ "${SOMEVAR}" = "Not Mona" ] || exit 1'
env:
SOMEVAR: 'Not Mona'
- uses: ./localdockerimagetest_

0 comments on commit a0d3602

Please sign in to comment.