From e6630e2e369f41fc9d9f9e570610611da18dda1d Mon Sep 17 00:00:00 2001 From: Christopher Homberger Date: Thu, 8 Feb 2024 02:43:39 +0000 Subject: [PATCH] Use artifacts v4 jwt if available (#471) Needs https://github.com/go-gitea/gitea/pull/28885 to provide jwt if sent by server Could fix #459, but that has not been verified. Co-authored-by: Lunny Xiao Reviewed-on: https://gitea.com/gitea/act_runner/pulls/471 Reviewed-by: delvh Reviewed-by: Lunny Xiao Co-authored-by: Christopher Homberger Co-committed-by: Christopher Homberger --- internal/app/run/runner.go | 8 ++++++-- internal/pkg/report/reporter.go | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index 37d68e2..426ad5e 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -162,8 +162,12 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report. preset.Token = t } - // use task token to action api token - r.envs["ACTIONS_RUNTIME_TOKEN"] = preset.Token + giteaRuntimeToken := taskContext["gitea_runtime_token"].GetStringValue() + if giteaRuntimeToken == "" { + // use task token to action api token for previous Gitea Server Versions + giteaRuntimeToken = preset.Token + } + r.envs["ACTIONS_RUNTIME_TOKEN"] = giteaRuntimeToken eventJSON, err := json.Marshal(preset.Event) if err != nil { diff --git a/internal/pkg/report/reporter.go b/internal/pkg/report/reporter.go index 0a3ed79..7a8658e 100644 --- a/internal/pkg/report/reporter.go +++ b/internal/pkg/report/reporter.go @@ -47,6 +47,9 @@ func NewReporter(ctx context.Context, cancel context.CancelFunc, client client.C if v := task.Context.Fields["token"].GetStringValue(); v != "" { oldnew = append(oldnew, v, "***") } + if v := task.Context.Fields["gitea_runtime_token"].GetStringValue(); v != "" { + oldnew = append(oldnew, v, "***") + } for _, v := range task.Secrets { oldnew = append(oldnew, v, "***") }