-
Notifications
You must be signed in to change notification settings - Fork 177
Description
Describe the bug
I'm following the steps from https://github.com/slsa-framework/slsa-github-generator/blob/main/internal/builders/go/README.md in order to use SLSA in my project
When building [my project](https://gtihub.com/cfergeau/vfkit/tree/slsa] I want to set CGO_CFLAGS=-mmacosx-version-min=11.0 in the environment.
I added this to my .slsa-goreleaser.yml:
env:
- CGO_ENABLED=1
- CGO_CFLAGS=-mmacosx-version-min=11.0
but the 'build dry project' step fails with invalid environment variable: CGO_CFLAGS=-mmacosx-version-min=11.0
https://github.com/cfergeau/vfkit/actions/runs/3469089554/jobs/5795684619
This seems to be caused by this code
slsa-github-generator/internal/builders/go/pkg/config.go
Lines 170 to 173 in eb79b8b
| es := strings.Split(e, "=") | |
| if len(es) != 2 { | |
| return fmt.Errorf("%w: %s", ErrorInvalidEnvironmentVariable, e) | |
| } |
= signs.
To Reproduce
Steps to reproduce the behavior:
- Add a
env: -CGO_CFLAGS=a=bline to your.slsa-goreleaser-yml - Trigger the slsa github actions workflow
Expected behavior
I think a change such as this one would let me use = in env vars.
diff --git a/internal/builders/go/pkg/config.go b/internal/builders/go/pkg/config.go
index 1df1bf7..eba3e39 100644
--- a/internal/builders/go/pkg/config.go
+++ b/internal/builders/go/pkg/config.go
@@ -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 value == "" || !present {
return fmt.Errorf("%w: %s", ErrorInvalidEnvironmentVariable, e)
}
- m[es[0]] = es[1]
+ m[name] = value
}
if len(m) > 0 {