Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change setupEnv to return an ExpressionEvaluator #423

Merged
merged 1 commit into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,11 @@ func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor {
Outputs: make(map[string]string),
}

_ = sc.setupEnv()(ctx)

if sc.Env != nil {
err := rc.JobContainer.UpdateFromGithubEnv(&sc.Env)(ctx)
if err != nil {
return err
}
exprEval, err := sc.setupEnv(ctx)
if err != nil {
return err
}
rc.ExprEval = sc.NewExpressionEvaluator()
rc.ExprEval = exprEval;

runStep, err := rc.EvalBool(sc.Step.If)
if err != nil {
Expand Down
56 changes: 38 additions & 18 deletions pkg/runner/step_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,53 @@ func (sc *StepContext) Executor() common.Executor {
return common.NewErrorExecutor(fmt.Errorf("Unable to determine how to run job:%s step:%+v", rc.Run, step))
}

func (sc *StepContext) setupEnv() common.Executor {
func (sc *StepContext) mergeEnv() map[string]string {
rc := sc.RunContext
job := rc.Run.Job()
step := sc.Step
return func(ctx context.Context) error {
var env map[string]string
c := job.Container()
if c != nil {
env = mergeMaps(rc.GetEnv(), c.Env, step.GetEnv())
} else {
env = mergeMaps(rc.GetEnv(), step.GetEnv())
}

if (rc.ExtraPath != nil) && (len(rc.ExtraPath) > 0) {
s := append(rc.ExtraPath, `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin`)
env["PATH"] = strings.Join(s, `:`)
}
var env map[string]string
c := job.Container()
if c != nil {
env = mergeMaps(rc.GetEnv(), c.Env, step.GetEnv())
} else {
env = mergeMaps(rc.GetEnv(), step.GetEnv())
}

if (rc.ExtraPath != nil) && (len(rc.ExtraPath) > 0) {
s := append(rc.ExtraPath, `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin`)
env["PATH"] = strings.Join(s, `:`)
}

sc.Env = rc.withGithubEnv(env)
return env
}


for k, v := range env {
env[k] = rc.ExprEval.Interpolate(v)
func (sc *StepContext) interpolateEnv(exprEval ExpressionEvaluator) {
for k, v := range sc.Env {
sc.Env[k] = exprEval.Interpolate(v)
}
}


func (sc *StepContext) setupEnv(ctx context.Context) (ExpressionEvaluator, error) {
rc := sc.RunContext
sc.Env = sc.mergeEnv()
if sc.Env != nil {
err := rc.JobContainer.UpdateFromGithubEnv(&sc.Env)(ctx)
if err != nil {
return nil, err
}
sc.Env = rc.withGithubEnv(env)
log.Debugf("setupEnv => %v", sc.Env)
return nil
}
evaluator := sc.NewExpressionEvaluator()
sc.interpolateEnv(evaluator)

log.Debugf("setupEnv: %v", sc.Env)
return evaluator, nil
}


func (sc *StepContext) setupShellCommand() common.Executor {
rc := sc.RunContext
step := sc.Step
Expand Down