Merge branch 'main' of gitea.com:gitea/act_runner into act-runner-actions-oss-act

This commit is contained in:
Christopher Homberger
2026-02-22 20:26:32 +01:00
14 changed files with 181 additions and 227 deletions

View File

@@ -4,7 +4,6 @@
package cmd
import (
"context"
"fmt"
"os"
"os/signal"
@@ -22,7 +21,7 @@ type cacheServerArgs struct {
Port uint16
}
func runCacheServer(ctx context.Context, configFile *string, cacheArgs *cacheServerArgs) func(cmd *cobra.Command, args []string) error {
func runCacheServer(configFile *string, cacheArgs *cacheServerArgs) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
cfg, err := config.LoadDefault(*configFile)
if err != nil {

View File

@@ -72,7 +72,7 @@ func Execute(ctx context.Context) {
Use: "cache-server",
Short: "Start a cache server for the cache action",
Args: cobra.MaximumNArgs(0),
RunE: runCacheServer(ctx, &configFile, &cacheArgs),
RunE: runCacheServer(&configFile, &cacheArgs),
}
cacheCmd.Flags().StringVarP(&cacheArgs.Dir, "dir", "d", "", "Cache directory")
cacheCmd.Flags().StringVarP(&cacheArgs.Host, "host", "s", "", "Host of the cache server")

View File

@@ -262,5 +262,5 @@ func getDockerSocketPath(configDockerHost string) (string, error) {
}
}
return "", fmt.Errorf("daemon Docker Engine socket not found and docker_host config was invalid")
return "", errors.New("daemon Docker Engine socket not found and docker_host config was invalid")
}

View File

@@ -6,7 +6,9 @@ package cmd
import (
"context"
"errors"
"fmt"
"maps"
"os"
"path/filepath"
"strconv"
@@ -78,7 +80,7 @@ func (i *executeArgs) LoadSecrets() map[string]string {
for _, secretPair := range i.secrets {
secretPairParts := strings.SplitN(secretPair, "=", 2)
secretPairParts[0] = strings.ToUpper(secretPairParts[0])
if strings.ToUpper(s[secretPairParts[0]]) == secretPairParts[0] {
if strings.EqualFold(s[secretPairParts[0]], secretPairParts[0]) {
log.Errorf("Secret %s is already defined (secrets are case insensitive)", secretPairParts[0])
}
if len(secretPairParts) == 2 {
@@ -105,9 +107,7 @@ func readEnvs(path string, envs map[string]string) bool {
if err != nil {
log.Fatalf("Error loading from %s: %v", path, err)
}
for k, v := range env {
envs[k] = v
}
maps.Copy(envs, env)
return true
}
return false
@@ -167,7 +167,7 @@ func (i *executeArgs) resolve(path string) string {
return path
}
func printList(plan *model.Plan) error {
func printList(plan *model.Plan) {
type lineInfoDef struct {
jobID string
jobName string
@@ -262,10 +262,9 @@ func printList(plan *model.Plan) error {
if duplicateJobIDs {
fmt.Print("\nDetected multiple jobs with the same job name, use `-W` to specify the path to the specific workflow.\n")
}
return nil
}
func runExecList(ctx context.Context, planner model.WorkflowPlanner, execArgs *executeArgs) error {
func runExecList(planner model.WorkflowPlanner, execArgs *executeArgs) error {
// plan with filtered jobs - to be used for filtering only
var filterPlan *model.Plan
@@ -307,7 +306,7 @@ func runExecList(ctx context.Context, planner model.WorkflowPlanner, execArgs *e
}
}
_ = printList(filterPlan)
printList(filterPlan)
return nil
}
@@ -325,7 +324,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
}
if execArgs.runList {
return runExecList(ctx, planner, execArgs)
return runExecList(planner, execArgs)
}
// plan with triggered jobs
@@ -385,7 +384,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
if len(execArgs.artifactServerAddr) == 0 {
ip := common.GetOutboundIP()
if ip == nil {
return fmt.Errorf("unable to determine outbound IP address")
return errors.New("unable to determine outbound IP address")
}
execArgs.artifactServerAddr = ip.String()
}
@@ -430,7 +429,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
// PresetGitHubContext: preset,
// EventJSON: string(eventJSON),
// TODO GITEA
// ContainerNamePrefix: fmt.Sprintf("GITEA-ACTIONS-TASK-%s", eventName),
// ContainerNamePrefix: "GITEA-ACTIONS-TASK-" + eventName,
// ContainerMaxLifetime: maxLifetime,
ContainerNetworkMode: container.NetworkMode(execArgs.network),
// TODO GITEA

View File

@@ -6,6 +6,7 @@ package cmd
import (
"bufio"
"context"
"errors"
"fmt"
"os"
"os/signal"
@@ -107,10 +108,10 @@ type registerInputs struct {
func (r *registerInputs) validate() error {
if r.InstanceAddr == "" {
return fmt.Errorf("instance address is empty")
return errors.New("instance address is empty")
}
if r.Token == "" {
return fmt.Errorf("token is empty")
return errors.New("token is empty")
}
if len(r.Labels) > 0 {
return validateLabels(r.Labels)

View File

@@ -102,7 +102,7 @@ func (p *Poller) Shutdown(ctx context.Context) error {
p.shutdownJobs()
// wait for running jobs to report their status to Gitea
_, _ = <-p.done
<-p.done
return ctx.Err()
}

View File

@@ -7,6 +7,7 @@ import (
"context"
"encoding/json"
"fmt"
"maps"
"path/filepath"
"strings"
"sync"
@@ -48,9 +49,7 @@ func NewRunner(cfg *config.Config, reg *config.Registration, cli client.Client)
}
}
envs := make(map[string]string, len(cfg.Runner.Envs))
for k, v := range cfg.Runner.Envs {
envs[k] = v
}
maps.Copy(envs, cfg.Runner.Envs)
if cfg.Cache.Enabled == nil || *cfg.Cache.Enabled {
if cfg.Cache.ExternalServer != "" {
envs["ACTIONS_CACHE_URL"] = cfg.Cache.ExternalServer
@@ -115,7 +114,7 @@ func (r *Runner) Run(ctx context.Context, task *runnerv1.Task) error {
// getDefaultActionsURL
// when DEFAULT_ACTIONS_URL == "https://github.com" and GithubMirror is not blank,
// it should be set to GithubMirror first.
func (r *Runner) getDefaultActionsURL(ctx context.Context, task *runnerv1.Task) string {
func (r *Runner) getDefaultActionsURL(task *runnerv1.Task) string {
giteaDefaultActionsURL := task.Context.Fields["gitea_default_actions_url"].GetStringValue()
if giteaDefaultActionsURL == "https://github.com" && r.cfg.Runner.GithubMirror != "" {
return r.cfg.Runner.GithubMirror
@@ -155,7 +154,7 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
taskContext := task.Context.Fields
log.Infof("task %v repo is %v %v %v", task.Id, taskContext["repository"].GetStringValue(),
r.getDefaultActionsURL(ctx, task),
r.getDefaultActionsURL(task),
r.client.Address())
preset := &model.GithubContext{
@@ -181,8 +180,8 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
preset.Token = t
}
if actionsIdTokenRequestUrl := taskContext["actions_id_token_request_url"].GetStringValue(); actionsIdTokenRequestUrl != "" {
r.envs["ACTIONS_ID_TOKEN_REQUEST_URL"] = actionsIdTokenRequestUrl
if actionsIDTokenRequestURL := taskContext["actions_id_token_request_url"].GetStringValue(); actionsIDTokenRequestURL != "" {
r.envs["ACTIONS_ID_TOKEN_REQUEST_URL"] = actionsIDTokenRequestURL
r.envs["ACTIONS_ID_TOKEN_REQUEST_TOKEN"] = taskContext["actions_id_token_request_token"].GetStringValue()
task.Secrets["ACTIONS_ID_TOKEN_REQUEST_TOKEN"] = r.envs["ACTIONS_ID_TOKEN_REQUEST_TOKEN"]
}
@@ -241,7 +240,7 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
"dummy": "-self-hosted",
},
// TODO GITEA
// DefaultActionInstance: r.getDefaultActionsURL(ctx, task),
// DefaultActionInstance: r.getDefaultActionsURL(task),
// PlatformPicker: r.labels.PickPlatform,
Vars: task.Vars,
// TODO GITEA

View File

@@ -307,7 +307,7 @@ func Test_yamlV4NodeRoundTrip(t *testing.T) {
t.Run("unmarshal and re-marshal workflow", func(t *testing.T) {
input := []byte("name: test\non: push\njobs:\n build:\n runs-on: ubuntu-latest\n steps:\n - run: echo hello\n")
var wf map[string]interface{}
var wf map[string]any
err := yaml.Unmarshal(input, &wf)
require.NoError(t, err)
assert.Equal(t, wf["name"], "test")
@@ -315,7 +315,7 @@ func Test_yamlV4NodeRoundTrip(t *testing.T) {
out, err := yaml.Marshal(wf)
require.NoError(t, err)
var wf2 map[string]interface{}
var wf2 map[string]any
err = yaml.Unmarshal(out, &wf2)
require.NoError(t, err)
assert.Equal(t, wf2["name"], "test")