You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-11-06 09:09:29 +02:00
fix: all envs allowed on build template (#992)
This commit is contained in:
committed by
GitHub
parent
ce69ee5316
commit
310bf450a8
@@ -3,6 +3,7 @@ package tmpl
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
@@ -63,6 +64,23 @@ func New(ctx *context.Context) *Template {
|
||||
}
|
||||
}
|
||||
|
||||
// WithEnvS overrides template's env field with the given KEY=VALUE list of
|
||||
// environment variables
|
||||
func (t *Template) WithEnvS(envs []string) *Template {
|
||||
var result = map[string]string{}
|
||||
for _, env := range envs {
|
||||
var parts = strings.SplitN(env, "=", 2)
|
||||
result[parts[0]] = parts[1]
|
||||
}
|
||||
return t.WithEnv(result)
|
||||
}
|
||||
|
||||
// WithEnv overrides template's env field with the given environment map
|
||||
func (t *Template) WithEnv(e map[string]string) *Template {
|
||||
t.fields[env] = e
|
||||
return t
|
||||
}
|
||||
|
||||
// WithArtifact populates fields from the artifact and replacements
|
||||
func (t *Template) WithArtifact(a artifact.Artifact, replacements map[string]string) *Template {
|
||||
var bin = a.Extra[binary]
|
||||
|
||||
@@ -113,6 +113,20 @@ func TestEnv(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithEnv(t *testing.T) {
|
||||
var ctx = context.New(config.Project{})
|
||||
ctx.Env = map[string]string{
|
||||
"FOO": "BAR",
|
||||
}
|
||||
ctx.Git.CurrentTag = "v1.2.3"
|
||||
out, err := New(ctx).WithEnvS([]string{
|
||||
"FOO=foo",
|
||||
"BAR=bar",
|
||||
}).Apply("{{ .Env.FOO }}-{{ .Env.BAR }}")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "foo-bar", out)
|
||||
}
|
||||
|
||||
func TestFuncMap(t *testing.T) {
|
||||
var ctx = context.New(config.Project{
|
||||
ProjectName: "proj",
|
||||
|
||||
Reference in New Issue
Block a user