mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2024-12-18 11:52:16 +03:00
7e7096e60b
Close #21. Refactor environment variables to configuration file (config.yaml) and registration file (.runner). The old environment variables are still supported, but warning logs will be printed. Like: ```text $ GITEA_DEBUG=true ./act_runner -c config.yaml daemon INFO[0000] Starting runner daemon WARN[0000] env GITEA_DEBUG has been ignored because config file is used $ GITEA_DEBUG=true ./act_runner daemon INFO[0000] Starting runner daemon WARN[0000] env GITEA_DEBUG will be deprecated, please use config file instead ``` Reviewed-on: https://gitea.com/gitea/act_runner/pulls/90 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
)
|
|
|
|
const registrationWarning = "This file is automatically generated by act-runner. Do not edit it manually unless you know what you are doing. Removing this file will cause act runner to re-register as a new runner."
|
|
|
|
// Registration is the registration information for a runner
|
|
type Registration struct {
|
|
Warning string `json:"WARNING"` // Warning message to display, it's always the registrationWarning constant
|
|
|
|
ID int64 `json:"id"`
|
|
UUID string `json:"uuid"`
|
|
Name string `json:"name"`
|
|
Token string `json:"token"`
|
|
Address string `json:"address"`
|
|
Labels []string `json:"labels"`
|
|
}
|
|
|
|
func LoadRegistration(file string) (*Registration, error) {
|
|
f, err := os.Open(file)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
|
|
var reg Registration
|
|
if err := json.NewDecoder(f).Decode(®); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
reg.Warning = ""
|
|
|
|
return ®, nil
|
|
}
|
|
|
|
func SaveRegistration(file string, reg *Registration) error {
|
|
f, err := os.Create(file)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
|
|
reg.Warning = registrationWarning
|
|
|
|
enc := json.NewEncoder(f)
|
|
enc.SetIndent("", " ")
|
|
return enc.Encode(reg)
|
|
}
|