fix: rewrite StepContext env (#832)
* fix: rewrite StepContext env step env from workflow should be last one to be written fixes https://github.com/nektos/act/issues/777 * test: verify env correctness * fix: move test into existing workflow
This commit is contained in:
parent
6c60af7677
commit
a0d360236e
2 changed files with 6 additions and 3 deletions
|
@ -130,14 +130,13 @@ func (sc *StepContext) Executor() common.Executor {
|
||||||
func (sc *StepContext) mergeEnv() map[string]string {
|
func (sc *StepContext) mergeEnv() map[string]string {
|
||||||
rc := sc.RunContext
|
rc := sc.RunContext
|
||||||
job := rc.Run.Job()
|
job := rc.Run.Job()
|
||||||
step := sc.Step
|
|
||||||
|
|
||||||
var env map[string]string
|
var env map[string]string
|
||||||
c := job.Container()
|
c := job.Container()
|
||||||
if c != nil {
|
if c != nil {
|
||||||
env = mergeMaps(rc.GetEnv(), c.Env, step.GetEnv())
|
env = mergeMaps(rc.GetEnv(), c.Env)
|
||||||
} else {
|
} else {
|
||||||
env = mergeMaps(rc.GetEnv(), step.GetEnv())
|
env = rc.GetEnv()
|
||||||
}
|
}
|
||||||
|
|
||||||
if env["PATH"] == "" {
|
if env["PATH"] == "" {
|
||||||
|
@ -176,6 +175,7 @@ func (sc *StepContext) setupEnv(ctx context.Context) (ExpressionEvaluator, error
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sc.Env = mergeMaps(sc.Env, sc.Step.GetEnv()) // step env should not be overwritten
|
||||||
evaluator := sc.NewExpressionEvaluator()
|
evaluator := sc.NewExpressionEvaluator()
|
||||||
sc.interpolateEnv(evaluator)
|
sc.interpolateEnv(evaluator)
|
||||||
|
|
||||||
|
|
|
@ -10,4 +10,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
who-to-greet: 'Mona the Octocat'
|
who-to-greet: 'Mona the Octocat'
|
||||||
- run: '[[ "${{ env.SOMEVAR }}" == "Mona the Octocat" ]]'
|
- run: '[[ "${{ env.SOMEVAR }}" == "Mona the Octocat" ]]'
|
||||||
|
- run: '[ "${SOMEVAR}" = "Not Mona" ] || exit 1'
|
||||||
|
env:
|
||||||
|
SOMEVAR: 'Not Mona'
|
||||||
- uses: ./localdockerimagetest_
|
- uses: ./localdockerimagetest_
|
||||||
|
|
Loading…
Reference in a new issue