1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/defaults/defaults.go
Carlos Alexandro Becker ddec194c7e
wip ctx
2017-01-14 12:34:22 -02:00

90 lines
1.9 KiB
Go

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
func (Pipe) Run(context *context.Context) (err error) {
if context.Config.Build.Main == "" {
context.Config.Build.Main = "main.go"
}
if len(context.Config.Build.Oses) == 0 {
context.Config.Build.Oses = []string{"linux", "darwin"}
}
if len(context.Config.Build.Arches) == 0 {
context.Config.Build.Arches = []string{"amd64", "386"}
}
if context.Config.Build.Ldflags == "" {
context.Config.Build.Ldflags = "-s -w"
}
if context.Config.Archive.NameTemplate == "" {
context.Config.Archive.NameTemplate = "{{.BinaryName}}_{{.Os}}_{{.Arch}}"
}
if context.Config.Archive.Format == "" {
context.Config.Archive.Format = "tar.gz"
}
if len(context.Config.Archive.Replacements) == 0 {
context.Config.Archive.Replacements = map[string]string{
"darwin": "Darwin",
"linux": "Linux",
"freebsd": "FreeBSD",
"openbsd": "OpenBSD",
"netbsd": "NetBSD",
"windows": "Windows",
"386": "i386",
"amd64": "x86_64",
}
}
if len(context.Config.Files) != 0 {
return
}
context.Config.Files = []string{}
for _, pattern := range filePatterns {
matches, err := globPath(pattern)
if err != nil {
return err
}
context.Config.Files = append(context.Config.Files, matches...)
}
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
}