feat: pass current matrix information to job logger ()

For log processing of the JSON logs, we want to be able to know which
keys/values of the matrices were used.
This commit adds the current matrix map to the job logger.

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
This commit is contained in:
Björn Brauer 2022-09-27 17:49:22 +02:00 committed by GitHub
parent 97c083e902
commit 00acf68188
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 3 deletions

View file

@ -164,7 +164,7 @@ func TestAddmaskUsemask(t *testing.T) {
re := captureOutput(t, func() { re := captureOutput(t, func() {
ctx := context.Background() ctx := context.Background()
ctx = WithJobLogger(ctx, "0", "testjob", config, &rc.Masks) ctx = WithJobLogger(ctx, "0", "testjob", config, &rc.Masks, map[string]interface{}{})
handler := rc.commandHandler(ctx) handler := rc.commandHandler(ctx)
handler("::add-mask::secret\n") handler("::add-mask::secret\n")

View file

@ -58,7 +58,7 @@ func WithMasks(ctx context.Context, masks *[]string) context.Context {
} }
// WithJobLogger attaches a new logger to context that is aware of steps // WithJobLogger attaches a new logger to context that is aware of steps
func WithJobLogger(ctx context.Context, jobID string, jobName string, config *Config, masks *[]string) context.Context { func WithJobLogger(ctx context.Context, jobID string, jobName string, config *Config, masks *[]string, matrix map[string]interface{}) context.Context {
mux.Lock() mux.Lock()
defer mux.Unlock() defer mux.Unlock()
@ -86,6 +86,7 @@ func WithJobLogger(ctx context.Context, jobID string, jobName string, config *Co
"job": jobName, "job": jobName,
"jobID": jobID, "jobID": jobID,
"dryrun": common.Dryrun(ctx), "dryrun": common.Dryrun(ctx),
"matrix": matrix,
}).WithContext(ctx) }).WithContext(ctx)
return common.WithLogger(ctx, rtn) return common.WithLogger(ctx, rtn)

View file

@ -192,7 +192,7 @@ func (runner *runnerImpl) NewPlanExecutor(plan *model.Plan) common.Executor {
} }
return nil return nil
})(common.WithJobErrorContainer(WithJobLogger(ctx, rc.Run.JobID, jobName, rc.Config, &rc.Masks))) })(common.WithJobErrorContainer(WithJobLogger(ctx, rc.Run.JobID, jobName, rc.Config, &rc.Masks, matrix)))
}) })
} }
pipeline = append(pipeline, common.NewParallelExecutor(maxParallel, stageExecutor...)) pipeline = append(pipeline, common.NewParallelExecutor(maxParallel, stageExecutor...))