Skip to content

[bug] Environment variable value cannot contain = #1231

@cfergeau

Description

@cfergeau

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

es := strings.Split(e, "=")
if len(es) != 2 {
return fmt.Errorf("%w: %s", ErrorInvalidEnvironmentVariable, e)
}
which do not expect the env var line to contain 2 = signs.

To Reproduce
Steps to reproduce the behavior:

  1. Add a env: -CGO_CFLAGS=a=b line to your .slsa-goreleaser-yml
  2. 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 {

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:goIssue related to the Go ecosystemtype:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions