diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 593b0ad822..4f39093beb 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -137,6 +137,21 @@ jobs: with: cache-key: test-${{ matrix.deployment }} + # Make origin/main available with enough history for `git diff --merge-base + # origin/main`, which the acceptance subset selector uses to always run the + # tests this PR adds/changes on the windows/macOS cells. actions/checkout does + # a shallow single-ref clone by default, so origin/main is otherwise absent and + # the diff fails, silently disabling change detection. This must run AFTER + # setup-build-environment, whose own checkout would re-shallow the repo. Only + # PRs subset tests, so the fetch is unnecessary elsewhere. + - name: Fetch origin/main for change detection + if: ${{ github.event_name == 'pull_request' }} + run: | + git fetch --no-tags origin +refs/heads/main:refs/remotes/origin/main + if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then + git fetch --no-tags --unshallow origin + fi + - name: Run tests env: ENVFILTER: DATABRICKS_BUNDLE_ENGINE=${{ matrix.deployment }} diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index ae650a19dd..2c9c2b31a1 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -450,7 +450,7 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int { // subset selector keep these tests, so detect them at most once here. var changedTests map[string][]string if skipLocalWithChanged || subset.enabled { - changedTests = selectChangedLocalTests(testDirsSet) + changedTests = selectChangedLocalTests(t, testDirsSet) } subset.changed = changedTests diff --git a/acceptance/skiplocal_test.go b/acceptance/skiplocal_test.go index c72f7c39a3..a16de1f0ef 100644 --- a/acceptance/skiplocal_test.go +++ b/acceptance/skiplocal_test.go @@ -1,10 +1,12 @@ package acceptance_test import ( + "errors" "os/exec" "path/filepath" "slices" "strings" + "testing" ) // DATABRICKS_TEST_SKIPLOCAL controls skipping of Local acceptance tests. @@ -61,8 +63,21 @@ func testDirForFile(repoRelPath string, testDirs map[string]bool) string { // committed. The three-dot form origin/main...HEAD only covers committed // changes and misses unstaged edits, which breaks the "touch a config, run // the test" local dev workflow (same reason lintdiff.py uses --merge-base). -func selectChangedLocalTests(testDirs map[string]bool) map[string][]string { - out, _ := exec.Command("git", "diff", "--name-status", "--merge-base", "-M", "origin/main").Output() +func selectChangedLocalTests(t *testing.T, testDirs map[string]bool) map[string][]string { + out, err := exec.Command("git", "diff", "--name-status", "--merge-base", "-M", "origin/main").Output() + if err != nil { + // A failed diff (most commonly a missing origin/main in a shallow CI + // checkout) disables change detection, so newly added tests fall back to + // the seeded subset and may not run. Log loudly but continue: failing the + // test here breaks integration runs whose checkout has no origin/main. The + // push.yml PR cells fetch full history so origin/main resolves there. + stderr := "" + if exitErr, ok := errors.AsType[*exec.ExitError](err); ok { + stderr = strings.TrimSpace(string(exitErr.Stderr)) + } + t.Logf("WARNING: change detection disabled: git diff --merge-base origin/main failed: %v\n%s", err, stderr) + return nil + } diff := strings.TrimSpace(string(out)) // result accumulates dirs with their filters; added tracks brand-new dirs.