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
15 changes: 14 additions & 1 deletion clerk/project-gate
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@ operation=${1:-}
request=$(cat)
worktree=$(printf '%s' "$request" | jq -er '.delivery.worktree')

if (cd "$worktree" && bats tests/clerk && shellcheck -S error bin/*) >&2; then
cpus=$(getconf _NPROCESSORS_ONLN 2>/dev/null || printf '1')
case "$cpus" in
"" | *[!0-9]*) cpus=1 ;;
esac
jobs=$((cpus / 2))
[ "$jobs" -ge 1 ] || jobs=1

if command -v parallel >/dev/null 2>&1 || command -v rush >/dev/null 2>&1; then
bats_command=(bats --jobs "$jobs" tests/clerk)
else
bats_command=(bats tests/clerk)
fi

if (cd "$worktree" && "${bats_command[@]}" && shellcheck -S error bin/*) >&2; then
status=passed
summary='bats tests/clerk and shellcheck -S error bin/* passed'
else
Expand Down
27 changes: 27 additions & 0 deletions tests/clerk/gate-submit.bats
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,33 @@ claimable_work() { # $1=repo
printf '%s' "$output" | jq -e '.[0].status == "closed"' >/dev/null
}

@test "the dotfiles synchronous adapter runs Bats on half the available CPUs" {
worktree="$BATS_TEST_TMPDIR/worktree"
mkdir -p "$worktree/bin" "$worktree/tests/clerk"
export BATS_ARGS="$BATS_TEST_TMPDIR/bats.args"
cat >"$STUB_BIN/bats" <<'SH'
#!/usr/bin/env bash
printf '%s\n' "$*" >"$BATS_ARGS"
SH
cat >"$STUB_BIN/shellcheck" <<'SH'
#!/usr/bin/env bash
exit 0
SH
chmod +x "$STUB_BIN/bats" "$STUB_BIN/shellcheck"
git init -q -b main "$worktree"
git -C "$worktree" config user.email clerk@test
git -C "$worktree" config user.name clerk
: >"$worktree/bin/tool"
git -C "$worktree" add . && git -C "$worktree" commit -q -m fixture

run bash -c 'printf "%s" "{\"delivery\":{\"worktree\":\"$1\"}}" | "$2" run' _ "$worktree" "$BATS_TEST_DIRNAME/../../clerk/project-gate"
[ "$status" -eq 0 ]
cpus=$(getconf _NPROCESSORS_ONLN)
jobs=$((cpus / 2))
[ "$jobs" -ge 1 ] || jobs=1
[ "$(cat "$BATS_ARGS")" = "--jobs $jobs tests/clerk" ]
}

@test "the dotfiles synchronous adapter translates selected command failure to a terminal verdict" {
worktree="$BATS_TEST_TMPDIR/worktree"
mkdir -p "$worktree/bin" "$worktree/tests/clerk"
Expand Down
Loading