forgejo-runner

git clone git://git.lin.moe/forgejo-runner.git

 1// Copyright 2023 The Gitea Authors. All rights reserved.
 2// SPDX-License-Identifier: MIT
 3
 4package config
 5
 6import (
 7	"os"
 8	"strconv"
 9	"strings"
10
11	log "github.com/sirupsen/logrus"
12)
13
14// Deprecated: could be removed in the future. TODO: remove it when Gitea 1.20.0 is released.
15// Be compatible with old envs.
16func compatibleWithOldEnvs(fileUsed bool, cfg *Config) {
17	handleEnv := func(key string) (string, bool) {
18		if v, ok := os.LookupEnv(key); ok {
19			if fileUsed {
20				log.Warnf("env %s has been ignored because config file is used", key)
21				return "", false
22			}
23			log.Warnf("env %s will be deprecated, please use config file instead", key)
24			return v, true
25		}
26		return "", false
27	}
28
29	if v, ok := handleEnv("GITEA_DEBUG"); ok {
30		if b, _ := strconv.ParseBool(v); b {
31			cfg.Log.Level = "debug"
32		}
33	}
34	if v, ok := handleEnv("GITEA_TRACE"); ok {
35		if b, _ := strconv.ParseBool(v); b {
36			cfg.Log.Level = "trace"
37		}
38	}
39	if v, ok := handleEnv("GITEA_RUNNER_CAPACITY"); ok {
40		if i, _ := strconv.Atoi(v); i > 0 {
41			cfg.Runner.Capacity = i
42		}
43	}
44	if v, ok := handleEnv("GITEA_RUNNER_FILE"); ok {
45		cfg.Runner.File = v
46	}
47	if v, ok := handleEnv("GITEA_RUNNER_ENVIRON"); ok {
48		splits := strings.Split(v, ",")
49		if cfg.Runner.Envs == nil {
50			cfg.Runner.Envs = map[string]string{}
51		}
52		for _, split := range splits {
53			kv := strings.SplitN(split, ":", 2)
54			if len(kv) == 2 && kv[0] != "" {
55				cfg.Runner.Envs[kv[0]] = kv[1]
56			}
57		}
58	}
59	if v, ok := handleEnv("GITEA_RUNNER_ENV_FILE"); ok {
60		cfg.Runner.EnvFile = v
61	}
62}