Inject version when building and report version to Gitea via log and header (#43)

close #42
1. Inject runner version when `make build`
After building, executing command line: `./act_runner -v` or `./act_runner --version`, the version of runner is printed.
![image](/attachments/e25efbd3-79b3-49a5-b93f-42646d42c707)

2. In `Actions` UI:
![image](/attachments/36c57470-2a1d-4796-9eb0-de3988ab88e1)

3. Set request header in http client interceptor.

Co-authored-by: sillyguodong <gedong_1994@163.com>
Reviewed-on: https://gitea.com/gitea/act_runner/pulls/43
Reviewed-by: delvh <dev.lh@web.de>
Reviewed-by: Jason Song <i@wolfogre.com>
Co-authored-by: sillyguodong <sillyguodong@noreply.gitea.io>
Co-committed-by: sillyguodong <sillyguodong@noreply.gitea.io>
This commit is contained in:
sillyguodong
2023-03-13 18:57:35 +08:00
committed by Jason Song
parent ebcf341de7
commit 0d71463662
9 changed files with 24 additions and 13 deletions

View File

@ -16,6 +16,7 @@ import (
// Runner runs the pipeline.
type Runner struct {
Machine string
Version string
ForgeInstance string
Environ map[string]string
Client client.Client
@ -30,7 +31,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, s.Machine)
return NewTask(s.ForgeInstance, task.Id, s.Client, env, s.platformPicker).Run(ctx, task, s.Machine, s.Version)
}
func (s *Runner) platformPicker(labels []string) string {

View File

@ -115,7 +115,7 @@ func getToken(task *runnerv1.Task) string {
return token
}
func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName string) (lastErr error) {
func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName, runnerVersion string) (lastErr error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
_, exist := globalTaskMap.Load(task.Id)
@ -144,7 +144,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName string)
}()
reporter.RunDaemon()
reporter.Logf("%s received task %v of job %v", runnerName, task.Id, task.Context.Fields["job"].GetStringValue())
reporter.Logf("%s(version:%s) received task %v of job %v", runnerName, runnerVersion, task.Id, task.Context.Fields["job"].GetStringValue())
workflowsPath, err := getWorkflowsPath(t.Input.repoDirectory)
if err != nil {