mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-04-04 22:14:28 +02:00
refactor(build): remove unused param (#3248)
we dont need to check the go version anymore, so we can remove all this now. Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
7aeebb12f2
commit
236e987ced
@ -4,8 +4,6 @@ package buildtarget
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/caarlos0/log"
|
"github.com/caarlos0/log"
|
||||||
@ -25,14 +23,6 @@ func (t target) String() string {
|
|||||||
|
|
||||||
// List compiles the list of targets for the given builds.
|
// List compiles the list of targets for the given builds.
|
||||||
func List(build config.Build) ([]string, error) {
|
func List(build config.Build) ([]string, error) {
|
||||||
version, err := goVersion(build)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return matrix(build, version)
|
|
||||||
}
|
|
||||||
|
|
||||||
func matrix(build config.Build, version []byte) ([]string, error) {
|
|
||||||
// nolint:prealloc
|
// nolint:prealloc
|
||||||
var targets []target
|
var targets []target
|
||||||
// nolint:prealloc
|
// nolint:prealloc
|
||||||
@ -135,23 +125,6 @@ func ignored(build config.Build, target target) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func goVersion(build config.Build) ([]byte, error) {
|
|
||||||
cmd := exec.Command(build.GoBinary, "version")
|
|
||||||
// If the build.Dir is acessible, set the cmd dir to it in case
|
|
||||||
// of reletive path to GoBinary
|
|
||||||
if fileInfo, err := os.Stat(build.Dir); err == nil {
|
|
||||||
if !fileInfo.IsDir() {
|
|
||||||
return nil, fmt.Errorf("invalid builds.dir property, it should be a directory: %s", build.Dir)
|
|
||||||
}
|
|
||||||
cmd.Dir = build.Dir
|
|
||||||
}
|
|
||||||
bts, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("unable to determine version of go binary (%s): %w", build.GoBinary, err)
|
|
||||||
}
|
|
||||||
return bts, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func valid(target target) bool {
|
func valid(target target) bool {
|
||||||
return contains(target.os+target.arch, validTargets)
|
return contains(target.os+target.arch, validTargets)
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func TestAllBuildTargets(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Run("go 1.18", func(t *testing.T) {
|
t.Run("go 1.18", func(t *testing.T) {
|
||||||
result, err := matrix(build, []byte("go version go1.18.0"))
|
result, err := List(build)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, []string{
|
require.Equal(t, []string{
|
||||||
"linux_386",
|
"linux_386",
|
||||||
@ -111,46 +111,46 @@ func TestAllBuildTargets(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid goos", func(t *testing.T) {
|
t.Run("invalid goos", func(t *testing.T) {
|
||||||
_, err := matrix(config.Build{
|
_, err := List(config.Build{
|
||||||
Goos: []string{"invalid"},
|
Goos: []string{"invalid"},
|
||||||
Goarch: []string{"amd64"},
|
Goarch: []string{"amd64"},
|
||||||
Goamd64: []string{"v2"},
|
Goamd64: []string{"v2"},
|
||||||
}, []byte("go version go1.18.0"))
|
})
|
||||||
require.EqualError(t, err, "invalid goos: invalid")
|
require.EqualError(t, err, "invalid goos: invalid")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid goarch", func(t *testing.T) {
|
t.Run("invalid goarch", func(t *testing.T) {
|
||||||
_, err := matrix(config.Build{
|
_, err := List(config.Build{
|
||||||
Goos: []string{"linux"},
|
Goos: []string{"linux"},
|
||||||
Goarch: []string{"invalid"},
|
Goarch: []string{"invalid"},
|
||||||
}, []byte("go version go1.18.0"))
|
})
|
||||||
require.EqualError(t, err, "invalid goarch: invalid")
|
require.EqualError(t, err, "invalid goarch: invalid")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid goarm", func(t *testing.T) {
|
t.Run("invalid goarm", func(t *testing.T) {
|
||||||
_, err := matrix(config.Build{
|
_, err := List(config.Build{
|
||||||
Goos: []string{"linux"},
|
Goos: []string{"linux"},
|
||||||
Goarch: []string{"arm"},
|
Goarch: []string{"arm"},
|
||||||
Goarm: []string{"invalid"},
|
Goarm: []string{"invalid"},
|
||||||
}, []byte("go version go1.18.0"))
|
})
|
||||||
require.EqualError(t, err, "invalid goarm: invalid")
|
require.EqualError(t, err, "invalid goarm: invalid")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid gomips", func(t *testing.T) {
|
t.Run("invalid gomips", func(t *testing.T) {
|
||||||
_, err := matrix(config.Build{
|
_, err := List(config.Build{
|
||||||
Goos: []string{"linux"},
|
Goos: []string{"linux"},
|
||||||
Goarch: []string{"mips"},
|
Goarch: []string{"mips"},
|
||||||
Gomips: []string{"invalid"},
|
Gomips: []string{"invalid"},
|
||||||
}, []byte("go version go1.18.0"))
|
})
|
||||||
require.EqualError(t, err, "invalid gomips: invalid")
|
require.EqualError(t, err, "invalid gomips: invalid")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid goamd64", func(t *testing.T) {
|
t.Run("invalid goamd64", func(t *testing.T) {
|
||||||
_, err := matrix(config.Build{
|
_, err := List(config.Build{
|
||||||
Goos: []string{"linux"},
|
Goos: []string{"linux"},
|
||||||
Goarch: []string{"amd64"},
|
Goarch: []string{"amd64"},
|
||||||
Goamd64: []string{"invalid"},
|
Goamd64: []string{"invalid"},
|
||||||
}, []byte("go version go1.18.0"))
|
})
|
||||||
require.EqualError(t, err, "invalid goamd64: invalid")
|
require.EqualError(t, err, "invalid goamd64: invalid")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -236,25 +236,4 @@ func TestList(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, []string{"linux_amd64_v2"}, targets)
|
require.Equal(t, []string{"linux_amd64_v2"}, targets)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("error with dir", func(t *testing.T) {
|
|
||||||
_, err := List(config.Build{
|
|
||||||
Goos: []string{"linux"},
|
|
||||||
Goarch: []string{"amd64"},
|
|
||||||
Goamd64: []string{"v2"},
|
|
||||||
GoBinary: "go",
|
|
||||||
Dir: "targets.go",
|
|
||||||
})
|
|
||||||
require.EqualError(t, err, "invalid builds.dir property, it should be a directory: targets.go")
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("fail", func(t *testing.T) {
|
|
||||||
_, err := List(config.Build{
|
|
||||||
Goos: []string{"linux"},
|
|
||||||
Goarch: []string{"amd64"},
|
|
||||||
Goamd64: []string{"v2"},
|
|
||||||
GoBinary: "nope",
|
|
||||||
})
|
|
||||||
require.EqualError(t, err, `unable to determine version of go binary (nope): exec: "nope": executable file not found in $PATH`)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user