1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00

fixed ldflags tag vs version confusion

This commit is contained in:
Carlos Alexandro Becker 2017-04-30 17:44:52 -03:00
parent 1b32f18463
commit 320cdf3b49
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
3 changed files with 10 additions and 5 deletions

View File

@ -190,9 +190,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=")
}