Skip to content
Permalink
Browse files
fix: gomod.env not being used (#3434)
Fixes  #3426

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Oct 4, 2022
1 parent ae9c8ac commit 4a510999646d7b6c794fd99a0b43bf4fbd16897e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
@@ -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")
@@ -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))
@@ -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
@@ -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
@@ -36,7 +37,8 @@ gomod:
mod: mod
# Which Go binary to use.
# Defaults to `go`.
#
# Default: `go`.
gobinary: go1.17
```

0 comments on commit 4a51099

Please sign in to comment.