diff --git a/internal/pipe/env/env.go b/internal/pipe/env/env.go index 4fe35dbf4..d6b15cd63 100644 --- a/internal/pipe/env/env.go +++ b/internal/pipe/env/env.go @@ -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) diff --git a/internal/pipe/env/env_test.go b/internal/pipe/env/env_test.go index 81877f841..365afdc62 100644 --- a/internal/pipe/env/env_test.go +++ b/internal/pipe/env/env_test.go @@ -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) { diff --git a/pkg/context/context.go b/pkg/context/context.go index aeb0799af..cc76b7a40 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -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)