fix #134 - support 'env' context in steps
This commit is contained in:
parent
4fde7d8865
commit
87392c2ed7
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue