1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

config wip

This commit is contained in:
Carlos Alexandro Becker 2016-12-21 10:35:34 -02:00
commit 8b63e6555b
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
3 changed files with 93 additions and 0 deletions

74
config/config.go Normal file
View File

@ -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
}

4
goreleaser.yml Normal file
View File

@ -0,0 +1,4 @@
repo: goreleaser/releaser
binary_name: release
brew:
repo: goreleaser/homebrew

15
main.go Normal file
View File

@ -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)
}