Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builder: go: Allow equal signs in env vars #1232

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/builders/go/pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ func validateVersion(cf *goReleaserConfigFile) error {
func (r *GoReleaserConfig) setEnvs(cf *goReleaserConfigFile) error {
m := make(map[string]string)
for _, e := range cf.Env {
es := strings.Split(e, "=")
if len(es) != 2 {
name, value, present := strings.Cut(e, "=")
if !present {
return fmt.Errorf("%w: %s", ErrorInvalidEnvironmentVariable, e)
}
m[es[0]] = es[1]
m[name] = value
}

if len(m) > 0 {
Expand Down
26 changes: 26 additions & 0 deletions internal/builders/go/pkg/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@ func Test_ConfigFromFile(t *testing.T) {
Main: asPointer("./relative/main.go"),
},
},
{
name: "valid env var with no value",
path: "./testdata/releaser-valid-envs-no-value.yml",
config: GoReleaserConfig{
Goos: "linux", Goarch: "amd64",
Flags: []string{"-trimpath", "-tags=netgo"},
Ldflags: []string{"{{ .Env.VERSION_LDFLAGS }}"},
Binary: "binary-{{ .OS }}-{{ .Arch }}",
Env: map[string]string{
"GO111MODULE": "on", "CGO_ENABLED": "0", "CGO_CFLAGS": "",
},
},
},
{
name: "valid env var with multiple = signs",
path: "./testdata/releaser-valid-envs-multiple-equal-signs.yml",
config: GoReleaserConfig{
Goos: "linux", Goarch: "amd64",
Flags: []string{"-trimpath", "-tags=netgo"},
Ldflags: []string{"{{ .Env.VERSION_LDFLAGS }}"},
Binary: "binary-{{ .OS }}-{{ .Arch }}",
Env: map[string]string{
"GO111MODULE": "on", "CGO_ENABLED": "0", "CGO_CFLAGS": "a=b=c",
},
},
},
{
name: "missing version",
path: "./testdata/releaser-noversion.yml",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 1
env:
- GO111MODULE=on
# https://stackoverflow.com/a/62821358/19407
- CGO_ENABLED=0
- CGO_CFLAGS=a=b=c

flags:
- -trimpath
- -tags=netgo

goos: linux
goarch: amd64
binary: binary-{{ .OS }}-{{ .Arch }}
ldflags:
- "{{ .Env.VERSION_LDFLAGS }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 1
env:
- GO111MODULE=on
# https://stackoverflow.com/a/62821358/19407
- CGO_ENABLED=0
- CGO_CFLAGS=

flags:
- -trimpath
- -tags=netgo

goos: linux
goarch: amd64
binary: binary-{{ .OS }}-{{ .Arch }}
ldflags:
- "{{ .Env.VERSION_LDFLAGS }}"