diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index a372d98..4b0f76b 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -113,6 +113,17 @@ func (r *Runner) Run(ctx context.Context, task *runnerv1.Task) error { return nil } +// 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 { + giteaDefaultActionsURL := task.Context.Fields["gitea_default_actions_url"].GetStringValue() + if giteaDefaultActionsURL == "https://github.com" && r.cfg.Runner.GithubMirror != "" { + return r.cfg.Runner.GithubMirror + } + return giteaDefaultActionsURL +} + func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.Reporter) (err error) { defer func() { if r := recover(); r != nil { @@ -137,7 +148,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(), - taskContext["gitea_default_actions_url"].GetStringValue(), + r.getDefaultActionsURL(ctx, task), r.client.Address()) preset := &model.GithubContext{ @@ -211,7 +222,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: r.getDefaultActionsURL(ctx, task), PlatformPicker: r.labels.PickPlatform, Vars: task.Vars, ValidVolumes: r.cfg.Container.ValidVolumes, diff --git a/internal/pkg/config/config.example.yaml b/internal/pkg/config/config.example.yaml index 2e3c3fb..67b7db5 100644 --- a/internal/pkg/config/config.example.yaml +++ b/internal/pkg/config/config.example.yaml @@ -32,6 +32,11 @@ runner: fetch_timeout: 5s # The interval for fetching the job from the Gitea instance. fetch_interval: 2s + # The github_mirror of a runner is used to specify the mirror address of the github that pulls the action repository. + # It works when something like `uses: actions/checkout@v4` is used and DEFAULT_ACTIONS_URL is set to github, + # and github_mirror is not empty. In this case, + # it replaces https://github.com with the value here, which is useful for some special network environments. + github_mirror: '' # The labels of a runner are used to determine which jobs the runner can run, and how to run them. # Like: "macos-arm64:host" or "ubuntu-latest:docker://docker.gitea.com/runner-images:ubuntu-latest" # Find more images provided by Gitea at https://gitea.com/docker.gitea.com/runner-images . diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index afc34b9..17147f0 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -31,6 +31,7 @@ type Runner struct { FetchTimeout time.Duration `yaml:"fetch_timeout"` // FetchTimeout specifies the timeout duration for fetching resources. FetchInterval time.Duration `yaml:"fetch_interval"` // FetchInterval specifies the interval duration for fetching resources. Labels []string `yaml:"labels"` // Labels specify the labels of the runner. Labels are declared on each startup + GithubMirror string `yaml:"github_mirror"` // GithubMirror defines what mirrors should be used when using github } // Cache represents the configuration for caching.