From 8b63e6555be45234c4c2a69576ca2ddab705302c Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 21 Dec 2016 10:35:34 -0200 Subject: [PATCH] config wip --- config/config.go | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ goreleaser.yml | 4 +++ main.go | 15 ++++++++++ 3 files changed, 93 insertions(+) create mode 100644 config/config.go create mode 100644 goreleaser.yml create mode 100644 main.go diff --git a/config/config.go b/config/config.go new file mode 100644 index 000000000..b9d1c31e6 --- /dev/null +++ b/config/config.go @@ -0,0 +1,74 @@ +package config + +import ( + "io/ioutil" + "log" + "os" + "path/filepath" + + yaml "gopkg.in/yaml.v1" +) + +var emptyBrew = HomebrewDeploy{} + +type HomebrewDeploy struct { + Repo string + Token string +} + +type ProjectConfig struct { + Repo string + Main string + BinaryName string + FileList []string + Brew HomebrewDeploy + Token string +} + +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 + } + return config +} + +func contains(s string, ss []string) (ok bool) { + for _, sx := range ss { + if sx == s { + ok = true + break + } + } + return ok +} diff --git a/goreleaser.yml b/goreleaser.yml new file mode 100644 index 000000000..aab83508f --- /dev/null +++ b/goreleaser.yml @@ -0,0 +1,4 @@ +repo: goreleaser/releaser +binary_name: release +brew: + repo: goreleaser/homebrew diff --git a/main.go b/main.go new file mode 100644 index 000000000..4389cbfc2 --- /dev/null +++ b/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + + "github.com/goreleaser/releaser/config" +) + +func main() { + config, err := config.Load("goreleaser.yml") + if err != nil { + panic(err) + } + fmt.Println(config) +}