1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-13 13:48:40 +02:00

Merge branch 'master' into feature/snapshot

This commit is contained in:
Carlos Alexandro Becker 2017-05-01 09:29:55 -03:00 committed by GitHub
commit ced1737e8b
3 changed files with 10 additions and 5 deletions

View File

@ -192,9 +192,10 @@ build:
# Custom ldflags template.
# This is parsed with Golang template engine and the following variables
# are available:
# - Version
# - Date
# - Commit
# - Tag
# - Version (Tag with the `v` prefix stripped)
# The default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}`
# Date format is `2006-01-02_15:04:05`
ldflags: -s -w -X main.build={{.Version}}

View File

@ -10,6 +10,7 @@ import (
type ldflagsData struct {
Date string
Tag string
Commit string
Version string
}
@ -17,7 +18,8 @@ type ldflagsData struct {
func ldflags(ctx *context.Context) (string, error) {
var data = ldflagsData{
Commit: ctx.Git.Commit,
Version: ctx.Git.CurrentTag,
Tag: ctx.Git.CurrentTag,
Version: ctx.Version,
Date: time.Now().UTC().Format(time.RFC3339),
}
var out bytes.Buffer

View File

@ -12,7 +12,7 @@ func TestLdFlagsFullTemplate(t *testing.T) {
assert := assert.New(t)
var config = config.Project{
Build: config.Build{
Ldflags: "-s -w -X main.version={{.Version}} -X main.date={{.Date}} -X main.commit={{.Commit}}",
Ldflags: "-s -w -X main.version={{.Version}} -X main.tag={{.Tag}} -X main.date={{.Date}} -X main.commit={{.Commit}}",
},
}
var ctx = &context.Context{
@ -20,12 +20,14 @@ func TestLdFlagsFullTemplate(t *testing.T) {
CurrentTag: "v1.2.3",
Commit: "123",
},
Config: config,
Version: "1.2.3",
Config: config,
}
flags, err := ldflags(ctx)
assert.NoError(err)
assert.Contains(flags, "-s -w")
assert.Contains(flags, "-X main.version=v1.2.3")
assert.Contains(flags, "-X main.version=1.2.3")
assert.Contains(flags, "-X main.tag=v1.2.3")
assert.Contains(flags, "-X main.commit=123")
assert.Contains(flags, "-X main.date=")
}