1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-26 04:22:05 +02:00

98 lines
2.4 KiB
Go
Raw Normal View History

2017-04-14 15:39:32 -03:00
// Package defaults implements the Pipe interface providing default values
// for missing configuration.
2017-01-14 12:34:22 -02:00
package defaults
import (
2017-05-01 09:59:18 -03:00
"fmt"
2017-01-14 12:34:22 -02:00
2017-01-14 20:01:32 -02:00
"github.com/goreleaser/goreleaser/context"
2017-01-14 12:34:22 -02:00
)
2017-04-24 14:27:21 -03:00
// NameTemplate default name_template for the archive.
const NameTemplate = "{{ .Binary }}_{{.Version}}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
2017-04-24 14:27:21 -03:00
2017-04-29 12:49:22 +02:00
// SnapshotNameTemplate represents the default format for snapshot release names.
2017-05-01 09:59:18 -03:00
const SnapshotNameTemplate = "SNAPSHOT-{{ .Commit }}"
2017-04-29 12:49:22 +02:00
2017-01-14 12:34:22 -02:00
// Pipe for brew deployment
type Pipe struct{}
2017-01-14 19:41:32 +01:00
// Description of the pipe
2017-01-14 15:14:35 -02:00
func (Pipe) Description() string {
2017-01-19 10:04:41 +01:00
return "Setting defaults"
2017-01-14 12:34:22 -02:00
}
// Run the pipe
2017-01-14 19:41:32 +01:00
func (Pipe) Run(ctx *context.Context) error {
2017-05-01 09:59:18 -03: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 09:59:18 -03:00
if err := setReleaseDefaults(ctx); err != nil {
return err
}
setBuildDefaults(ctx)
if ctx.Config.Brew.Install == "" {
ctx.Config.Brew.Install = fmt.Sprintf(
`bin.install "%s"`,
ctx.Config.Build.Binary,
)
}
2017-05-01 09:59:18 -03:00
return setArchiveDefaults(ctx)
}
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-03-22 21:06:37 -03:00
if ctx.Config.Build.Binary == "" {
ctx.Config.Build.Binary = ctx.Config.Release.GitHub.Name
2017-01-14 19:29:30 +01:00
}
2017-01-14 14:06:57 -02:00
if ctx.Config.Build.Main == "" {
ctx.Config.Build.Main = "."
2017-01-14 12:34:22 -02:00
}
if len(ctx.Config.Build.Goos) == 0 {
ctx.Config.Build.Goos = []string{"linux", "darwin"}
2017-01-14 12:34:22 -02:00
}
if len(ctx.Config.Build.Goarch) == 0 {
ctx.Config.Build.Goarch = []string{"amd64", "386"}
2017-01-14 12:34:22 -02:00
}
2017-04-24 14:27:21 -03:00
if len(ctx.Config.Build.Goarm) == 0 {
ctx.Config.Build.Goarm = []string{"6"}
}
2017-01-14 14:06:57 -02:00
if ctx.Config.Build.Ldflags == "" {
2017-03-25 20:24:38 -03:00
ctx.Config.Build.Ldflags = "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}"
2017-01-14 12:34:22 -02:00
}
2017-05-01 09:59:18 -03:00
}
2017-05-01 09:59:18 -03:00
func setArchiveDefaults(ctx *context.Context) error {
2017-01-14 14:06:57 -02:00
if ctx.Config.Archive.NameTemplate == "" {
2017-04-24 14:27:21 -03:00
ctx.Config.Archive.NameTemplate = NameTemplate
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
}
if len(ctx.Config.Archive.Files) == 0 {
2017-05-11 00:05:51 -03:00
ctx.Config.Archive.Files = []string{
"licence*",
"LICENCE*",
"license*",
"LICENSE*",
"readme*",
"README*",
"changelog*",
"CHANGELOG*",
}
2017-01-14 12:34:22 -02:00
}
2017-01-14 19:41:32 +01:00
return nil
2017-01-14 12:34:22 -02:00
}