1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-04-11 11:42:15 +02:00

fix: env templates

closes #2281

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos A Becker 2021-06-04 18:11:29 +00:00
parent e25b6bb313
commit 39e5792993
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
3 changed files with 12 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"os"
"strings"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/internal/tmpl"
@ -49,7 +50,11 @@ func (Pipe) Run(ctx *context.Context) error {
if err != nil {
return err
}
ctx.Config.Env[i] = env
// XXX: this has no risk of panicking because it would already have
// panicked at `context.go`'s `splitEnv` method.
// Need to properly handle this at some point.
parts := strings.SplitN(env, "=", 2)
ctx.Env[parts[0]] = parts[1]
}
setDefaultTokenFiles(ctx)

View File

@ -39,12 +39,16 @@ func TestSetDefaultTokenFiles(t *testing.T) {
Env: []string{
"FOO=FOO_{{ .Env.BAR }}",
"FOOBAR={{.ProjectName}}",
"EMPTY_VAL=",
},
})
ctx.Env["FOOBAR"] = "old foobar"
os.Setenv("BAR", "lebar")
os.Setenv("GITHUB_TOKEN", "fake")
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, ctx.Config.Env, []string{"FOO=FOO_lebar", "FOOBAR=foobar"})
require.Equal(t, "FOO_lebar", ctx.Env["FOO"])
require.Equal(t, "foobar", ctx.Env["FOOBAR"])
require.Equal(t, "", ctx.Env["EMPTY_VAL"])
})
t.Run("template error", func(t *testing.T) {

View File

@ -127,6 +127,7 @@ func Wrap(ctx ctx.Context, config config.Project) *Context {
}
func splitEnv(env []string) map[string]string {
// TODO: this might panic if there is no `=` sign
r := map[string]string{}
for _, e := range env {
p := strings.SplitN(e, "=", 2)