1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-07-27 17:28:35 +00:00

feat: add forgejo_default_actions_url + forgejo_runtime_token

the context sent from the Forgejo instance is expected to have

gitea_default_actions_url
gitea_runtime_token

add support for

forgejo_default_actions_url
forgejo_runtime_token

as well so that future Forgejo versions can make the change.
This commit is contained in:
Earl Warren 2025-07-03 16:43:22 +02:00
parent 42cacd47c2
commit 8cb450ffe0
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 31 additions and 9 deletions

View file

@ -206,8 +206,12 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
taskContext := task.Context.Fields
defaultActionURL := client.BackwardCompatibleContext(task, "default_actions_url")
if defaultActionURL == "" {
return fmt.Errorf("task %v context does not contain a {forgejo,gitea}_default_actions_url key", task.Id)
}
log.Infof("task %v repo is %v %v %v", task.Id, taskContext["repository"].GetStringValue(),
taskContext["gitea_default_actions_url"].GetStringValue(),
defaultActionURL,
r.client.Address())
preset := &model.GithubContext{
@ -241,12 +245,12 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
runEnvs[id] = v
}
giteaRuntimeToken := taskContext["gitea_runtime_token"].GetStringValue()
if giteaRuntimeToken == "" {
runtimeToken := client.BackwardCompatibleContext(task, "runtime_token")
if runtimeToken == "" {
// use task token to action api token for previous Gitea Server Versions
giteaRuntimeToken = preset.Token
runtimeToken = preset.Token
}
runEnvs["ACTIONS_RUNTIME_TOKEN"] = giteaRuntimeToken
runEnvs["ACTIONS_RUNTIME_TOKEN"] = runtimeToken
// Register the run with the cacheproxy and modify the CACHE_URL
if r.cacheProxy != nil {
@ -303,7 +307,7 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
ContainerOptions: r.cfg.Container.Options,
ContainerDaemonSocket: r.cfg.Container.DockerHost,
Privileged: r.cfg.Container.Privileged,
DefaultActionInstance: taskContext["gitea_default_actions_url"].GetStringValue(),
DefaultActionInstance: defaultActionURL,
PlatformPicker: r.labels.PickPlatform,
Vars: task.Vars,
ValidVolumes: r.cfg.Container.ValidVolumes,

View file

@ -0,0 +1,18 @@
// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package client
import (
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
)
func BackwardCompatibleContext(task *runnerv1.Task, suffix string) string {
for _, prefix := range []string{"forgejo_", "gitea_"} {
value := task.Context.Fields[prefix+suffix]
if value != nil {
return value.GetStringValue()
}
}
return ""
}

View file

@ -43,12 +43,12 @@ type Reporter struct {
stopCommandEndToken string
}
func NewReporter(ctx context.Context, cancel context.CancelFunc, client client.Client, task *runnerv1.Task, reportInterval time.Duration) *Reporter {
func NewReporter(ctx context.Context, cancel context.CancelFunc, c client.Client, task *runnerv1.Task, reportInterval time.Duration) *Reporter {
var oldnew []string
if v := task.Context.Fields["token"].GetStringValue(); v != "" {
oldnew = append(oldnew, v, "***")
}
if v := task.Context.Fields["gitea_runtime_token"].GetStringValue(); v != "" {
if v := client.BackwardCompatibleContext(task, "runtime_token"); v != "" {
oldnew = append(oldnew, v, "***")
}
for _, v := range task.Secrets {
@ -58,7 +58,7 @@ func NewReporter(ctx context.Context, cancel context.CancelFunc, client client.C
rv := &Reporter{
ctx: ctx,
cancel: cancel,
client: client,
client: c,
oldnew: oldnew,
reportInterval: reportInterval,
logReplacer: strings.NewReplacer(oldnew...),