From f24e0721dcdc047eeda37a9422507cefa2dda5fe Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Mon, 6 Mar 2023 18:42:07 +0800 Subject: [PATCH] Add runner name to log (#37) User can get the name of the runner that executed the specified job. ![image](/attachments/61328f68-7223-4345-85c7-ac08781e81db) Co-authored-by: Zettat123 Reviewed-on: https://gitea.com/gitea/act_runner/pulls/37 Reviewed-by: Jason Song Reviewed-by: Lunny Xiao Co-authored-by: Zettat123 Co-committed-by: Zettat123 --- .gitignore | 6 +++++- config/config.go | 3 +++ runtime/runtime.go | 2 +- runtime/task.go | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 53d57e1..4e43895 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,8 @@ act_runner .env .runner coverage.txt -/gitea-vet \ No newline at end of file +/gitea-vet + +# MS VSCode +.vscode +__debug_bin diff --git a/config/config.go b/config/config.go index 4ac00fd..61d5e50 100644 --- a/config/config.go +++ b/config/config.go @@ -68,6 +68,9 @@ func FromEnviron() (Config, error) { if runner.UUID != "" { cfg.Runner.UUID = runner.UUID } + if runner.Name != "" { + cfg.Runner.Name = runner.Name + } if runner.Token != "" { cfg.Runner.Token = runner.Token } diff --git a/runtime/runtime.go b/runtime/runtime.go index 941946e..258c6c5 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -30,7 +30,7 @@ func (s *Runner) Run(ctx context.Context, task *runnerv1.Task) error { env[k] = v } env["ACTIONS_CACHE_URL"] = s.CacheHandler.ExternalURL() + "/" - return NewTask(s.ForgeInstance, task.Id, s.Client, env, s.platformPicker).Run(ctx, task) + return NewTask(s.ForgeInstance, task.Id, s.Client, env, s.platformPicker).Run(ctx, task, s.Machine) } func (s *Runner) platformPicker(labels []string) string { diff --git a/runtime/task.go b/runtime/task.go index 9fc9a64..d13b6df 100644 --- a/runtime/task.go +++ b/runtime/task.go @@ -115,7 +115,7 @@ func getToken(task *runnerv1.Task) string { return token } -func (t *Task) Run(ctx context.Context, task *runnerv1.Task) (lastErr error) { +func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName string) (lastErr error) { ctx, cancel := context.WithCancel(ctx) defer cancel() _, exist := globalTaskMap.Load(task.Id) @@ -143,7 +143,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) (lastErr error) { }() reporter.RunDaemon() - reporter.Logf("received task %v of job %v", task.Id, task.Context.Fields["job"].GetStringValue()) + reporter.Logf("%s received task %v of job %v", runnerName, task.Id, task.Context.Fields["job"].GetStringValue()) workflowsPath, err := getWorkflowsPath(t.Input.repoDirectory) if err != nil {