1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-11 14:39:28 +02:00

fix: check if builds.dir is a directory (#2587)

* fix: validate builds.main

* fix: pr comments
This commit is contained in:
Pedro López Mareque 2021-10-17 02:42:53 +02:00 committed by GitHub
parent 870dc146fa
commit 160d97af40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -147,7 +147,10 @@ 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 _, err := os.Stat(build.Dir); err == nil {
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()

View File

@ -271,6 +271,16 @@ func TestList(t *testing.T) {
require.Equal(t, []string{"linux_amd64"}, targets)
})
t.Run("error with dir", func(t *testing.T) {
_, err := List(config.Build{
Goos: []string{"linux"},
Goarch: []string{"amd64"},
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"},