1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2024-12-27 01:33:39 +02:00

feat: default GOARM change to 7 (#5157)

Guarded by an environment variable for now.

Closes #5155
This commit is contained in:
Carlos Alexandro Becker 2024-09-27 13:31:29 -03:00 committed by GitHub
parent 15d54735ab
commit 0468da12fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 90 additions and 4 deletions

View File

@ -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"}

View File

@ -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
}

View File

@ -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())
})
}

View File

@ -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"

View File

@ -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"

View File

@ -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") ||

View File

@ -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

22
www/docs/experiments.md Normal file
View File

@ -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`.

View File

@ -194,6 +194,7 @@ nav:
- sponsors.md
- users.md
- deprecations.md
- experiments.md
- Common errors:
- errors/version.md
- errors/dirty.md