1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/config/config.go

87 lines
1.6 KiB
Go
Raw Normal View History

2016-12-21 14:35:34 +02:00
package config
import (
"io/ioutil"
"log"
"os"
"path/filepath"
yaml "gopkg.in/yaml.v1"
)
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) {
log.Println("Loading", file)
data, err := ioutil.ReadFile(file)
if err != nil {
return config, err
}
err = yaml.Unmarshal(data, &config)
return fix(config), err
}
func fix(config ProjectConfig) ProjectConfig {
if config.BinaryName == "" {
dir, _ := os.Getwd()
config.BinaryName = filepath.Base(dir)
}
if len(config.FileList) == 0 {
config.FileList = []string{
"README.md",
"LICENSE.md",
config.BinaryName,
}
} else {
if !contains(config.BinaryName, config.FileList) {
config.FileList = append(config.FileList, config.BinaryName)
}
}
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
}
func contains(s string, ss []string) (ok bool) {
for _, sx := range ss {
if sx == s {
ok = true
break
}
}
return ok
}