fix: step env is unavailable in with property expr (#1458)
* fix: step env is unavailable in with property expr * don't run the test on windows * fix: composite action add missing shell Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
57bf4d27a2
commit
8c5748a55c
5 changed files with 40 additions and 2 deletions
|
@ -21,6 +21,10 @@ type ExpressionEvaluator interface {
|
||||||
|
|
||||||
// NewExpressionEvaluator creates a new evaluator
|
// NewExpressionEvaluator creates a new evaluator
|
||||||
func (rc *RunContext) NewExpressionEvaluator(ctx context.Context) ExpressionEvaluator {
|
func (rc *RunContext) NewExpressionEvaluator(ctx context.Context) ExpressionEvaluator {
|
||||||
|
return rc.NewExpressionEvaluatorWithEnv(ctx, rc.GetEnv())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RunContext) NewExpressionEvaluatorWithEnv(ctx context.Context, env map[string]string) ExpressionEvaluator {
|
||||||
// todo: cleanup EvaluationEnvironment creation
|
// todo: cleanup EvaluationEnvironment creation
|
||||||
using := make(map[string]map[string]map[string]string)
|
using := make(map[string]map[string]map[string]string)
|
||||||
strategy := make(map[string]interface{})
|
strategy := make(map[string]interface{})
|
||||||
|
@ -46,7 +50,7 @@ func (rc *RunContext) NewExpressionEvaluator(ctx context.Context) ExpressionEval
|
||||||
|
|
||||||
ee := &exprparser.EvaluationEnvironment{
|
ee := &exprparser.EvaluationEnvironment{
|
||||||
Github: ghc,
|
Github: ghc,
|
||||||
Env: rc.GetEnv(),
|
Env: env,
|
||||||
Job: rc.getJobContext(),
|
Job: rc.getJobContext(),
|
||||||
// todo: should be unavailable
|
// todo: should be unavailable
|
||||||
// but required to interpolate/evaluate the step outputs on the job
|
// but required to interpolate/evaluate the step outputs on the job
|
||||||
|
|
|
@ -287,6 +287,7 @@ func TestRunEventHostEnvironment(t *testing.T) {
|
||||||
|
|
||||||
tables = append(tables, []TestJobFileInfo{
|
tables = append(tables, []TestJobFileInfo{
|
||||||
{workdir, "nix-prepend-path", "push", "", platforms},
|
{workdir, "nix-prepend-path", "push", "", platforms},
|
||||||
|
{workdir, "inputs-via-env-context", "push", "", platforms},
|
||||||
}...)
|
}...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,7 +179,17 @@ func setupEnv(ctx context.Context, step step) error {
|
||||||
|
|
||||||
exprEval := rc.NewExpressionEvaluator(ctx)
|
exprEval := rc.NewExpressionEvaluator(ctx)
|
||||||
for k, v := range *step.getEnv() {
|
for k, v := range *step.getEnv() {
|
||||||
(*step.getEnv())[k] = exprEval.Interpolate(ctx, v)
|
if !strings.HasPrefix(k, "INPUT_") {
|
||||||
|
(*step.getEnv())[k] = exprEval.Interpolate(ctx, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// after we have an evaluated step context, update the expresson evaluator with a new env context
|
||||||
|
// you can use step level env in the with property of a uses construct
|
||||||
|
exprEval = rc.NewExpressionEvaluatorWithEnv(ctx, *step.getEnv())
|
||||||
|
for k, v := range *step.getEnv() {
|
||||||
|
if strings.HasPrefix(k, "INPUT_") {
|
||||||
|
(*step.getEnv())[k] = exprEval.Interpolate(ctx, v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
common.Logger(ctx).Debugf("setupEnv => %v", *step.getEnv())
|
common.Logger(ctx).Debugf("setupEnv => %v", *step.getEnv())
|
||||||
|
|
8
pkg/runner/testdata/inputs-via-env-context/action.yml
vendored
Normal file
8
pkg/runner/testdata/inputs-via-env-context/action.yml
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
inputs:
|
||||||
|
test-env-input: {}
|
||||||
|
runs:
|
||||||
|
using: composite
|
||||||
|
steps:
|
||||||
|
- run: |
|
||||||
|
exit ${{ inputs.test-env-input == env.test-env-input && '0' || '1'}}
|
||||||
|
shell: bash
|
15
pkg/runner/testdata/inputs-via-env-context/push.yml
vendored
Normal file
15
pkg/runner/testdata/inputs-via-env-context/push.yml
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
on: push
|
||||||
|
jobs:
|
||||||
|
test-inputs-via-env-context:
|
||||||
|
runs-on: self-hosted
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: ./inputs-via-env-context
|
||||||
|
with:
|
||||||
|
test-env-input: ${{ env.test-env-input }}
|
||||||
|
env:
|
||||||
|
test-env-input: ${{ github.event_name }}/${{ github.run_id }}
|
||||||
|
- run: |
|
||||||
|
exit ${{ env.test-env-input == format('{0}/{1}', github.event_name, github.run_id) && '0' || '1' }}
|
||||||
|
env:
|
||||||
|
test-env-input: ${{ github.event_name }}/${{ github.run_id }}
|
Loading…
Reference in a new issue