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:
parent
e25b6bb313
commit
39e5792993
7
internal/pipe/env/env.go
vendored
7
internal/pipe/env/env.go
vendored
@ -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)
|
||||
|
6
internal/pipe/env/env_test.go
vendored
6
internal/pipe/env/env_test.go
vendored
@ -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) {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user