1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

34 lines
647 B
Go
Raw Normal View History

2017-03-25 20:24:38 -03:00
package build
import (
"bytes"
"text/template"
"time"
2017-06-27 19:36:36 -03:00
"github.com/goreleaser/goreleaser/config"
2017-03-25 20:24:38 -03:00
"github.com/goreleaser/goreleaser/context"
)
type ldflagsData struct {
Date string
2017-04-30 17:44:52 -03:00
Tag string
2017-03-25 20:24:38 -03:00
Commit string
Version string
}
2017-06-27 19:36:36 -03:00
func ldflags(ctx *context.Context, build config.Build) (string, error) {
2017-03-25 20:24:38 -03:00
var data = ldflagsData{
Commit: ctx.Git.Commit,
2017-04-30 17:44:52 -03:00
Tag: ctx.Git.CurrentTag,
Version: ctx.Version,
2017-04-09 10:22:09 -03:00
Date: time.Now().UTC().Format(time.RFC3339),
2017-03-25 20:24:38 -03:00
}
var out bytes.Buffer
2017-06-27 19:36:36 -03:00
t, err := template.New("ldflags").Parse(build.Ldflags)
2017-03-25 20:24:38 -03:00
if err != nil {
return "", err
}
err = t.Execute(&out, data)
return out.String(), err
}