Repository: goreleaser/goreleaser
Pull request #3248 (2022-07-21 12:17:13)

refactor(build): remove unused param
we dont need to check the go version anymore, so we can remove all this
now.


codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/3248?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#3248](https://codecov.io/gh/goreleaser/goreleaser/pull/3248?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (7405594) into [main](https://codecov.io/gh/goreleaser/goreleaser/commit/7aeebb12f238d9185b213b961d0bad654d504c62?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (7aeebb1) will **decrease** coverage by `0.03%`.
> The diff coverage is `n/a`.

```diff
@@            Coverage Diff             @@
##             main    #3248      +/-   ##
==========================================
- Coverage   84.29%   84.26%   -0.04%     
==========================================
  Files         115      115              
  Lines        9322     9302      -20     
==========================================
- Hits         7858     7838      -20     
  Misses       1183     1183              
  Partials      281      281              
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/3248?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) | Coverage Δ | |
|---|---|---|
| [internal/builders/buildtarget/targets.go](https://codecov.io/gh/goreleaser/goreleaser/pull/3248/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-aW50ZXJuYWwvYnVpbGRlcnMvYnVpbGR0YXJnZXQvdGFyZ2V0cy5nbw==) | `100.00% <ø> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/3248?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/3248?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Last update [7aeebb1...7405594](https://codecov.io/gh/goreleaser/goreleaser/pull/3248?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).


Patch:
diff --git a/internal/builders/buildtarget/targets.go b/internal/builders/buildtarget/targets.go
index d30d5b4d..e4d07ceb 100644
--- a/internal/builders/buildtarget/targets.go
+++ b/internal/builders/buildtarget/targets.go
@@ -4,8 +4,6 @@ package buildtarget
 
 import (
 	"fmt"
-	"os"
-	"os/exec"
 	"strings"
 
 	"github.com/caarlos0/log"
@@ -25,14 +23,6 @@ func (t target) String() string {
 
 // List compiles the list of targets for the given builds.
 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
 	var targets []target
 	// nolint:prealloc
@@ -135,23 +125,6 @@ func ignored(build config.Build, target target) bool {
 	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 {
 	return contains(target.os+target.arch, validTargets)
 }


Test patch:
diff --git a/internal/builders/buildtarget/targets_test.go b/internal/builders/buildtarget/targets_test.go
index 9b4f8179..a2f11164 100644
--- a/internal/builders/buildtarget/targets_test.go
+++ b/internal/builders/buildtarget/targets_test.go
@@ -67,7 +67,7 @@ func TestAllBuildTargets(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.Equal(t, []string{
 			"linux_386",
@@ -111,46 +111,46 @@ func TestAllBuildTargets(t *testing.T) {
 	})
 
 	t.Run("invalid goos", func(t *testing.T) {
-		_, err := matrix(config.Build{
+		_, err := List(config.Build{
 			Goos:    []string{"invalid"},
 			Goarch:  []string{"amd64"},
 			Goamd64: []string{"v2"},
-		}, []byte("go version go1.18.0"))
+		})
 		require.EqualError(t, err, "invalid goos: invalid")
 	})
 
 	t.Run("invalid goarch", func(t *testing.T) {
-		_, err := matrix(config.Build{
+		_, err := List(config.Build{
 			Goos:   []string{"linux"},
 			Goarch: []string{"invalid"},
-		}, []byte("go version go1.18.0"))
+		})
 		require.EqualError(t, err, "invalid goarch: invalid")
 	})
 
 	t.Run("invalid goarm", func(t *testing.T) {
-		_, err := matrix(config.Build{
+		_, err := List(config.Build{
 			Goos:   []string{"linux"},
 			Goarch: []string{"arm"},
 			Goarm:  []string{"invalid"},
-		}, []byte("go version go1.18.0"))
+		})
 		require.EqualError(t, err, "invalid goarm: invalid")
 	})
 
 	t.Run("invalid gomips", func(t *testing.T) {
-		_, err := matrix(config.Build{
+		_, err := List(config.Build{
 			Goos:   []string{"linux"},
 			Goarch: []string{"mips"},
 			Gomips: []string{"invalid"},
-		}, []byte("go version go1.18.0"))
+		})
 		require.EqualError(t, err, "invalid gomips: invalid")
 	})
 
 	t.Run("invalid goamd64", func(t *testing.T) {
-		_, err := matrix(config.Build{
+		_, err := List(config.Build{
 			Goos:    []string{"linux"},
 			Goarch:  []string{"amd64"},
 			Goamd64: []string{"invalid"},
-		}, []byte("go version go1.18.0"))
+		})
 		require.EqualError(t, err, "invalid goamd64: invalid")
 	})
 }
@@ -236,25 +236,4 @@ func TestList(t *testing.T) {
 		require.NoError(t, err)
 		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`)
-	})
 }