-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
50 lines (43 loc) · 1.17 KB
/
config.go
File metadata and controls
50 lines (43 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package githubactionsrunnerlauncher
import (
"fmt"
"io/ioutil"
"github.com/k0kubun/pp"
"gopkg.in/yaml.v2"
log "github.com/sirupsen/logrus"
)
// RunnerEnvironment ...
type RunnerEnvironment struct {
RepoURL string `yaml:"REPO_URL"`
AccessToken string `yaml:"ACCESS_TOKEN"`
RunnerName string `yaml:"RUNNER_NAME"`
RunnerToken string `yaml:"RUNNER_TOKEN"`
RunnerWorkdir string `yaml:"RUNNER_WORKDIR"`
IsOrgRunner string `yaml:"ORG_RUNNER"`
OrgName string `yaml:"ORG_NAME"`
Labels string `yaml:"LABELS"`
}
// RunnerConfig ...
type RunnerConfig struct {
Environment RunnerEnvironment `yaml:"environment"`
}
// LaunchConfig ...
type LaunchConfig struct {
Services map[string]RunnerConfig `yaml:"services"`
}
// ParseConfigFile ...
func (l *Launcher) ParseConfigFile(file string) error {
data, err := ioutil.ReadFile(file)
if err != nil {
return fmt.Errorf("Failed to read config file %v: %v", file, err)
}
if err := yaml.Unmarshal(data, &l.Config); err != nil {
return fmt.Errorf("Failed to parse config: %v", err)
}
if log.IsLevelEnabled(log.DebugLevel) {
pp.Print(l.Config)
}
l.configPath = file
log.Info("Parsed config")
return nil
}