From be2df361ef19bbf979f826da999169dc2b0ac298 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 2 Apr 2024 07:39:40 +0000 Subject: [PATCH] Ensure declare to use new labels (#530) Ensure "declare" is supported, to use new labels, see https://gitea.com/gitea/act_runner/pulls/529 Reviewed-on: https://gitea.com/gitea/act_runner/pulls/530 Reviewed-by: Lunny Xiao --- internal/app/cmd/daemon.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/app/cmd/daemon.go b/internal/app/cmd/daemon.go index 3695aa4..5dccc1c 100644 --- a/internal/app/cmd/daemon.go +++ b/internal/app/cmd/daemon.go @@ -10,6 +10,7 @@ import ( "path" "path/filepath" "runtime" + "slices" "strconv" "strings" @@ -88,6 +89,14 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command, } } + if !slices.Equal(reg.Labels, ls.ToStrings()) { + reg.Labels = ls.ToStrings() + if err := config.SaveRegistration(cfg.Runner.File, reg); err != nil { + return fmt.Errorf("failed to save runner config: %w", err) + } + log.Infof("labels updated to: %v", reg.Labels) + } + cli := client.New( reg.Address, cfg.Runner.Insecure, @@ -97,22 +106,18 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command, ) runner := run.NewRunner(cfg, reg, cli) + // declare the labels of the runner before fetching tasks resp, err := runner.Declare(ctx, ls.Names()) if err != nil && connect.CodeOf(err) == connect.CodeUnimplemented { - // Gitea instance is older version. skip declare step. - log.Warn("Because the Gitea instance is an old version, skip declare labels and version.") + log.Errorf("Your Gitea version is too old to support runner declare, please upgrade to v1.21 or later") + return err } else if err != nil { log.WithError(err).Error("fail to invoke Declare") return err } else { log.Infof("runner: %s, with version: %s, with labels: %v, declare successfully", resp.Msg.Runner.Name, resp.Msg.Runner.Version, resp.Msg.Runner.Labels) - // if declare successfully, override the labels in the.runner file with valid labels in the config file (if specified) - reg.Labels = ls.ToStrings() - if err := config.SaveRegistration(cfg.Runner.File, reg); err != nil { - return fmt.Errorf("failed to save runner config: %w", err) - } } poller := poll.New(cfg, cli, runner)