1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-04 03:11:55 +02:00
This commit is contained in:
Carlos Alexandro Becker 2017-01-06 12:53:48 -02:00
parent e45e47b953
commit 759bb2918e
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 27 additions and 22 deletions

View File

@ -34,6 +34,11 @@ type GitInfo struct {
Diff string
}
// ArchiveConfig
type ArchiveConfig struct {
Format string
}
// ProjectConfig includes all project configuration
type ProjectConfig struct {
Repo string
@ -43,10 +48,27 @@ type ProjectConfig struct {
Token string `yaml:"-"`
Build BuildConfig
Git GitInfo `yaml:"-"`
Archive ArchiveConfig
}
var defaults = ProjectConfig{
Token: os.Getenv("GITHUB_TOKEN"),
Build: BuildConfig{
Main: "main.go",
Oses: []string{"linux", "darwin"},
Arches: []string{"amd64", "386"},
},
Brew: Homebrew{
Token: os.Getenv("GITHUB_TOKEN"),
},
Archive: ArchiveConfig{
Format: "tar.gz",
},
}
// Load config file
func Load(file string) (config ProjectConfig, err error) {
func Load(file string) (ProjectConfig, error) {
var config = defaults
data, err := ioutil.ReadFile(file)
if err != nil {
return config, err
@ -54,7 +76,6 @@ func Load(file string) (config ProjectConfig, err error) {
if err := yaml.Unmarshal(data, &config); err != nil {
return config, err
}
config.fillBasicData()
if err := config.fillFiles(); err != nil {
return config, err
}
@ -90,24 +111,6 @@ func (config *ProjectConfig) fillFiles() (err error) {
return
}
func (config *ProjectConfig) fillBasicData() {
if config.Token == "" {
config.Token = os.Getenv("GITHUB_TOKEN")
}
if config.Brew.Repo != "" {
config.Brew.Token = config.Token
}
if config.Build.Main == "" {
config.Build.Main = "main.go"
}
if len(config.Build.Oses) == 0 {
config.Build.Oses = []string{"linux", "darwin"}
}
if len(config.Build.Arches) == 0 {
config.Build.Arches = []string{"amd64", "386"}
}
}
func (config *ProjectConfig) fillGitData() (err error) {
tag, err := git.CurrentTag()
if err != nil {

View File

@ -5,14 +5,16 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v1"
)
func TestFillBasicData(t *testing.T) {
assert := assert.New(t)
config := ProjectConfig{}
config.fillBasicData()
config := defaults
assert.NoError(yaml.Unmarshal([]byte{}, &config))
assert.Equal("main.go", config.Build.Main)
assert.Equal("tar.gz", config.Archive.Format)
assert.Contains(config.Build.Oses, "darwin")
assert.Contains(config.Build.Oses, "linux")
assert.Contains(config.Build.Arches, "386")