feat: interpolate the step names (#1422)
* feat: interpolate the step names Step names could contain expressions refering to event data. Fixes #1353 * test: add missing mock data * fix: setup composite expression evaluator The RunContext does contain a cached ExpressionEvaluator. This should be the case the composite RunContext as well. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
parent
e520382d2f
commit
809da7198c
7 changed files with 19 additions and 4 deletions
|
@ -71,6 +71,7 @@ func newCompositeRunContext(ctx context.Context, parent *RunContext, step action
|
|||
Parent: parent,
|
||||
EventJSON: parent.EventJSON,
|
||||
}
|
||||
compositerc.ExprEval = compositerc.NewExpressionEvaluator(ctx)
|
||||
|
||||
return compositerc
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo
|
|||
|
||||
func useStepLogger(rc *RunContext, stepModel *model.Step, stage stepStage, executor common.Executor) common.Executor {
|
||||
return func(ctx context.Context) error {
|
||||
ctx = withStepLogger(ctx, stepModel.ID, stepModel.String(), stage.String())
|
||||
ctx = withStepLogger(ctx, stepModel.ID, rc.ExprEval.Interpolate(ctx, stepModel.String()), stage.String())
|
||||
|
||||
rawLogger := common.Logger(ctx).WithField("raw_output", true)
|
||||
logWriter := common.NewLineWriter(rc.commandHandler(ctx), func(s string) bool {
|
||||
|
|
|
@ -249,7 +249,17 @@ func TestNewJobExecutor(t *testing.T) {
|
|||
sfm := &stepFactoryMock{}
|
||||
rc := &RunContext{
|
||||
JobContainer: &jobContainerMock{},
|
||||
Run: &model.Run{
|
||||
JobID: "test",
|
||||
Workflow: &model.Workflow{
|
||||
Jobs: map[string]*model.Job{
|
||||
"test": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
Config: &Config{},
|
||||
}
|
||||
rc.ExprEval = rc.NewExpressionEvaluator(ctx)
|
||||
executorOrder := make([]string, 0)
|
||||
|
||||
jim.On("steps").Return(tt.steps)
|
||||
|
|
|
@ -90,7 +90,7 @@ func runStepExecutor(step step, stage stepStage, executor common.Executor) commo
|
|||
return nil
|
||||
}
|
||||
|
||||
stepString := stepModel.String()
|
||||
stepString := rc.ExprEval.Interpolate(ctx, stepModel.String())
|
||||
if strings.Contains(stepString, "::add-mask::") {
|
||||
stepString = "add-mask command"
|
||||
}
|
||||
|
|
|
@ -275,6 +275,7 @@ func TestStepActionLocalPost(t *testing.T) {
|
|||
Step: tt.stepModel,
|
||||
action: tt.actionModel,
|
||||
}
|
||||
sal.RunContext.ExprEval = sal.RunContext.NewExpressionEvaluator(ctx)
|
||||
|
||||
if tt.mocks.env {
|
||||
cm.On("UpdateFromImageEnv", &sal.env).Return(func(ctx context.Context) error { return nil })
|
||||
|
|
|
@ -155,6 +155,7 @@ func TestStepActionRemote(t *testing.T) {
|
|||
readAction: sarm.readAction,
|
||||
runAction: sarm.runAction,
|
||||
}
|
||||
sar.RunContext.ExprEval = sar.RunContext.NewExpressionEvaluator(ctx)
|
||||
|
||||
suffixMatcher := func(suffix string) interface{} {
|
||||
return mock.MatchedBy(func(actionDir string) bool {
|
||||
|
@ -586,6 +587,7 @@ func TestStepActionRemotePost(t *testing.T) {
|
|||
Step: tt.stepModel,
|
||||
action: tt.actionModel,
|
||||
}
|
||||
sar.RunContext.ExprEval = sar.RunContext.NewExpressionEvaluator(ctx)
|
||||
|
||||
if tt.mocks.env {
|
||||
cm.On("UpdateFromImageEnv", &sar.env).Return(func(ctx context.Context) error { return nil })
|
||||
|
|
|
@ -25,6 +25,8 @@ func TestStepDockerMain(t *testing.T) {
|
|||
ContainerNewContainer = origContainerNewContainer
|
||||
})()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
sd := &stepDocker{
|
||||
RunContext: &RunContext{
|
||||
StepResults: map[string]*model.StepResult{},
|
||||
|
@ -51,8 +53,7 @@ func TestStepDockerMain(t *testing.T) {
|
|||
WorkingDirectory: "workdir",
|
||||
},
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
sd.RunContext.ExprEval = sd.RunContext.NewExpressionEvaluator(ctx)
|
||||
|
||||
cm.On("UpdateFromImageEnv", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue