diff --git a/internal/builders/golang/build.go b/internal/builders/golang/build.go index ae27907ac..01fc444a0 100644 --- a/internal/builders/golang/build.go +++ b/internal/builders/golang/build.go @@ -15,6 +15,7 @@ import ( "github.com/caarlos0/log" "github.com/goreleaser/goreleaser/v2/internal/artifact" "github.com/goreleaser/goreleaser/v2/internal/builders/buildtarget" + "github.com/goreleaser/goreleaser/v2/internal/experimental" "github.com/goreleaser/goreleaser/v2/internal/gio" "github.com/goreleaser/goreleaser/v2/internal/logext" "github.com/goreleaser/goreleaser/v2/internal/tmpl" @@ -63,7 +64,7 @@ func (*Builder) WithDefaults(build config.Build) (config.Build, error) { build.Goarch = []string{"amd64", "arm64", "386"} } if len(build.Goarm) == 0 { - build.Goarm = []string{"6"} + build.Goarm = []string{experimental.DefaultGOARM()} } if len(build.Gomips) == 0 { build.Gomips = []string{"hardfloat"} diff --git a/internal/experimental/exp.go b/internal/experimental/exp.go new file mode 100644 index 000000000..404088771 --- /dev/null +++ b/internal/experimental/exp.go @@ -0,0 +1,31 @@ +// Package experimental guards experimental features. +package experimental + +import ( + "os" + "strings" +) + +const ( + envKey = "GORELEASER_EXPERIMENTAL" + defaultGOARMv7 = "defaultgoarm" +) + +// DefaultGOARM considers the `defaultgoarm` experiment and returns the correct +// value. +func DefaultGOARM() string { + if has(defaultGOARMv7) { + return "7" + } + return "6" +} + +func has(e string) bool { + experiments := strings.Split(os.Getenv(envKey), ",") + for _, exp := range experiments { + if exp == e { + return true + } + } + return false +} diff --git a/internal/experimental/exp_test.go b/internal/experimental/exp_test.go new file mode 100644 index 000000000..afbbaff09 --- /dev/null +++ b/internal/experimental/exp_test.go @@ -0,0 +1,25 @@ +package experimental + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestDefaultGoarm(t *testing.T) { + t.Run("not set", func(t *testing.T) { + require.Equal(t, "6", DefaultGOARM()) + }) + t.Run("empty", func(t *testing.T) { + t.Setenv(envKey, "") + require.Equal(t, "6", DefaultGOARM()) + }) + t.Run("notset", func(t *testing.T) { + t.Setenv(envKey, "otherexp") + require.Equal(t, "6", DefaultGOARM()) + }) + t.Run("set", func(t *testing.T) { + t.Setenv(envKey, "foo,"+defaultGOARMv7+",somethingelse") + require.Equal(t, "7", DefaultGOARM()) + }) +} diff --git a/internal/pipe/brew/brew.go b/internal/pipe/brew/brew.go index e87fd607b..893595fd4 100644 --- a/internal/pipe/brew/brew.go +++ b/internal/pipe/brew/brew.go @@ -16,6 +16,7 @@ import ( "github.com/goreleaser/goreleaser/v2/internal/artifact" "github.com/goreleaser/goreleaser/v2/internal/client" "github.com/goreleaser/goreleaser/v2/internal/commitauthor" + "github.com/goreleaser/goreleaser/v2/internal/experimental" "github.com/goreleaser/goreleaser/v2/internal/pipe" "github.com/goreleaser/goreleaser/v2/internal/skips" "github.com/goreleaser/goreleaser/v2/internal/tmpl" @@ -64,7 +65,7 @@ func (Pipe) Default(ctx *context.Context) error { brew.Name = ctx.Config.ProjectName } if brew.Goarm == "" { - brew.Goarm = "6" + brew.Goarm = experimental.DefaultGOARM() } if brew.Goamd64 == "" { brew.Goamd64 = "v1" diff --git a/internal/pipe/docker/docker.go b/internal/pipe/docker/docker.go index 35bc01257..65716aab4 100644 --- a/internal/pipe/docker/docker.go +++ b/internal/pipe/docker/docker.go @@ -12,6 +12,7 @@ import ( "github.com/caarlos0/log" "github.com/goreleaser/goreleaser/v2/internal/artifact" + "github.com/goreleaser/goreleaser/v2/internal/experimental" "github.com/goreleaser/goreleaser/v2/internal/gio" "github.com/goreleaser/goreleaser/v2/internal/ids" "github.com/goreleaser/goreleaser/v2/internal/pipe" @@ -66,7 +67,7 @@ func (Pipe) Default(ctx *context.Context) error { docker.Goarch = "amd64" } if docker.Goarm == "" { - docker.Goarm = "6" + docker.Goarm = experimental.DefaultGOARM() } if docker.Goamd64 == "" { docker.Goamd64 = "v1" diff --git a/internal/pipe/partial/partial.go b/internal/pipe/partial/partial.go index dcb9e0b06..7873dcaf0 100644 --- a/internal/pipe/partial/partial.go +++ b/internal/pipe/partial/partial.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/charmbracelet/x/exp/ordered" + "github.com/goreleaser/goreleaser/v2/internal/experimental" "github.com/goreleaser/goreleaser/v2/pkg/context" ) @@ -29,7 +30,7 @@ func getFilter() string { target = target + "_" + goamd64 } if strings.HasSuffix(target, "_arm") { - goarm := ordered.First(os.Getenv("GGOARM"), os.Getenv("GOARM"), "6") + goarm := ordered.First(os.Getenv("GGOARM"), os.Getenv("GOARM"), experimental.DefaultGOARM()) target = target + "_" + goarm } if strings.HasSuffix(target, "_mips") || diff --git a/pkg/context/context.go b/pkg/context/context.go index 84fda8c39..26ede6651 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -162,6 +162,9 @@ func ToEnv(env []string) Env { if !ok || k == "" { continue } + if k == "GORELEASER_EXPERIMENTAL" { + os.Setenv(k, v) + } r[k] = v } return r diff --git a/www/docs/experiments.md b/www/docs/experiments.md new file mode 100644 index 000000000..d5a62a9da --- /dev/null +++ b/www/docs/experiments.md @@ -0,0 +1,22 @@ +# Experimental features + +Much like Go, GoReleaser can be told to use an experimental feature via +environment variables. + +Currently, the following experiments are available. + +## Default `GOARM` change to `7` + +Historically, GoReleaser sets `GOARM` to `6` by default. +You can make it use `7` instead by setting: + +```sh +export GORELEASER_EXPERIMENTAL="defaultgoarm" +``` + +This will be default behavior in GoReleaser v3. + +!!! tip + + You can also set the `GORELEASER_EXPERIMENTAL` variable in `env` array in + your `.goreleaser.yml`. diff --git a/www/mkdocs.yml b/www/mkdocs.yml index 60a7f8ed6..094dda626 100644 --- a/www/mkdocs.yml +++ b/www/mkdocs.yml @@ -194,6 +194,7 @@ nav: - sponsors.md - users.md - deprecations.md + - experiments.md - Common errors: - errors/version.md - errors/dirty.md