Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions scripts/check-affected.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
# the checks there. Nothing is written under .git, so the checkout's HEAD,
# index and worktree list stay as they are. With CHECK_AFFECTED_SCRIPT_EXEC_BIT=1
# (the issue lane's patch run) that commit makes each new or changed .sh or #!
# file executable, as apply-patch will.
# file executable, as apply-patch will. --tests runs the suites from this tree,
# whose work tree holds the same edits, not the scratch one, which has no
# node_modules.
#
# Each check calls the script or tool CI calls; none restates a check's logic
# but machine-specific-paths, whose entry script is in ci-workflows, not here:
Expand Down Expand Up @@ -193,11 +195,18 @@ if ((uncommitted)); then
git -C "$snap/tree" -c core.hooksPath=/dev/null checkout --quiet --detach "$commit" || exit 2
args=(--base "$base" --no-fetch --jobs "$jobs")
((run_tests)) && args+=(--tests)
# A snapshot of this tree's own work tree is no foreign code, so the inner
# run's tests run here, where the selector reads the same uncommitted edits.
own=
[[ "$(pwd -P)" != "$tools" ]] || own="$tools"
rc=0
CHECK_DATA_ROOT="$snap/tree" bash "$tools/scripts/check-affected.sh" "${args[@]}" || rc=$?
CHECK_AFFECTED_SNAPSHOT_OF="$own" CHECK_DATA_ROOT="$snap/tree" bash "$tools/scripts/check-affected.sh" "${args[@]}" || rc=$?
exit "$rc"
fi
base="${base:-origin/main}"
snapshot=0
[[ -z "${CHECK_AFFECTED_SNAPSHOT_OF-}" || "$CHECK_AFFECTED_SNAPSHOT_OF" != "$tools" ]] || snapshot=1
Comment thread
kyle-sexton marked this conversation as resolved.
Resolved
unset CHECK_AFFECTED_SNAPSHOT_OF
foreign=0
if [[ "$(pwd -P)" != "$tools" ]]; then
foreign=1
Expand Down Expand Up @@ -570,7 +579,7 @@ else
"$tools/scripts/check-changed-skills.sh" "$base"
fi

if ((run_tests && foreign)); then
if ((run_tests && foreign && !snapshot)); then
skip tests "runs the checked tree's own test code"
elif ((run_tests)); then
# Suites load the locked npm packages, which a fresh worktree lacks or a
Expand All @@ -579,7 +588,7 @@ elif ((run_tests)); then
# could not run (npm or nice missing) is a SKIP, and the suites still run.
npm_failed=0
rc=0
bash "$tools/scripts/setup-env.sh" --node >"$out" 2>&1 || rc=$?
bash "$tools/scripts/setup-env.sh" --node --root "$tools" >"$out" 2>&1 || rc=$?
if ((rc == 0)); then
grep '^setup-env: installed' "$out" >&2
elif ((rc == 2 || rc == 127)); then
Expand Down
11 changes: 11 additions & 0 deletions scripts/check-affected.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ cat >"$repo/scripts/affected-tests.sh" <<'STUB'
#!/usr/bin/env bash
echo "affected-tests ran" >&2
[[ -z "${STUB_ENV_LOG:-}" ]] || printf '%s' "${CHECK_DATA_ROOT-unset}" >"$STUB_ENV_LOG"
# The real selector diffs its own tree's work tree, so the stub logs that.
[[ -z "${STUB_STATUS_LOG:-}" ]] || git -C "$(dirname "$0")/.." status --porcelain --untracked-files=all >"$STUB_STATUS_LOG"
[[ -v CHECK_DATA_ROOT ]] && { echo "affected-tests saw CHECK_DATA_ROOT" >&2; exit 1; }
while (($#)); do
[[ "$1" == --write-not-run ]] && printf '%s' "${STUB_NOT_RUN:-}" >"$2"
Expand Down Expand Up @@ -488,6 +490,15 @@ chmod +x "$repo/new-tool"
run -- --uncommitted
check "--uncommitted passes once the file is executable on disk" \
'[[ $RC == 0 && $OUT == *"over 1 changed files"* ]]'
# The snapshot is this tree's own work tree, so --tests selects from that work
# tree, uncommitted edits included, as a committed run selects from its diff.
run STUB_STATUS_LOG="$tmp/status.log" -- --uncommitted --tests
check "--uncommitted --tests runs the suites over the uncommitted change" \
'[[ $RC == 0 && $ERR != *"SKIP tests"* && $(cat "$tmp/status.log" 2>/dev/null) == *"?? new-tool"* ]]'
RC=0
ERR="$(cd "$tmp" && CHECK_DATA_ROOT="$repo" bash "$tools/scripts/check-affected.sh" --uncommitted --tests 2>&1)" || RC=$?
check "a copy's --uncommitted --tests run still skips the checked tree's tests" \
'[[ $ERR == *"SKIP tests (runs the checked tree"* && $ERR != *"copy of affected-tests"* ]]'
mkdir -p "$repo/plugins/demo"
printf 'x\n' >"$repo/plugins/demo/new.md"
printf '#!/usr/bin/env bash\necho "validate-plugins ran: $*" >&2\nexit 1\n' >"$repo/scripts/validate-plugins.sh"
Expand Down
Loading