Skip to content

Commit 809da71

Browse files
KnisterPetermergify[bot]cplee
authored
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 <[email protected]>
1 parent e520382 commit 809da71

File tree

7 files changed

+19
-4
lines changed

7 files changed

+19
-4
lines changed

pkg/runner/action_composite.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func newCompositeRunContext(ctx context.Context, parent *RunContext, step action
7171
Parent: parent,
7272
EventJSON: parent.EventJSON,
7373
}
74+
compositerc.ExprEval = compositerc.NewExpressionEvaluator(ctx)
7475

7576
return compositerc
7677
}

pkg/runner/job_executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo
133133

134134
func useStepLogger(rc *RunContext, stepModel *model.Step, stage stepStage, executor common.Executor) common.Executor {
135135
return func(ctx context.Context) error {
136-
ctx = withStepLogger(ctx, stepModel.ID, stepModel.String(), stage.String())
136+
ctx = withStepLogger(ctx, stepModel.ID, rc.ExprEval.Interpolate(ctx, stepModel.String()), stage.String())
137137

138138
rawLogger := common.Logger(ctx).WithField("raw_output", true)
139139
logWriter := common.NewLineWriter(rc.commandHandler(ctx), func(s string) bool {

pkg/runner/job_executor_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,17 @@ func TestNewJobExecutor(t *testing.T) {
249249
sfm := &stepFactoryMock{}
250250
rc := &RunContext{
251251
JobContainer: &jobContainerMock{},
252+
Run: &model.Run{
253+
JobID: "test",
254+
Workflow: &model.Workflow{
255+
Jobs: map[string]*model.Job{
256+
"test": {},
257+
},
258+
},
259+
},
260+
Config: &Config{},
252261
}
262+
rc.ExprEval = rc.NewExpressionEvaluator(ctx)
253263
executorOrder := make([]string, 0)
254264

255265
jim.On("steps").Return(tt.steps)

pkg/runner/step.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func runStepExecutor(step step, stage stepStage, executor common.Executor) commo
9090
return nil
9191
}
9292

93-
stepString := stepModel.String()
93+
stepString := rc.ExprEval.Interpolate(ctx, stepModel.String())
9494
if strings.Contains(stepString, "::add-mask::") {
9595
stepString = "add-mask command"
9696
}

pkg/runner/step_action_local_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ func TestStepActionLocalPost(t *testing.T) {
275275
Step: tt.stepModel,
276276
action: tt.actionModel,
277277
}
278+
sal.RunContext.ExprEval = sal.RunContext.NewExpressionEvaluator(ctx)
278279

279280
if tt.mocks.env {
280281
cm.On("UpdateFromImageEnv", &sal.env).Return(func(ctx context.Context) error { return nil })

pkg/runner/step_action_remote_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func TestStepActionRemote(t *testing.T) {
155155
readAction: sarm.readAction,
156156
runAction: sarm.runAction,
157157
}
158+
sar.RunContext.ExprEval = sar.RunContext.NewExpressionEvaluator(ctx)
158159

159160
suffixMatcher := func(suffix string) interface{} {
160161
return mock.MatchedBy(func(actionDir string) bool {
@@ -586,6 +587,7 @@ func TestStepActionRemotePost(t *testing.T) {
586587
Step: tt.stepModel,
587588
action: tt.actionModel,
588589
}
590+
sar.RunContext.ExprEval = sar.RunContext.NewExpressionEvaluator(ctx)
589591

590592
if tt.mocks.env {
591593
cm.On("UpdateFromImageEnv", &sar.env).Return(func(ctx context.Context) error { return nil })

pkg/runner/step_docker_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func TestStepDockerMain(t *testing.T) {
2525
ContainerNewContainer = origContainerNewContainer
2626
})()
2727

28+
ctx := context.Background()
29+
2830
sd := &stepDocker{
2931
RunContext: &RunContext{
3032
StepResults: map[string]*model.StepResult{},
@@ -51,8 +53,7 @@ func TestStepDockerMain(t *testing.T) {
5153
WorkingDirectory: "workdir",
5254
},
5355
}
54-
55-
ctx := context.Background()
56+
sd.RunContext.ExprEval = sd.RunContext.NewExpressionEvaluator(ctx)
5657

5758
cm.On("UpdateFromImageEnv", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
5859
return nil

0 commit comments

Comments
 (0)