mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
feat: allow to override env for a target (#3201)
* feat: allow to override env for a target Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: dupe key Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * test: fixes Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
b3fcc54a32
commit
f75d64d6cc
@ -206,11 +206,12 @@ func withOverrides(ctx *context.Context, build config.Build, options api.Options
|
||||
Flags: build.BuildDetails.Flags,
|
||||
Asmflags: build.BuildDetails.Asmflags,
|
||||
Gcflags: build.BuildDetails.Gcflags,
|
||||
Env: build.BuildDetails.Env,
|
||||
}
|
||||
if err := mergo.Merge(&dets, o.BuildDetails, mergo.WithOverride); err != nil {
|
||||
return build.BuildDetails, err
|
||||
}
|
||||
log.WithField("dets", dets).Info("will use")
|
||||
log.WithField("details", dets).Infof("overridden build details for %s", optsTarget)
|
||||
return dets, nil
|
||||
}
|
||||
}
|
||||
|
@ -340,7 +340,6 @@ func TestBuild(t *testing.T) {
|
||||
Builds: []config.Build{
|
||||
{
|
||||
ID: "foo",
|
||||
Env: []string{"GO111MODULE=off"},
|
||||
Binary: "bin/foo-{{ .Version }}",
|
||||
Targets: []string{
|
||||
"linux_amd64",
|
||||
@ -354,6 +353,7 @@ func TestBuild(t *testing.T) {
|
||||
GoBinary: "go",
|
||||
Command: "build",
|
||||
BuildDetails: config.BuildDetails{
|
||||
Env: []string{"GO111MODULE=off"},
|
||||
Asmflags: []string{".=", "all="},
|
||||
Gcflags: []string{"all="},
|
||||
Flags: []string{"{{.Env.GO_FLAGS}}"},
|
||||
@ -524,7 +524,6 @@ func TestBuildCodeInSubdir(t *testing.T) {
|
||||
Builds: []config.Build{
|
||||
{
|
||||
ID: "foo",
|
||||
Env: []string{"GO111MODULE=off"},
|
||||
Dir: "bar",
|
||||
Binary: "foo",
|
||||
Targets: []string{
|
||||
@ -532,6 +531,9 @@ func TestBuildCodeInSubdir(t *testing.T) {
|
||||
},
|
||||
GoBinary: "go",
|
||||
Command: "build",
|
||||
BuildDetails: config.BuildDetails{
|
||||
Env: []string{"GO111MODULE=off"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -555,11 +557,13 @@ func TestBuildWithDotGoDir(t *testing.T) {
|
||||
Builds: []config.Build{
|
||||
{
|
||||
ID: "foo",
|
||||
Env: []string{"GO111MODULE=off"},
|
||||
Binary: "foo",
|
||||
Targets: []string{runtimeTarget},
|
||||
GoBinary: "go",
|
||||
Command: "build",
|
||||
BuildDetails: config.BuildDetails{
|
||||
Env: []string{"GO111MODULE=off"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -834,12 +838,14 @@ func TestRunPipeWithMainFuncNotInMainGoFile(t *testing.T) {
|
||||
config := config.Project{
|
||||
Builds: []config.Build{
|
||||
{
|
||||
Env: []string{"GO111MODULE=off"},
|
||||
Binary: "foo",
|
||||
Hooks: config.BuildHookConfig{},
|
||||
Targets: []string{
|
||||
runtimeTarget,
|
||||
},
|
||||
BuildDetails: config.BuildDetails{
|
||||
Env: []string{"GO111MODULE=off"},
|
||||
},
|
||||
GoBinary: "go",
|
||||
Command: "build",
|
||||
},
|
||||
@ -978,7 +984,6 @@ func TestBuildModTimestamp(t *testing.T) {
|
||||
Builds: []config.Build{
|
||||
{
|
||||
ID: "foo",
|
||||
Env: []string{"GO111MODULE=off"},
|
||||
Binary: "bin/foo-{{ .Version }}",
|
||||
Targets: []string{
|
||||
"linux_amd64",
|
||||
@ -990,6 +995,7 @@ func TestBuildModTimestamp(t *testing.T) {
|
||||
"linux_mips64le_softfloat",
|
||||
},
|
||||
BuildDetails: config.BuildDetails{
|
||||
Env: []string{"GO111MODULE=off"},
|
||||
Asmflags: []string{".=", "all="},
|
||||
Gcflags: []string{"all="},
|
||||
Flags: []string{"{{.Env.GO_FLAGS}}"},
|
||||
@ -1175,6 +1181,7 @@ func TestOverrides(t *testing.T) {
|
||||
config.Build{
|
||||
BuildDetails: config.BuildDetails{
|
||||
Ldflags: []string{"original"},
|
||||
Env: []string{"FOO=bar"},
|
||||
},
|
||||
BuildDetailsOverrides: []config.BuildDetailsOverride{
|
||||
{
|
||||
@ -1182,6 +1189,7 @@ func TestOverrides(t *testing.T) {
|
||||
Goarch: "amd64",
|
||||
BuildDetails: config.BuildDetails{
|
||||
Ldflags: []string{"overridden"},
|
||||
Env: []string{"FOO=overridden"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -1193,6 +1201,7 @@ func TestOverrides(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, dets, config.BuildDetails{
|
||||
Ldflags: []string{"overridden"},
|
||||
Env: []string{"FOO=overridden"},
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -72,8 +72,8 @@ func TestBuild(t *testing.T) {
|
||||
Binary: "testing.v{{.Version}}",
|
||||
BuildDetails: config.BuildDetails{
|
||||
Flags: []string{"-n"},
|
||||
Env: []string{"BLAH=1"},
|
||||
},
|
||||
Env: []string{"BLAH=1"},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -245,8 +245,10 @@ func TestDefaultExpandEnv(t *testing.T) {
|
||||
Config: config.Project{
|
||||
Builds: []config.Build{
|
||||
{
|
||||
Env: []string{
|
||||
"XFOO=bar_$XBAR",
|
||||
BuildDetails: config.BuildDetails{
|
||||
Env: []string{
|
||||
"XFOO=bar_$XBAR",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -321,7 +321,6 @@ type Build struct {
|
||||
Main string `yaml:"main,omitempty"`
|
||||
Binary string `yaml:"binary,omitempty"`
|
||||
Hooks BuildHookConfig `yaml:"hooks,omitempty"`
|
||||
Env []string `yaml:"env,omitempty"`
|
||||
Builder string `yaml:"builder,omitempty"`
|
||||
ModTimestamp string `yaml:"mod_timestamp,omitempty"`
|
||||
Skip bool `yaml:"skip,omitempty"`
|
||||
@ -351,6 +350,7 @@ type BuildDetails struct {
|
||||
Flags FlagArray `yaml:"flags,omitempty"`
|
||||
Asmflags StringArray `yaml:"asmflags,omitempty"`
|
||||
Gcflags StringArray `yaml:"gcflags,omitempty"`
|
||||
Env []string `yaml:"env,omitempty"`
|
||||
}
|
||||
|
||||
type BuildHookConfig struct {
|
||||
|
@ -194,6 +194,7 @@ builds:
|
||||
overrides:
|
||||
- goos: darwin
|
||||
goarch: arm64
|
||||
goamd64: v1
|
||||
goarm: ''
|
||||
gomips: ''
|
||||
ldflags:
|
||||
@ -204,6 +205,8 @@ builds:
|
||||
- foobar
|
||||
gcflags:
|
||||
- foobaz
|
||||
env:
|
||||
- CGO_ENABLED=1
|
||||
```
|
||||
|
||||
!!! tip
|
||||
|
Loading…
x
Reference in New Issue
Block a user