mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-28 04:44:34 +02:00
fix: gomod.env not being used (#3434)
Fixes #3426 Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
ae9c8acc99
commit
4a51099964
@ -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
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user