mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
commit
5165364640
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
dist
|
||||
releasr
|
||||
vendor
|
||||
releaser
|
||||
|
0
config/.test/1/LICENSE.md
Normal file
0
config/.test/1/LICENSE.md
Normal file
0
config/.test/1/README.md
Normal file
0
config/.test/1/README.md
Normal file
0
config/.test/2/LICENCE.md
Normal file
0
config/.test/2/LICENCE.md
Normal file
0
config/.test/2/README.md
Normal file
0
config/.test/2/README.md
Normal file
0
config/.test/3/LICENCE.txt
Normal file
0
config/.test/3/LICENCE.txt
Normal file
0
config/.test/3/README.txt
Normal file
0
config/.test/3/README.txt
Normal file
0
config/.test/4/LICENCE
Normal file
0
config/.test/4/LICENCE
Normal file
@ -3,13 +3,19 @@ package config
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/goreleaser/releaser/config/git"
|
||||
yaml "gopkg.in/yaml.v1"
|
||||
)
|
||||
|
||||
var emptyBrew = Homebrew{}
|
||||
var (
|
||||
emptyBrew = Homebrew{}
|
||||
filePatterns = []string{"LICENCE*", "LICENSE*", "README*"}
|
||||
)
|
||||
|
||||
// Homebrew contains the brew section
|
||||
type Homebrew struct {
|
||||
@ -66,9 +72,15 @@ func Load(file string) (config ProjectConfig, err error) {
|
||||
|
||||
func fix(config ProjectConfig) ProjectConfig {
|
||||
if len(config.Files) == 0 {
|
||||
config.Files = []string{
|
||||
"README.md",
|
||||
"LICENSE.md",
|
||||
config.Files = []string{}
|
||||
|
||||
for _, pattern := range filePatterns {
|
||||
matches, err := globPath(pattern)
|
||||
if err != nil {
|
||||
log.Fatalf("Error searching for %q: %v", pattern, err)
|
||||
}
|
||||
|
||||
config.Files = append(config.Files, matches...)
|
||||
}
|
||||
}
|
||||
if config.Token == "" {
|
||||
@ -86,6 +98,7 @@ func fix(config ProjectConfig) ProjectConfig {
|
||||
if len(config.Build.Arches) == 0 {
|
||||
config.Build.Arches = []string{"amd64", "386"}
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
@ -117,3 +130,26 @@ func contains(s string, ss []string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func globPath(p string) (m []string, err error) {
|
||||
var cwd string
|
||||
var dirs []string
|
||||
|
||||
if cwd, err = os.Getwd(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
fp := path.Join(cwd, p)
|
||||
|
||||
if dirs, err = filepath.Glob(fp); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Normalise to avoid nested dirs in tarball
|
||||
for _, dir := range dirs {
|
||||
_, f := filepath.Split(dir)
|
||||
m = append(m, f)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -9,11 +10,65 @@ import (
|
||||
func TestFixConfig(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
config := fix(ProjectConfig{})
|
||||
|
||||
assert.Equal("main.go", config.Build.Main)
|
||||
assert.Contains(config.Files, "README.md")
|
||||
assert.Contains(config.Files, "LICENSE.md")
|
||||
assert.Contains(config.Build.Oses, "darwin")
|
||||
assert.Contains(config.Build.Oses, "linux")
|
||||
assert.Contains(config.Build.Arches, "386")
|
||||
assert.Contains(config.Build.Arches, "amd64")
|
||||
}
|
||||
|
||||
func TestFixConfigMissingFiles(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
config := fix(ProjectConfig{})
|
||||
|
||||
assert.Equal([]string{}, config.Files)
|
||||
}
|
||||
|
||||
func TestFixConfigUSENMarkdown(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
cwd, _ := os.Getwd()
|
||||
os.Chdir("./.test/1")
|
||||
|
||||
config := fix(ProjectConfig{})
|
||||
assert.Equal([]string{"LICENSE.md", "README.md"}, config.Files)
|
||||
|
||||
os.Chdir(cwd)
|
||||
}
|
||||
|
||||
func TestFixConfigRealENMarkdown(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
cwd, _ := os.Getwd()
|
||||
os.Chdir("./.test/2")
|
||||
|
||||
config := fix(ProjectConfig{})
|
||||
assert.Equal([]string{"LICENCE.md", "README.md"}, config.Files)
|
||||
|
||||
os.Chdir(cwd)
|
||||
}
|
||||
|
||||
func TestFixConfigArbitratryENTXT(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
cwd, _ := os.Getwd()
|
||||
os.Chdir("./.test/3")
|
||||
|
||||
config := fix(ProjectConfig{})
|
||||
assert.Equal([]string{"LICENCE.txt", "README.txt"}, config.Files)
|
||||
|
||||
os.Chdir(cwd)
|
||||
}
|
||||
|
||||
func TestFixConfigArbitratryENNoSuffix(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
cwd, _ := os.Getwd()
|
||||
os.Chdir("./.test/4")
|
||||
|
||||
config := fix(ProjectConfig{})
|
||||
assert.Equal([]string{"LICENCE"}, config.Files)
|
||||
|
||||
os.Chdir(cwd)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user