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

fix: gomod.env not being used #3434

Merged
merged 1 commit into from Oct 4, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/pipe/gomod/gomod.go
Expand Up @@ -33,7 +33,9 @@ func (Pipe) Run(ctx *context.Context) error {
if ctx.Config.GoMod.Mod != "" {
flags = append(flags, "-mod="+ctx.Config.GoMod.Mod)
}
out, err := exec.CommandContext(ctx, ctx.Config.GoMod.GoBinary, flags...).CombinedOutput()
cmd := exec.CommandContext(ctx, ctx.Config.GoMod.GoBinary, flags...)
cmd.Env = append(ctx.Env.Strings(), ctx.Config.GoMod.Env...)
out, err := cmd.CombinedOutput()
result := strings.TrimSpace(string(out))
if result == go115NotAGoModuleError || result == go116NotAGoModuleError {
return pipe.Skip("not a go module")
Expand Down
13 changes: 13 additions & 0 deletions internal/pipe/gomod/gomod_test.go
Expand Up @@ -29,6 +29,19 @@ func TestRunCustomMod(t *testing.T) {
require.Equal(t, "github.com/goreleaser/goreleaser", ctx.ModulePath)
}

func TestCustomEnv(t *testing.T) {
bin := filepath.Join(t.TempDir(), "go.bin")
require.NoError(t, os.WriteFile(bin, []byte("#!/bin/sh\nenv | grep -qw FOO=bar"), 0o755))
ctx := context.New(config.Project{
GoMod: config.GoMod{
GoBinary: bin,
Env: []string{"FOO=bar"},
},
})
require.NoError(t, Pipe{}.Default(ctx))
require.NoError(t, Pipe{}.Run(ctx))
}

func TestRunOutsideGoModule(t *testing.T) {
dir := testlib.Mktmp(t)
require.NoError(t, os.WriteFile(filepath.Join(dir, "main.go"), []byte("package main\nfunc main() {println(0)}"), 0o666))
Expand Down
3 changes: 2 additions & 1 deletion www/docs/customization/build.md
Expand Up @@ -60,7 +60,8 @@ builds:
- feature

# Custom environment variables to be set during the builds.
# Default is empty.
#
# Default: `os.Environ()` merged with what you set the root `env` section.
env:
- CGO_ENABLED=0

Expand Down
8 changes: 5 additions & 3 deletions www/docs/customization/verifiable_builds.md
Expand Up @@ -18,12 +18,13 @@ gomod:
# this setting.
# Notice: for this to work your `build.main` must be a package, not a `.go` file.
#
# Default is false.
# Default: false.
proxy: true

# If proxy is true, use these environment variables when running `go mod`
# commands (namely, `go mod tidy`).
# Defaults to `os.Environ()`.
#
# Default: `os.Environ()` merged with what you set the root `env` section.
env:
- GOPROXY=https://proxy.golang.org,direct
- GOSUMDB=sum.golang.org
Expand All @@ -36,7 +37,8 @@ gomod:
mod: mod

# Which Go binary to use.
# Defaults to `go`.
#
# Default: `go`.
gobinary: go1.17
```

Expand Down