Skip to content

Commit

Permalink
fix: build dir that dont exist yet (#2435)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Sep 1, 2021
1 parent 55f420e commit b132d00
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
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 {
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.

1 comment on commit b132d00

@vercel
Copy link

@vercel vercel bot commented on b132d00 Sep 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.