From 87392c2ed75fdc1468c980604a85429a07b9d7d8 Mon Sep 17 00:00:00 2001 From: Casey Lee Date: Fri, 6 Mar 2020 13:39:01 -0800 Subject: [PATCH] fix #134 - support 'env' context in steps --- pkg/runner/expression.go | 2 ++ pkg/runner/run_context.go | 2 ++ pkg/runner/step_context.go | 5 +---- pkg/runner/testdata/basic/push.yml | 9 +++++++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/runner/expression.go b/pkg/runner/expression.go index af4a2d1..c9e5618 100644 --- a/pkg/runner/expression.go +++ b/pkg/runner/expression.go @@ -13,6 +13,7 @@ import ( "github.com/robertkrimen/otto" "github.com/sirupsen/logrus" + log "github.com/sirupsen/logrus" "gopkg.in/godo.v2/glob" ) @@ -240,6 +241,7 @@ func (rc *RunContext) vmGithub() func(*otto.Otto) { func (sc *StepContext) vmEnv() func(*otto.Otto) { return func(vm *otto.Otto) { + log.Debugf("context env => %v", sc.Env) _ = vm.Set("env", sc.Env) } } diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index a826fad..1b5b8b9 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -193,6 +193,8 @@ func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor { Success: true, Outputs: make(map[string]string), } + + sc.setupEnv()(ctx) rc.ExprEval = sc.NewExpressionEvaluator() if !rc.EvalBool(sc.Step.If) { diff --git a/pkg/runner/step_context.go b/pkg/runner/step_context.go index 898adac..fbd13d7 100644 --- a/pkg/runner/step_context.go +++ b/pkg/runner/step_context.go @@ -38,21 +38,18 @@ func (sc *StepContext) Executor() common.Executor { switch step.Type() { case model.StepTypeRun: return common.NewPipelineExecutor( - sc.setupEnv(), sc.setupShellCommand(), sc.execJobContainer(), ) case model.StepTypeUsesDockerURL: return common.NewPipelineExecutor( - sc.setupEnv(), sc.runUsesContainer(), ) case model.StepTypeUsesActionLocal: actionDir := filepath.Join(rc.Config.Workdir, step.Uses) return common.NewPipelineExecutor( - sc.setupEnv(), sc.setupAction(actionDir, ""), sc.runAction(actionDir, ""), ) @@ -72,7 +69,6 @@ func (sc *StepContext) Executor() common.Executor { Ref: remoteAction.Ref, Dir: actionDir, }), - sc.setupEnv(), sc.setupAction(actionDir, remoteAction.Path), sc.runAction(actionDir, remoteAction.Path), ) @@ -98,6 +94,7 @@ func (sc *StepContext) setupEnv() common.Executor { env[k] = rc.ExprEval.Interpolate(v) } sc.Env = rc.withGithubEnv(env) + log.Debugf("setupEnv => %v", sc.Env) return nil } } diff --git a/pkg/runner/testdata/basic/push.yml b/pkg/runner/testdata/basic/push.yml index 2ae1ea5..1e09070 100644 --- a/pkg/runner/testdata/basic/push.yml +++ b/pkg/runner/testdata/basic/push.yml @@ -1,10 +1,19 @@ name: basic on: push +env: + TEST: value + jobs: check: runs-on: ubuntu-latest steps: + - run: echo ${{ env.TEST }} | grep value + - run: env + - uses: docker://alpine:3.8 + with: + somekey: ${{ env.TEST }} + args: echo ${INPUT_SOMEKEY} | grep somevalue - run: ls - run: echo 'hello world' - run: echo ${GITHUB_SHA} >> /github/sha.txt