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 package testutil
import ( import (
"os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
"testing" "testing"
"time" "time"
"github.com/databricks/cli/libs/folders"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func findRoot(t *testing.T) string { func BuildCLI(t *testing.T, flags ...string) string {
curr, err := os.Getwd() repoRoot, err := folders.FindDirWithLeaf(".", ".git")
require.NoError(t, err) require.NoError(t, err)
for curr != filepath.Dir(curr) { // Stable path for the CLI binary. This ensures fast builds and cache reuse.
if _, err := os.Stat(filepath.Join(curr, "go.mod")); err == nil { execPath := filepath.Join(repoRoot, "internal", "testutil", "build", "databricks")
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")
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
execPath += ".exe" execPath += ".exe"
} }
@ -51,7 +39,7 @@ func BuildCLI(t *testing.T, flags ...string) string {
} }
cmd := exec.Command(args[0], args[1:]...) cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = findRoot(t) cmd.Dir = repoRoot
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
elapsed := time.Since(start) elapsed := time.Since(start)
t.Logf("%s took %s", args, elapsed) t.Logf("%s took %s", args, elapsed)