2017-04-14 20:39:32 +02:00
|
|
|
// Package defaults implements the Pipe interface providing default values
|
|
|
|
// for missing configuration.
|
2017-01-14 16:34:22 +02:00
|
|
|
package defaults
|
|
|
|
|
|
|
|
import (
|
2017-05-01 14:59:18 +02:00
|
|
|
"fmt"
|
2017-06-28 00:20:08 +02:00
|
|
|
"strings"
|
2017-01-14 16:34:22 +02:00
|
|
|
|
2017-06-28 00:20:08 +02:00
|
|
|
"github.com/apex/log"
|
|
|
|
"github.com/goreleaser/goreleaser/config"
|
2017-01-15 00:01:32 +02:00
|
|
|
"github.com/goreleaser/goreleaser/context"
|
2017-01-14 16:34:22 +02:00
|
|
|
)
|
|
|
|
|
2017-04-24 19:27:21 +02:00
|
|
|
// NameTemplate default name_template for the archive.
|
2017-05-20 04:37:51 +02:00
|
|
|
const NameTemplate = "{{ .Binary }}_{{.Version}}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
|
2017-04-24 19:27:21 +02:00
|
|
|
|
2017-04-29 12:49:22 +02:00
|
|
|
// SnapshotNameTemplate represents the default format for snapshot release names.
|
2017-05-01 14:59:18 +02:00
|
|
|
const SnapshotNameTemplate = "SNAPSHOT-{{ .Commit }}"
|
2017-04-29 12:49:22 +02:00
|
|
|
|
2017-01-14 16:34:22 +02:00
|
|
|
// Pipe for brew deployment
|
|
|
|
type Pipe struct{}
|
|
|
|
|
2017-01-14 20:41:32 +02:00
|
|
|
// Description of the pipe
|
2017-01-14 19:14:35 +02:00
|
|
|
func (Pipe) Description() string {
|
2017-01-19 11:04:41 +02:00
|
|
|
return "Setting defaults"
|
2017-01-14 16:34:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run the pipe
|
2017-01-14 20:41:32 +02:00
|
|
|
func (Pipe) Run(ctx *context.Context) error {
|
2017-05-01 14:59:18 +02:00
|
|
|
ctx.Config.Dist = "dist"
|
2017-04-29 12:49:22 +02:00
|
|
|
if ctx.Config.Snapshot.NameTemplate == "" {
|
|
|
|
ctx.Config.Snapshot.NameTemplate = SnapshotNameTemplate
|
|
|
|
}
|
2017-05-01 14:59:18 +02:00
|
|
|
if err := setReleaseDefaults(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-28 00:20:08 +02:00
|
|
|
if ctx.Config.Name == "" {
|
|
|
|
ctx.Config.Name = ctx.Config.Release.GitHub.Name
|
|
|
|
}
|
2017-05-01 14:59:18 +02:00
|
|
|
setBuildDefaults(ctx)
|
|
|
|
if ctx.Config.Brew.Install == "" {
|
2017-06-28 00:20:08 +02:00
|
|
|
var installs []string
|
|
|
|
for _, build := range ctx.Config.Builds {
|
2017-07-02 03:06:40 +02:00
|
|
|
if !isBrewBuild(build) {
|
|
|
|
continue
|
|
|
|
}
|
2017-06-28 00:20:08 +02:00
|
|
|
installs = append(
|
|
|
|
installs,
|
|
|
|
fmt.Sprintf(`bin.install "%s"`, build.Binary),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
ctx.Config.Brew.Install = strings.Join(installs, "\n")
|
2017-01-14 20:12:20 +02:00
|
|
|
}
|
2017-06-28 00:20:08 +02:00
|
|
|
err := setArchiveDefaults(ctx)
|
|
|
|
log.WithField("config", ctx.Config).Debug("defaults set")
|
|
|
|
return err
|
2017-05-01 14:59:18 +02:00
|
|
|
}
|
|
|
|
|
2017-07-02 03:06:40 +02:00
|
|
|
func isBrewBuild(build config.Build) bool {
|
|
|
|
for _, ignore := range build.Ignore {
|
|
|
|
if ignore.Goos == "darwin" && ignore.Goarch == "amd64" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return contains(build.Goos, "darwin") && contains(build.Goarch, "amd64")
|
|
|
|
}
|
|
|
|
|
|
|
|
func contains(ss []string, s string) bool {
|
|
|
|
for _, zs := range ss {
|
|
|
|
if zs == s {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-05-01 14:59:18 +02:00
|
|
|
func setReleaseDefaults(ctx *context.Context) error {
|
|
|
|
if ctx.Config.Release.GitHub.Name != "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
repo, err := remoteRepo()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed reading repo from git: %v", err.Error())
|
|
|
|
}
|
|
|
|
ctx.Config.Release.GitHub = repo
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func setBuildDefaults(ctx *context.Context) {
|
2017-07-02 02:13:02 +02:00
|
|
|
for i, build := range ctx.Config.Builds {
|
|
|
|
ctx.Config.Builds[i] = buildWithDefaults(ctx, build)
|
|
|
|
}
|
|
|
|
if len(ctx.Config.Builds) == 0 {
|
|
|
|
ctx.Config.Builds = []config.Build{
|
2017-07-02 02:27:30 +02:00
|
|
|
buildWithDefaults(ctx, ctx.Config.SingleBuild),
|
2017-06-28 01:06:45 +02:00
|
|
|
}
|
2017-01-14 16:34:22 +02:00
|
|
|
}
|
2017-07-02 02:13:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func buildWithDefaults(ctx *context.Context, build config.Build) config.Build {
|
|
|
|
if build.Binary == "" {
|
|
|
|
build.Binary = ctx.Config.Release.GitHub.Name
|
|
|
|
}
|
|
|
|
if build.Main == "" {
|
|
|
|
build.Main = "."
|
|
|
|
}
|
|
|
|
if len(build.Goos) == 0 {
|
|
|
|
build.Goos = []string{"linux", "darwin"}
|
|
|
|
}
|
|
|
|
if len(build.Goarch) == 0 {
|
|
|
|
build.Goarch = []string{"amd64", "386"}
|
|
|
|
}
|
|
|
|
if len(build.Goarm) == 0 {
|
|
|
|
build.Goarm = []string{"6"}
|
|
|
|
}
|
|
|
|
if build.Ldflags == "" {
|
|
|
|
build.Ldflags = "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}"
|
|
|
|
}
|
|
|
|
return build
|
2017-05-01 14:59:18 +02:00
|
|
|
}
|
2017-01-14 23:47:15 +02:00
|
|
|
|
2017-05-01 14:59:18 +02:00
|
|
|
func setArchiveDefaults(ctx *context.Context) error {
|
2017-01-14 18:06:57 +02:00
|
|
|
if ctx.Config.Archive.NameTemplate == "" {
|
2017-04-24 19:27:21 +02:00
|
|
|
ctx.Config.Archive.NameTemplate = NameTemplate
|
2017-01-14 16:34:22 +02:00
|
|
|
}
|
2017-01-14 18:06:57 +02:00
|
|
|
if ctx.Config.Archive.Format == "" {
|
|
|
|
ctx.Config.Archive.Format = "tar.gz"
|
2017-01-14 16:34:22 +02:00
|
|
|
}
|
2017-01-14 23:47:15 +02:00
|
|
|
if len(ctx.Config.Archive.Files) == 0 {
|
2017-05-11 05:05:51 +02:00
|
|
|
ctx.Config.Archive.Files = []string{
|
|
|
|
"licence*",
|
|
|
|
"LICENCE*",
|
|
|
|
"license*",
|
|
|
|
"LICENSE*",
|
|
|
|
"readme*",
|
|
|
|
"README*",
|
|
|
|
"changelog*",
|
|
|
|
"CHANGELOG*",
|
2017-01-14 23:47:15 +02:00
|
|
|
}
|
2017-01-14 16:34:22 +02:00
|
|
|
}
|
2017-01-14 20:41:32 +02:00
|
|
|
return nil
|
2017-01-14 16:34:22 +02:00
|
|
|
}
|