-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
builder: go: Allow equal signs in env vars
If .slsa-goreleaser.yml contains an env var with multiple '=' signs: ``` env: - CGO_ENABLED=1 - CGO_CFLAGS=-mmacosx-version-min=11.0 ``` the 'build dry project' GH workflow step fails with "invalid environment variable: CGO_CFLAGS=-mmacosx-version-min=11.0" This is caused by the way the env vars are parsed in GoReleaserConfig:setEnvs which only allow for a single '=' sign. This commit fixes this by splitting the env string at the first equal sign, first part is the env var name and won't contain '=' signs, second part is its value and can contain any number of '='. This also adds unit tests for this situation, and for env vars with no values (`CGO_CFLAGS=`). This fixes #1231 Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
- Loading branch information
Showing
4 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
internal/builders/go/pkg/testdata/releaser-valid-envs-multiple-equal-signs.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}" |
16 changes: 16 additions & 0 deletions
16
internal/builders/go/pkg/testdata/releaser-valid-envs-no-value.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}" |