cache build

This commit is contained in:
Shreyas Goenka 2025-01-22 21:52:27 +01:00
parent 0d6b3e4a96
commit 25831e3432
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
2 changed files with 6 additions and 18 deletions

View File

@ -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()
func BuildCLI(t *testing.T, flags ...string) string {
repoRoot, err := folders.FindDirWithLeaf(".", ".git")
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()
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"
}
@ -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)