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

feat: .Now template variable (#3853)

This will allow more customized templates using dates!

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2023-03-19 22:21:43 -03:00 committed by GitHub
parent 6e4c0e6abe
commit 590eff32d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 0 deletions

View File

@ -52,6 +52,7 @@ const (
isSnapshot = "IsSnapshot"
env = "Env"
date = "Date"
now = "Now"
timestamp = "Timestamp"
modulePath = "ModulePath"
releaseNotes = "ReleaseNotes"
@ -102,6 +103,7 @@ func New(ctx *context.Context) *Template {
releaseURL: ctx.ReleaseURL,
env: ctx.Env,
date: ctx.Date.UTC().Format(time.RFC3339),
now: ctx.Date.UTC(),
timestamp: ctx.Date.UTC().Unix(),
major: ctx.Semver.Major,
minor: ctx.Semver.Minor,

View File

@ -6,6 +6,7 @@ import (
"runtime"
"testing"
"text/template"
"time"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/testctx"
@ -38,6 +39,7 @@ func TestWithArtifact(t *testing.T) {
func(ctx *context.Context) {
ctx.ModulePath = "github.com/goreleaser/goreleaser"
ctx.ReleaseNotes = "test release notes"
ctx.Date = time.Unix(1678327562, 0)
},
)
for expect, tmpl := range map[string]string{
@ -75,6 +77,9 @@ func TestWithArtifact(t *testing.T) {
"artifact path: /tmp/foo.exe": "artifact path: {{ .ArtifactPath }}",
"artifact basename: foo.exe": "artifact basename: {{ base .ArtifactPath }}",
"artifact dir: /tmp": "artifact dir: {{ dir .ArtifactPath }}",
"2023": `{{ .Now.Format "2006" }}`,
"2023-03-09T02:06:02Z": `{{ .Date }}`,
"1678327562": `{{ .Timestamp }}`,
"remove this": "{{ filter .Env.MULTILINE \".*remove.*\" }}",
"something with\nmultiple lines\nto test things": "{{ reverseFilter .Env.MULTILINE \".*remove.*\" }}",

View File

@ -37,6 +37,7 @@ Key |Description
`.IsNightly` |`true` if `--nightly` is set, `false` otherwise
`.Env` |a map with system's environment variables
`.Date` |current UTC date in RFC 3339 format
`.Now` |current UTC date as `time.Time` struct, allows all `time.Time` functions (e.g. `{{ .Now.Format "2006" }}`) . Since v1.17.
`.Timestamp` |current UTC time in Unix format
`.ModulePath` |the go module path, as reported by `go list -m`
`incpatch "v1.2.4"` |increments the patch of the given version[^panic-if-not-semver]