Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: build dir that dont exist yet #2435

Merged
merged 1 commit into from Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions internal/builders/golang/build_test.go
Expand Up @@ -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" {
Expand Down
7 changes: 6 additions & 1 deletion internal/builders/golang/targets.go
Expand Up @@ -2,6 +2,7 @@ package golang

import (
"fmt"
"os"
"os/exec"
"regexp"
"strings"
Expand Down Expand Up @@ -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 {
caarlos0 marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down
Empty file.