28 lines
1.1 KiB
Bash
Executable File
28 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
if [[ "$#" -ne 1 || ! "$1" =~ ^(TASK-|BS-)?([0-9]{3})$ ]]; then
|
|
echo 'Usage: ./scripts/testtask.sh TASK-XXX (for example: TASK-001)' >&2
|
|
exit 2
|
|
fi
|
|
task="${BASH_REMATCH[2]}"
|
|
branch="$(git -C "$root" branch --show-current)"
|
|
if [[ -f "$root/.roborto/testtask.conf" && "$branch" == "bs-$task" ]]; then
|
|
if ! command -v roborto-testtask >/dev/null 2>&1; then
|
|
echo 'testtask: standalone roborto-testtask CLI is missing.' >&2
|
|
exit 127
|
|
fi
|
|
mkdir -p "$root/.test-worktrees"
|
|
exec 8>"$root/.test-worktrees/session.lock"
|
|
flock -n 8 || { echo 'testtask: another test session is running in this worktree.' >&2; exit 1; }
|
|
cd "$root"
|
|
exec roborto-testtask "$task"
|
|
fi
|
|
candidate="$root/.task-worktrees/bs-$task"
|
|
if [[ ! -x "$candidate/scripts/testtask.sh" ]]; then
|
|
echo "testtask: TASK-$task maps to BS-$task; no prepared task worktree at $candidate" >&2
|
|
exit 1
|
|
fi
|
|
printf 'testtask: TASK-%s -> BS-%s (%s)\n' "$task" "$task" "$candidate"
|
|
exec "$candidate/scripts/testtask.sh" "TASK-$task"
|