1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-11-06 09:09:29 +02:00

fix: build dir that dont exist yet (#2435)

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker
2021-08-31 22:42:15 -03:00
committed by GitHub
parent 55f420e9d1
commit b132d00aec
3 changed files with 36 additions and 1 deletions

View File

@@ -88,6 +88,36 @@ func TestWithDefaults(t *testing.T) {
},
goBinary: "go",
},
"empty with custom dir": {
build: config.Build{
ID: "foo2",
Binary: "foo",
Dir: "./testdata",
},
targets: []string{
"linux_amd64",
"linux_386",
"linux_arm64",
"darwin_amd64",
"darwin_arm64",
},
goBinary: "go",
},
"empty with custom dir that doest exist": {
build: config.Build{
ID: "foo2",
Binary: "foo",
Dir: "./nope",
},
targets: []string{
"linux_amd64",
"linux_386",
"linux_arm64",
"darwin_amd64",
"darwin_arm64",
},
goBinary: "go",
},
} {
t.Run(name, func(t *testing.T) {
if testcase.build.GoBinary != "" && testcase.build.GoBinary != "go" {

View File

@@ -2,6 +2,7 @@ package golang
import (
"fmt"
"os"
"os/exec"
"regexp"
"strings"
@@ -133,7 +134,11 @@ var (
func goVersion(build config.Build) ([]byte, error) {
cmd := exec.Command(build.GoBinary, "version")
cmd.Dir = build.Dir // Set Dir to build directory in case of reletive path to GoBinary
// If the build.Dir is acessible, set the cmd dir to it in case
// of reletive path to GoBinary
if _, err := os.Stat(build.Dir); err == nil {
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)

View File