2016-12-21 14:35:34 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2016-12-29 03:40:59 +02:00
|
|
|
"errors"
|
2016-12-21 14:35:34 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
yaml "gopkg.in/yaml.v1"
|
2016-12-29 03:46:18 +02:00
|
|
|
"fmt"
|
2016-12-21 14:35:34 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var emptyBrew = HomebrewDeploy{}
|
|
|
|
|
|
|
|
type HomebrewDeploy struct {
|
|
|
|
Repo string
|
|
|
|
Token string
|
|
|
|
}
|
|
|
|
|
2016-12-21 15:37:31 +02:00
|
|
|
type BuildConfig struct {
|
|
|
|
Oses []string
|
|
|
|
Arches []string
|
|
|
|
}
|
|
|
|
|
2016-12-21 14:35:34 +02:00
|
|
|
type ProjectConfig struct {
|
|
|
|
Repo string
|
|
|
|
Main string
|
|
|
|
BinaryName string
|
|
|
|
FileList []string
|
|
|
|
Brew HomebrewDeploy
|
|
|
|
Token string
|
2016-12-21 15:37:31 +02:00
|
|
|
Build BuildConfig
|
2016-12-21 14:35:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func Load(file string) (config ProjectConfig, err error) {
|
|
|
|
data, err := ioutil.ReadFile(file)
|
|
|
|
if err != nil {
|
|
|
|
return config, err
|
|
|
|
}
|
|
|
|
err = yaml.Unmarshal(data, &config)
|
2016-12-29 03:46:18 +02:00
|
|
|
fmt.Println("a",config.BinaryName)
|
2016-12-29 03:35:45 +02:00
|
|
|
config = fix(config)
|
2016-12-29 03:46:18 +02:00
|
|
|
fmt.Println("b",config.BinaryName)
|
2016-12-29 03:35:45 +02:00
|
|
|
if config.BinaryName == "" {
|
2016-12-29 03:46:18 +02:00
|
|
|
return config, errors.New("missing binary_name")
|
2016-12-29 03:35:45 +02:00
|
|
|
}
|
|
|
|
if config.Repo == "" {
|
2016-12-29 03:46:18 +02:00
|
|
|
return config, errors.New("missing repo")
|
2016-12-29 03:35:45 +02:00
|
|
|
}
|
|
|
|
return config, err
|
2016-12-21 14:35:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func fix(config ProjectConfig) ProjectConfig {
|
|
|
|
if len(config.FileList) == 0 {
|
|
|
|
config.FileList = []string{
|
|
|
|
"README.md",
|
|
|
|
"LICENSE.md",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if config.Main == "" {
|
|
|
|
config.Main = "main.go"
|
|
|
|
}
|
|
|
|
if config.Token == "" {
|
|
|
|
config.Token = os.Getenv("GITHUB_TOKEN")
|
|
|
|
}
|
|
|
|
if config.Brew != emptyBrew && config.Brew.Token == "" {
|
|
|
|
config.Brew.Token = config.Token
|
|
|
|
}
|
2016-12-21 15:37:31 +02:00
|
|
|
if len(config.Build.Oses) == 0 {
|
|
|
|
config.Build.Oses = []string{"linux", "darwin"}
|
|
|
|
}
|
|
|
|
if len(config.Build.Arches) == 0 {
|
|
|
|
config.Build.Arches = []string{"amd64", "386"}
|
|
|
|
}
|
2016-12-21 14:35:34 +02:00
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
2016-12-21 18:42:23 +02:00
|
|
|
func contains(s string, ss []string) bool {
|
2016-12-21 14:35:34 +02:00
|
|
|
for _, sx := range ss {
|
|
|
|
if sx == s {
|
2016-12-21 18:42:23 +02:00
|
|
|
return true
|
2016-12-21 14:35:34 +02:00
|
|
|
}
|
|
|
|
}
|
2016-12-21 18:42:23 +02:00
|
|
|
return false
|
2016-12-21 14:35:34 +02:00
|
|
|
}
|