diff --git a/internal/app/cmd/daemon.go b/internal/app/cmd/daemon.go index 0c31c42..b69cdd3 100644 --- a/internal/app/cmd/daemon.go +++ b/internal/app/cmd/daemon.go @@ -200,6 +200,8 @@ func runDaemon(ctx context.Context, daemArgs *daemonArgs, configFile *string) fu default: log.Infof("runner: %s, with version: %s, with labels: %v, declare successfully", resp.Msg.Runner.Name, resp.Msg.Runner.Version, resp.Msg.Runner.Labels) + // Merge any admin-added labels from the server + runner.MergeServerLabels(resp.Msg.Runner.Labels) } // Start periodic capabilities update goroutine diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index 34d4040..abc99c7 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -308,10 +308,31 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report. } // Declare sends the runner's labels and capabilities to the server. -func (r *Runner) Declare(ctx context.Context, labels []string, capabilitiesJSON string) (*connect.Response[runnerv1.DeclareResponse], error) { +func (r *Runner) Declare(ctx context.Context, declareLabels []string, capabilitiesJSON string) (*connect.Response[runnerv1.DeclareResponse], error) { return r.client.Declare(ctx, connect.NewRequest(&runnerv1.DeclareRequest{ Version: ver.Version(), - Labels: labels, + Labels: declareLabels, CapabilitiesJson: capabilitiesJSON, })) } + +// MergeServerLabels merges labels returned from the server (which may include admin-added labels) +// with the runner's existing labels. This allows admins to add labels via the Gitea UI. +func (r *Runner) MergeServerLabels(serverLabels []string) { + existing := make(map[string]bool) + for _, l := range r.labels { + existing[l.Name] = true + } + + for _, labelStr := range serverLabels { + label, err := labels.Parse(labelStr) + if err != nil { + log.Warnf("ignoring invalid server label %q: %v", labelStr, err) + continue + } + if !existing[label.Name] { + r.labels = append(r.labels, label) + log.Infof("merged server label: %s", labelStr) + } + } +}