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:
parent
1b32f18463
commit
320cdf3b49
@ -190,9 +190,10 @@ build:
|
|||||||
# Custom ldflags template.
|
# Custom ldflags template.
|
||||||
# This is parsed with Golang template engine and the following variables
|
# This is parsed with Golang template engine and the following variables
|
||||||
# are available:
|
# are available:
|
||||||
# - Version
|
|
||||||
# - Date
|
# - Date
|
||||||
# - Commit
|
# - 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}}`
|
# 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`
|
# Date format is `2006-01-02_15:04:05`
|
||||||
ldflags: -s -w -X main.build={{.Version}}
|
ldflags: -s -w -X main.build={{.Version}}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
type ldflagsData struct {
|
type ldflagsData struct {
|
||||||
Date string
|
Date string
|
||||||
|
Tag string
|
||||||
Commit string
|
Commit string
|
||||||
Version string
|
Version string
|
||||||
}
|
}
|
||||||
@ -17,7 +18,8 @@ type ldflagsData struct {
|
|||||||
func ldflags(ctx *context.Context) (string, error) {
|
func ldflags(ctx *context.Context) (string, error) {
|
||||||
var data = ldflagsData{
|
var data = ldflagsData{
|
||||||
Commit: ctx.Git.Commit,
|
Commit: ctx.Git.Commit,
|
||||||
Version: ctx.Git.CurrentTag,
|
Tag: ctx.Git.CurrentTag,
|
||||||
|
Version: ctx.Version,
|
||||||
Date: time.Now().UTC().Format(time.RFC3339),
|
Date: time.Now().UTC().Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
|
@ -12,7 +12,7 @@ func TestLdFlagsFullTemplate(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
var config = config.Project{
|
var config = config.Project{
|
||||||
Build: config.Build{
|
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{
|
var ctx = &context.Context{
|
||||||
@ -20,12 +20,14 @@ func TestLdFlagsFullTemplate(t *testing.T) {
|
|||||||
CurrentTag: "v1.2.3",
|
CurrentTag: "v1.2.3",
|
||||||
Commit: "123",
|
Commit: "123",
|
||||||
},
|
},
|
||||||
Config: config,
|
Version: "1.2.3",
|
||||||
|
Config: config,
|
||||||
}
|
}
|
||||||
flags, err := ldflags(ctx)
|
flags, err := ldflags(ctx)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Contains(flags, "-s -w")
|
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.commit=123")
|
||||||
assert.Contains(flags, "-X main.date=")
|
assert.Contains(flags, "-X main.date=")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user