mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-14 03:51:24 +02:00
refactor: use std maps,slices instead of golang.org/exp (#5221)
The PR refactors code by replacing usage of `golang.org/exp/slices`/`golang.org/exp/maps` package with the standard `slices`/`maps`. Additionally, replace the function `keys(someMap)` with `slices.Compact(maps.Keys(someMap))` Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
542e5a0723
commit
0f48a6dd40
2
go.mod
2
go.mod
@ -331,7 +331,7 @@ require (
|
||||
go.uber.org/automaxprocs v1.6.0
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
|
||||
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect
|
||||
golang.org/x/mod v0.21.0 // indirect
|
||||
golang.org/x/net v0.30.0 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"maps"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@ -102,7 +103,7 @@ func (*Builder) WithDefaults(build config.Build) (config.Build, error) {
|
||||
}
|
||||
targets[fixTarget(target)] = true
|
||||
}
|
||||
build.Targets = keys(targets)
|
||||
build.Targets = slices.Collect(maps.Keys(targets))
|
||||
}
|
||||
return build, nil
|
||||
}
|
||||
@ -163,14 +164,6 @@ func warnIfTargetsAndOtherOptionTogether(build config.Build) bool {
|
||||
return res
|
||||
}
|
||||
|
||||
func keys(m map[string]bool) []string {
|
||||
result := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
result = append(result, k)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
const (
|
||||
go118FirstClassTargetsName = "go_118_first_class"
|
||||
goStableFirstClassTargetsName = "go_first_class"
|
||||
|
@ -5,9 +5,11 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
@ -377,21 +379,12 @@ func installs(ctx *context.Context, cfg config.Homebrew, art *artifact.Artifact)
|
||||
}
|
||||
}
|
||||
|
||||
result := keys(installMap)
|
||||
sort.Strings(result)
|
||||
result := slices.Sorted(maps.Keys(installMap))
|
||||
log.WithField("install", result).Info("guessing install")
|
||||
|
||||
return append(result, split(extraInstall)...), nil
|
||||
}
|
||||
|
||||
func keys(m map[string]bool) []string {
|
||||
keys := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.ReleaseURLTemplater, artifacts []*artifact.Artifact) (templateData, error) {
|
||||
sort.Slice(cfg.Dependencies, func(i, j int) bool {
|
||||
return cfg.Dependencies[i].Name < cfg.Dependencies[j].Name
|
||||
|
@ -5,12 +5,12 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
@ -23,7 +23,6 @@ import (
|
||||
"github.com/goreleaser/goreleaser/v2/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/v2/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/v2/pkg/context"
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
const nixConfigExtra = "NixConfig"
|
||||
@ -313,11 +312,10 @@ func preparePkg(
|
||||
}
|
||||
}
|
||||
|
||||
if roots := slices.Compact(maps.Values(data.SourceRoots)); len(roots) == 1 {
|
||||
if roots := slices.Compact(slices.Collect(maps.Values(data.SourceRoots))); len(roots) == 1 {
|
||||
data.SourceRoot = roots[0]
|
||||
}
|
||||
data.Platforms = keys(platforms)
|
||||
sort.Strings(data.Platforms)
|
||||
data.Platforms = slices.Sorted(maps.Keys(platforms))
|
||||
|
||||
return doBuildPkg(ctx, data)
|
||||
}
|
||||
@ -339,14 +337,6 @@ var goosToPlatform = map[string]string{
|
||||
"darwinarm64": "aarch64-darwin",
|
||||
}
|
||||
|
||||
func keys(m map[string]bool) []string {
|
||||
keys := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
func doPublish(ctx *context.Context, prefetcher shaPrefetcher, cl client.Client, pkg *artifact.Artifact) error {
|
||||
nix, err := artifact.Extra[config.Nix](*pkg, nixConfigExtra)
|
||||
if err != nil {
|
||||
|
@ -2,12 +2,12 @@ package skips
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/goreleaser/goreleaser/v2/pkg/context"
|
||||
"golang.org/x/exp/maps"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
type Key string
|
||||
@ -36,8 +36,7 @@ const (
|
||||
)
|
||||
|
||||
func String(ctx *context.Context) string {
|
||||
keys := maps.Keys(ctx.Skips)
|
||||
sort.Strings(keys)
|
||||
keys := slices.Sorted(maps.Keys(ctx.Skips))
|
||||
str := strings.Join(keys, ", ")
|
||||
if idx := strings.LastIndex(str, ","); idx > -1 {
|
||||
str = str[:idx] + " and" + str[idx+1:]
|
||||
|
@ -1,12 +1,13 @@
|
||||
package skips_test
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/v2/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/testctx"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
@ -36,5 +37,5 @@ func TestAny(t *testing.T) {
|
||||
func TestSet(t *testing.T) {
|
||||
ctx := testctx.New()
|
||||
skips.Set(ctx, skips.Publish, skips.Announce)
|
||||
require.ElementsMatch(t, []string{"publish", "announce"}, maps.Keys(ctx.Skips))
|
||||
require.ElementsMatch(t, []string{"publish", "announce"}, slices.Collect(maps.Keys(ctx.Skips)))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user