Add needs
job output (#629)
* Add outputs field to job model * Add output interpolation for jobs * Add otto config reference for interpolated job output values into 'needs' context * Add output interpolation call after job has completed. * gofmt * Remove whitespace * goimports Co-authored-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
@@ -229,6 +229,7 @@ func (rc *RunContext) newVM() *otto.Otto {
|
||||
rc.vmStrategy(),
|
||||
rc.vmMatrix(),
|
||||
rc.vmEnv(),
|
||||
rc.vmNeeds(),
|
||||
}
|
||||
vm := otto.New()
|
||||
for _, configer := range configers {
|
||||
@@ -415,6 +416,23 @@ func (sc *StepContext) vmInputs() func(*otto.Otto) {
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *RunContext) vmNeeds() func(*otto.Otto) {
|
||||
jobs := rc.Run.Workflow.Jobs
|
||||
jobNeeds := rc.Run.Job().Needs()
|
||||
|
||||
using := make(map[string]map[string]map[string]string)
|
||||
for _, needs := range jobNeeds {
|
||||
using[needs] = map[string]map[string]string{
|
||||
"outputs": jobs[needs].Outputs,
|
||||
}
|
||||
}
|
||||
|
||||
return func(vm *otto.Otto) {
|
||||
log.Debugf("context needs => %v", using)
|
||||
_ = vm.Set("needs", using)
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *RunContext) vmJob() func(*otto.Otto) {
|
||||
job := rc.getJobContext()
|
||||
|
||||
|
@@ -262,7 +262,7 @@ func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor {
|
||||
rc.ExprEval = exprEval
|
||||
|
||||
common.Logger(ctx).Infof("\u2B50 Run %s", sc.Step)
|
||||
err = sc.Executor()(ctx)
|
||||
err = sc.Executor().Then(sc.interpolateOutputs())(ctx)
|
||||
if err == nil {
|
||||
common.Logger(ctx).Infof(" \u2705 Success - %s", sc.Step)
|
||||
} else {
|
||||
|
@@ -29,6 +29,7 @@ type StepContext struct {
|
||||
Env map[string]string
|
||||
Cmd []string
|
||||
Action *model.Action
|
||||
Needs *model.Job
|
||||
}
|
||||
|
||||
func (sc *StepContext) execJobContainer() common.Executor {
|
||||
@@ -37,6 +38,19 @@ func (sc *StepContext) execJobContainer() common.Executor {
|
||||
}
|
||||
}
|
||||
|
||||
func (sc *StepContext) interpolateOutputs() common.Executor {
|
||||
return func(ctx context.Context) error {
|
||||
ee := sc.NewExpressionEvaluator()
|
||||
for k, v := range sc.RunContext.Run.Job().Outputs {
|
||||
interpolated := ee.Interpolate(v)
|
||||
if v != interpolated {
|
||||
sc.RunContext.Run.Job().Outputs[k] = interpolated
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
type formatError string
|
||||
|
||||
func (e formatError) Error() string {
|
||||
|
Reference in New Issue
Block a user