1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

90 lines
1.8 KiB
Go
Raw Normal View History

2017-01-14 12:34:22 -02:00
package defaults
import (
"os"
"path"
"path/filepath"
"github.com/goreleaser/releaser/context"
)
var filePatterns = []string{"LICENCE*", "LICENSE*", "README*", "CHANGELOG*"}
// Pipe for brew deployment
type Pipe struct{}
// Name of the pipe
func (Pipe) Name() string {
return "Defaults"
}
// Run the pipe
2017-01-14 14:06:57 -02:00
func (Pipe) Run(ctx *context.Context) (err error) {
if ctx.Config.Build.Main == "" {
ctx.Config.Build.Main = "main.go"
2017-01-14 12:34:22 -02:00
}
2017-01-14 14:06:57 -02:00
if len(ctx.Config.Build.Oses) == 0 {
ctx.Config.Build.Oses = []string{"linux", "darwin"}
2017-01-14 12:34:22 -02:00
}
2017-01-14 14:06:57 -02:00
if len(ctx.Config.Build.Arches) == 0 {
ctx.Config.Build.Arches = []string{"amd64", "386"}
2017-01-14 12:34:22 -02:00
}
2017-01-14 14:06:57 -02:00
if ctx.Config.Build.Ldflags == "" {
ctx.Config.Build.Ldflags = "-s -w"
2017-01-14 12:34:22 -02:00
}
2017-01-14 14:06:57 -02:00
if ctx.Config.Archive.NameTemplate == "" {
ctx.Config.Archive.NameTemplate = "{{.BinaryName}}_{{.Os}}_{{.Arch}}"
2017-01-14 12:34:22 -02:00
}
2017-01-14 14:06:57 -02:00
if ctx.Config.Archive.Format == "" {
ctx.Config.Archive.Format = "tar.gz"
2017-01-14 12:34:22 -02:00
}
2017-01-14 14:06:57 -02:00
if len(ctx.Config.Archive.Replacements) == 0 {
ctx.Config.Archive.Replacements = map[string]string{
2017-01-14 12:34:22 -02:00
"darwin": "Darwin",
"linux": "Linux",
"freebsd": "FreeBSD",
"openbsd": "OpenBSD",
"netbsd": "NetBSD",
"windows": "Windows",
"386": "i386",
"amd64": "x86_64",
}
}
2017-01-14 14:06:57 -02:00
if len(ctx.Config.Files) != 0 {
2017-01-14 12:34:22 -02:00
return
}
2017-01-14 14:06:57 -02:00
ctx.Config.Files = []string{}
2017-01-14 12:34:22 -02:00
for _, pattern := range filePatterns {
matches, err := globPath(pattern)
if err != nil {
return err
}
2017-01-14 14:06:57 -02:00
ctx.Config.Files = append(ctx.Config.Files, matches...)
2017-01-14 12:34:22 -02:00
}
return
}
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
}