Files
lab-console-git-branching-1/tools/card-action.sh
T

13 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
action="${1:?action required}"; root="${STEM_REPO:-$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)}"; profile="${STEM_PROFILE:-native-amd64}"; target="${STEM_TARGET:-native}"; selector="${STEM_TASK:-task1}"
tasks=(task01_create_and_switch task02_divergent_work task03_merge_completed_work)
resolve_task(){ local value="${1,,}" name; for name in "${tasks[@]}"; do [[ "$value" == "$name" ]] && { printf '%s\n' "$name"; return; }; done; [[ "$value" =~ ^(task|t)?[-_]?0*([1-3])($|[-_].*) ]] && { printf '%s\n' "${tasks[${BASH_REMATCH[2]} - 1]}"; return; }; exit 2; }
task="$(resolve_task "$selector")"; artifact_dir="$root/.stem/artifacts/$profile/$target/$task"; mkdir -p "$artifact_dir"
case "$profile:$target:$action" in
native-amd64:native:build) bash -n "$root"/src/tasks/*.sh "$root/tests/test_tasks.sh"; command -v git >/dev/null; printf 'BUILD tasks=3 git=%s\n' "$(git --version | tr ' ' '-')" ;;
native-amd64:native:test|native-amd64:native:run) exec env CARD_ROOT="$root" "$root/tests/test_tasks.sh" "$task" ;;
native-amd64:native:debug) trace_file="$artifact_dir/trace.log"; set +e; env CARD_ROOT="$root" bash -x "$root/tests/test_tasks.sh" "$task" >"$trace_file" 2>&1; status=$?; set -e; cat "$trace_file"; [[ $status -eq 0 && -s "$trace_file" ]]; printf 'TRACE %s log=%s\n' "$task" "$trace_file" ;;
*) exit 2 ;;
esac