Skip to content

Commit

Permalink
Fix: create build dir if it's not present (elastic#39)
Browse files Browse the repository at this point in the history
* Fix: create missing build directory

* Fix
  • Loading branch information
mtojek authored Jul 31, 2020
1 parent 2d46c92 commit d4609f6
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion internal/builder/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ func buildPackage(sourcePath string) error {
return errors.Wrap(err, "locating build directory failed")
}
if !found {
return errors.New("build directory not found")
buildDir, err = createBuildPackagesDirectory()
if err != nil {
return errors.Wrap(err, "creating new build directory failed")
}
}

m, err := readPackageManifest(filepath.Join(sourcePath, packageManifestFile))
Expand Down Expand Up @@ -136,6 +139,33 @@ func buildPackage(sourcePath string) error {
return nil
}

func createBuildPackagesDirectory() (string, error) {
workDir, err := os.Getwd()
if err != nil {
return "", errors.Wrap(err, "locating working directory failed")
}

dir := workDir
for dir != "." {
path := filepath.Join(dir, ".git")
fileInfo, err := os.Stat(path)
if err == nil && fileInfo.IsDir() {
buildDir := filepath.Join(dir, "build", "integrations") // TODO add support for other package types
err = os.MkdirAll(buildDir, 0755)
if err != nil {
return "", errors.Wrapf(err, "mkdir failed (path: %s)", buildDir)
}
return buildDir, nil
}

if dir == "/" {
break
}
dir = filepath.Dir(dir)
}
return "", errors.New("locating place for build directory failed")
}

func readPackageManifest(path string) (*packageManifest, error) {
content, err := ioutil.ReadFile(path)
if err != nil {
Expand Down

0 comments on commit d4609f6

Please sign in to comment.