From fab9714f9a8a76c3435e38ee59df9e284fc03146 Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 19 May 2026 16:49:15 +0000 Subject: [PATCH] Remove stale Gitea 1.20 compatibility shims (#978) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The runner already enforces Gitea v1.21+ (see the `connect.CodeUnimplemented` check in `daemon.go`), so several shims kept for v1.20 compatibility have been dead since 2023: - `compatibleWithOldEnvs` — the `GITEA_DEBUG`, `GITEA_TRACE`, `GITEA_RUNNER_CAPACITY`, `GITEA_RUNNER_FILE`, `GITEA_RUNNER_ENVIRON`, `GITEA_RUNNER_ENV_FILE` env vars (superseded by the config file) - `VersionHeader` (`x-runner-version`) and the `version` param of `client.New` - `AgentLabels` field in `RegisterRequest` (replaced by `Labels`) Also replaces a verbose `strings.TrimRightFunc` closure with `strings.TrimRight(s, "\r\n")` in the log row parser. --- This PR was written with the help of Claude Opus 4.7 --------- Co-authored-by: Nicolas Reviewed-on: https://gitea.com/gitea/runner/pulls/978 Reviewed-by: Nicolas Co-authored-by: silverwind Co-committed-by: silverwind --- internal/app/cmd/daemon.go | 1 - internal/app/cmd/register.go | 12 +++--- internal/pkg/client/header.go | 2 - internal/pkg/client/http.go | 6 +-- internal/pkg/config/config.go | 1 - internal/pkg/config/deprecated.go | 62 ------------------------------- internal/pkg/report/reporter.go | 2 +- 7 files changed, 7 insertions(+), 79 deletions(-) delete mode 100644 internal/pkg/config/deprecated.go diff --git a/internal/app/cmd/daemon.go b/internal/app/cmd/daemon.go index aaac6401..247d77f0 100644 --- a/internal/app/cmd/daemon.go +++ b/internal/app/cmd/daemon.go @@ -132,7 +132,6 @@ func runDaemon(ctx context.Context, daemArgs *daemonArgs, configFile *string) fu cfg.Runner.Insecure, reg.UUID, reg.Token, - ver.Version(), ) runner := run.NewRunner(cfg, reg, cli) diff --git a/internal/app/cmd/register.go b/internal/app/cmd/register.go index ea4c0ee9..c0a1950e 100644 --- a/internal/app/cmd/register.go +++ b/internal/app/cmd/register.go @@ -325,7 +325,6 @@ func doRegister(ctx context.Context, cfg *config.Config, inputs *registerInputs) cfg.Runner.Insecure, "", "", - ver.Version(), ) for { @@ -366,12 +365,11 @@ func doRegister(ctx context.Context, cfg *config.Config, inputs *registerInputs) } // register new runner. resp, err := cli.Register(ctx, connect.NewRequest(&runnerv1.RegisterRequest{ - Name: reg.Name, - Token: reg.Token, - Version: ver.Version(), - AgentLabels: ls, // Could be removed after Gitea 1.20 - Labels: ls, - Ephemeral: reg.Ephemeral, + Name: reg.Name, + Token: reg.Token, + Version: ver.Version(), + Labels: ls, + Ephemeral: reg.Ephemeral, })) if err != nil { log.WithError(err).Error("poller: cannot register new runner") diff --git a/internal/pkg/client/header.go b/internal/pkg/client/header.go index 24844fa2..ab29a558 100644 --- a/internal/pkg/client/header.go +++ b/internal/pkg/client/header.go @@ -6,6 +6,4 @@ package client const ( UUIDHeader = "x-runner-uuid" TokenHeader = "x-runner-token" - // Deprecated: could be removed after Gitea 1.20 released - VersionHeader = "x-runner-version" ) diff --git a/internal/pkg/client/http.go b/internal/pkg/client/http.go index d976d12c..0b9a0955 100644 --- a/internal/pkg/client/http.go +++ b/internal/pkg/client/http.go @@ -31,7 +31,7 @@ func getHTTPClient(endpoint string, insecure bool) *http.Client { } // New returns a new runner client. -func New(endpoint string, insecure bool, uuid, token, version string, opts ...connect.ClientOption) *HTTPClient { +func New(endpoint string, insecure bool, uuid, token string, opts ...connect.ClientOption) *HTTPClient { baseURL := strings.TrimRight(endpoint, "/") + "/api/actions" opts = append(opts, connect.WithInterceptors(connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc { @@ -42,10 +42,6 @@ func New(endpoint string, insecure bool, uuid, token, version string, opts ...co if token != "" { req.Header().Set(TokenHeader, token) } - // TODO: version will be removed from request header after Gitea 1.20 released. - if version != "" { - req.Header().Set(VersionHeader, version) - } return next(ctx, req) } }))) diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index 4f5b11d5..efad73de 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -109,7 +109,6 @@ func LoadDefault(file string) (*Config, error) { return nil, fmt.Errorf("parse config file %q for defaults metadata: %w", file, err) } } - compatibleWithOldEnvs(file != "", cfg) if cfg.Runner.EnvFile != "" { if stat, err := os.Stat(cfg.Runner.EnvFile); err == nil && !stat.IsDir() { diff --git a/internal/pkg/config/deprecated.go b/internal/pkg/config/deprecated.go deleted file mode 100644 index b5051aa0..00000000 --- a/internal/pkg/config/deprecated.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2023 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -package config - -import ( - "os" - "strconv" - "strings" - - log "github.com/sirupsen/logrus" -) - -// Deprecated: could be removed in the future. TODO: remove it when Gitea 1.20.0 is released. -// Be compatible with old envs. -func compatibleWithOldEnvs(fileUsed bool, cfg *Config) { - handleEnv := func(key string) (string, bool) { - if v, ok := os.LookupEnv(key); ok { - if fileUsed { - log.Warnf("env %s has been ignored because config file is used", key) - return "", false - } - log.Warnf("env %s will be deprecated, please use config file instead", key) - return v, true - } - return "", false - } - - if v, ok := handleEnv("GITEA_DEBUG"); ok { - if b, _ := strconv.ParseBool(v); b { - cfg.Log.Level = "debug" - } - } - if v, ok := handleEnv("GITEA_TRACE"); ok { - if b, _ := strconv.ParseBool(v); b { - cfg.Log.Level = "trace" - } - } - if v, ok := handleEnv("GITEA_RUNNER_CAPACITY"); ok { - if i, _ := strconv.Atoi(v); i > 0 { - cfg.Runner.Capacity = i - } - } - if v, ok := handleEnv("GITEA_RUNNER_FILE"); ok { - cfg.Runner.File = v - } - if v, ok := handleEnv("GITEA_RUNNER_ENVIRON"); ok { - splits := strings.Split(v, ",") - if cfg.Runner.Envs == nil { - cfg.Runner.Envs = map[string]string{} - } - for _, split := range splits { - kv := strings.SplitN(split, ":", 2) - if len(kv) == 2 && kv[0] != "" { - cfg.Runner.Envs[kv[0]] = kv[1] - } - } - } - if v, ok := handleEnv("GITEA_RUNNER_ENV_FILE"); ok { - cfg.Runner.EnvFile = v - } -} diff --git a/internal/pkg/report/reporter.go b/internal/pkg/report/reporter.go index 49e839f2..d86f03a6 100644 --- a/internal/pkg/report/reporter.go +++ b/internal/pkg/report/reporter.go @@ -639,7 +639,7 @@ func (r *Reporter) handleCommand(originalContent, command, value string) *string } func (r *Reporter) parseLogRow(entry *log.Entry) *runnerv1.LogRow { - content := strings.TrimRightFunc(entry.Message, func(r rune) bool { return r == '\r' || r == '\n' }) + content := strings.TrimRight(entry.Message, "\r\n") matches := cmdRegex.FindStringSubmatch(content) if matches != nil {