fix #134 - support 'env' context in steps

This commit is contained in:
Casey Lee 2020-03-06 13:39:01 -08:00
parent 4fde7d8865
commit 87392c2ed7
No known key found for this signature in database
GPG key ID: 1899120ECD0A1784
4 changed files with 14 additions and 4 deletions

View file

@ -13,6 +13,7 @@ import (
"github.com/robertkrimen/otto" "github.com/robertkrimen/otto"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
"gopkg.in/godo.v2/glob" "gopkg.in/godo.v2/glob"
) )
@ -240,6 +241,7 @@ func (rc *RunContext) vmGithub() func(*otto.Otto) {
func (sc *StepContext) vmEnv() func(*otto.Otto) { func (sc *StepContext) vmEnv() func(*otto.Otto) {
return func(vm *otto.Otto) { return func(vm *otto.Otto) {
log.Debugf("context env => %v", sc.Env)
_ = vm.Set("env", sc.Env) _ = vm.Set("env", sc.Env)
} }
} }

View file

@ -193,6 +193,8 @@ func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor {
Success: true, Success: true,
Outputs: make(map[string]string), Outputs: make(map[string]string),
} }
sc.setupEnv()(ctx)
rc.ExprEval = sc.NewExpressionEvaluator() rc.ExprEval = sc.NewExpressionEvaluator()
if !rc.EvalBool(sc.Step.If) { if !rc.EvalBool(sc.Step.If) {

View file

@ -38,21 +38,18 @@ func (sc *StepContext) Executor() common.Executor {
switch step.Type() { switch step.Type() {
case model.StepTypeRun: case model.StepTypeRun:
return common.NewPipelineExecutor( return common.NewPipelineExecutor(
sc.setupEnv(),
sc.setupShellCommand(), sc.setupShellCommand(),
sc.execJobContainer(), sc.execJobContainer(),
) )
case model.StepTypeUsesDockerURL: case model.StepTypeUsesDockerURL:
return common.NewPipelineExecutor( return common.NewPipelineExecutor(
sc.setupEnv(),
sc.runUsesContainer(), sc.runUsesContainer(),
) )
case model.StepTypeUsesActionLocal: case model.StepTypeUsesActionLocal:
actionDir := filepath.Join(rc.Config.Workdir, step.Uses) actionDir := filepath.Join(rc.Config.Workdir, step.Uses)
return common.NewPipelineExecutor( return common.NewPipelineExecutor(
sc.setupEnv(),
sc.setupAction(actionDir, ""), sc.setupAction(actionDir, ""),
sc.runAction(actionDir, ""), sc.runAction(actionDir, ""),
) )
@ -72,7 +69,6 @@ func (sc *StepContext) Executor() common.Executor {
Ref: remoteAction.Ref, Ref: remoteAction.Ref,
Dir: actionDir, Dir: actionDir,
}), }),
sc.setupEnv(),
sc.setupAction(actionDir, remoteAction.Path), sc.setupAction(actionDir, remoteAction.Path),
sc.runAction(actionDir, remoteAction.Path), sc.runAction(actionDir, remoteAction.Path),
) )
@ -98,6 +94,7 @@ func (sc *StepContext) setupEnv() common.Executor {
env[k] = rc.ExprEval.Interpolate(v) env[k] = rc.ExprEval.Interpolate(v)
} }
sc.Env = rc.withGithubEnv(env) sc.Env = rc.withGithubEnv(env)
log.Debugf("setupEnv => %v", sc.Env)
return nil return nil
} }
} }

View file

@ -1,10 +1,19 @@
name: basic name: basic
on: push on: push
env:
TEST: value
jobs: jobs:
check: check:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: 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: ls
- run: echo 'hello world' - run: echo 'hello world'
- run: echo ${GITHUB_SHA} >> /github/sha.txt - run: echo ${GITHUB_SHA} >> /github/sha.txt