Skip to content

Commit

Permalink
cache build
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas-goenka committed Jan 22, 2025
1 parent 0d6b3e4 commit 25831e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
File renamed without changes.
24 changes: 6 additions & 18 deletions internal/testutil/build_cli.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
package testutil

import (
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
"time"

"github.com/databricks/cli/libs/folders"
"github.com/stretchr/testify/require"
)

func findRoot(t *testing.T) string {
curr, err := os.Getwd()
require.NoError(t, err)

for curr != filepath.Dir(curr) {
if _, err := os.Stat(filepath.Join(curr, "go.mod")); err == nil {
return curr
}
curr = filepath.Dir(curr)
}
require.Fail(t, "could not find root directory")
return ""
}

func BuildCLI(t *testing.T, flags ...string) string {
tmpDir := t.TempDir()
repoRoot, err := folders.FindDirWithLeaf(".", ".git")
require.NoError(t, err)

execPath := filepath.Join(tmpDir, "build", "databricks")
// Stable path for the CLI binary. This ensures fast builds and cache reuse.
execPath := filepath.Join(repoRoot, "internal", "testutil", "build", "databricks")
if runtime.GOOS == "windows" {
execPath += ".exe"
}
Expand All @@ -51,7 +39,7 @@ func BuildCLI(t *testing.T, flags ...string) string {
}

cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = findRoot(t)
cmd.Dir = repoRoot
out, err := cmd.CombinedOutput()
elapsed := time.Since(start)
t.Logf("%s took %s", args, elapsed)
Expand Down

0 comments on commit 25831e3

Please sign in to comment.