Repository: goreleaser/goreleaser
Pull request #1775 (2020-08-29 17:24:22)

feat: Add `gobinary` option to build configs.
If applied, this commit will add a `gobinary` option to the build config allowing specification of specific go binaries to use during a build.

The change is being made because it was listed in #1235 as requested.

See: #1235 for further details.


vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.


codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1775?src=pr&el=h1) Report
> Merging [#1775](https://codecov.io/gh/goreleaser/goreleaser/pull/1775?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/37b2f42b9325012fd0a8373d4e4f9fb6c4bc58f1?el=desc) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/1775/graphs/tree.svg?width=650&height=150&src=pr&token=3bJvv6b7hN)](https://codecov.io/gh/goreleaser/goreleaser/pull/1775?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #1775   +/-   ##
=======================================
  Coverage   82.54%   82.55%           
=======================================
  Files          72       72           
  Lines        4177     4179    +2     
=======================================
+ Hits         3448     3450    +2     
  Misses        608      608           
  Partials      121      121           
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/1775?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/config/config.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1775/diff?src=pr&el=tree#diff-cGtnL2NvbmZpZy9jb25maWcuZ28=) | `94.44% <ø> (ø)` | |
| [internal/builders/golang/build.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1775/diff?src=pr&el=tree#diff-aW50ZXJuYWwvYnVpbGRlcnMvZ29sYW5nL2J1aWxkLmdv) | `94.66% <100.00%> (+0.07%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1775?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1775?src=pr&el=footer). Last update [37b2f42...8b977fc](https://codecov.io/gh/goreleaser/goreleaser/pull/1775?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/internal/builders/golang/build.go b/internal/builders/golang/build.go
index 9f9ea1cf..b49bf3ad 100644
--- a/internal/builders/golang/build.go
+++ b/internal/builders/golang/build.go
@@ -56,6 +56,9 @@ func (*Builder) WithDefaults(build config.Build) config.Build {
 	if len(build.Targets) == 0 {
 		build.Targets = matrix(build)
 	}
+	if build.GoBinary == "" {
+		build.GoBinary = "go"
+	}
 	return build
 }
 
@@ -69,7 +72,7 @@ func (*Builder) Build(ctx *context.Context, build config.Build, options api.Opti
 		return err
 	}
 
-	var cmd = []string{"go", "build"}
+	var cmd = []string{build.GoBinary, "build"}
 
 	var env = append(ctx.Env.Strings(), build.Env...)
 	env = append(env, target.Env()...)
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 2421d6e1..fa8fb702 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -201,6 +201,7 @@ type Build struct {
 	Gcflags      StringArray    `yaml:",omitempty"`
 	ModTimestamp string         `yaml:"mod_timestamp,omitempty"`
 	Skip         bool           `yaml:",omitempty"`
+	GoBinary     string         `yaml:",omitempty"`
 }
 
 type HookConfig struct {
diff --git a/www/docs/customization/build.md b/www/docs/customization/build.md
index 97647554..971e9e63 100644
--- a/www/docs/customization/build.md
+++ b/www/docs/customization/build.md
@@ -101,6 +101,11 @@ builds:
       - goarm: mips64
         gomips: hardfloat
 
+    # Set a specific go binary to use when building. It is safe to ignore
+    # this option in most cases.
+    # Default is "go"
+    gobinary: "go1.13.4"
+
     # Set the modified timestamp on the output binary, typically
     # you would do this to ensure a build was reproducible. Pass
     # empty string to skip modifying the output.


Test patch:
diff --git a/internal/builders/golang/build_test.go b/internal/builders/golang/build_test.go
index bcf0d8a9..847bed7a 100644
--- a/internal/builders/golang/build_test.go
+++ b/internal/builders/golang/build_test.go
@@ -24,8 +24,9 @@ var runtimeTarget = runtime.GOOS + "_" + runtime.GOARCH
 
 func TestWithDefaults(t *testing.T) {
 	for name, testcase := range map[string]struct {
-		build   config.Build
-		targets []string
+		build    config.Build
+		targets  []string
+		goBinary string
 	}{
 		"full": {
 			build: config.Build{
@@ -47,6 +48,7 @@ func TestWithDefaults(t *testing.T) {
 				Gomips: []string{
 					"softfloat",
 				},
+				GoBinary: "go1.2.3",
 			},
 			targets: []string{
 				"linux_amd64",
@@ -55,6 +57,7 @@ func TestWithDefaults(t *testing.T) {
 				"windows_amd64",
 				"linux_arm_6",
 			},
+			goBinary: "go1.2.3",
 		},
 		"empty": {
 			build: config.Build{
@@ -66,6 +69,7 @@ func TestWithDefaults(t *testing.T) {
 				"linux_386",
 				"darwin_amd64",
 			},
+			goBinary: "go",
 		},
 	} {
 		t.Run(name, func(tt *testing.T) {
@@ -78,6 +82,7 @@ func TestWithDefaults(t *testing.T) {
 			ctx.Git.CurrentTag = "5.6.7"
 			var build = Default.WithDefaults(ctx.Config.Builds[0])
 			assert.ElementsMatch(t, build.Targets, testcase.targets)
+			assert.EqualValues(t, testcase.goBinary, build.GoBinary)
 		})
 	}
 }
@@ -104,6 +109,7 @@ func TestBuild(t *testing.T) {
 				Asmflags: []string{".=", "all="},
 				Gcflags:  []string{"all="},
 				Flags:    []string{"{{.Env.GO_FLAGS}}"},
+				GoBinary: "go",
 			},
 		},
 	}
@@ -259,6 +265,7 @@ func TestBuildCodeInSubdir(t *testing.T) {
 				Targets: []string{
 					runtimeTarget,
 				},
+				GoBinary: "go",
 			},
 		},
 	}
@@ -286,6 +293,7 @@ func TestBuildFailed(t *testing.T) {
 				Targets: []string{
 					runtimeTarget,
 				},
+				GoBinary: "go",
 			},
 		},
 	}
@@ -476,6 +484,7 @@ func TestRunPipeWithMainFuncNotInMainGoFile(t *testing.T) {
 				Targets: []string{
 					runtimeTarget,
 				},
+				GoBinary: "go",
 			},
 		},
 	}
@@ -643,6 +652,7 @@ func TestBuildModTimestamp(t *testing.T) {
 				Gcflags:      []string{"all="},
 				Flags:        []string{"{{.Env.GO_FLAGS}}"},
 				ModTimestamp: fmt.Sprintf("%d", modTime.Unix()),
+				GoBinary:     "go",
 			},
 		},
 	}
diff --git a/internal/pipe/blob/blob_minio_test.go b/internal/pipe/blob/blob_minio_test.go
index 050ef326..910c39a9 100644
--- a/internal/pipe/blob/blob_minio_test.go
+++ b/internal/pipe/blob/blob_minio_test.go
@@ -272,7 +272,8 @@ func start(t *testing.T, name, listen string) {
 		"-e", "MINIO_ACCESS_KEY=minio",
 		"-e", "MINIO_SECRET_KEY=miniostorage",
 		"--health-interval", "1s",
-		"minio/minio:RELEASE.2019-05-14T23-57-45Z",
+		"--health-cmd=curl --silent --fail http://localhost:9000/minio/health/ready || exit 1",
+		"minio/minio",
 		"server", "/data",
 	).CombinedOutput(); err != nil {
 		t.Fatalf("failed to start minio: %s", string(out))