#!/bin/bash set -euo pipefail cd "$(dirname "$0")/../.." temp=${TMPDIR:-/tmp} work=$(mktemp -d "${temp%/}/task-dispatch.XXXXXX") trap 'rm -rf "$work"' EXIT mkdir -p "$work/Scripts" "$work/bin" cp mise.toml lefthook.yml "$work/" # The isolated dispatcher uses mock executables, not mise's pinned scanners. python3 -I - "$work/mise.toml" <<'PY' import sys from pathlib import Path config = Path(sys.argv[1]) text = config.read_text() start = text.index('[tools]\n') end = text.index('\n[tasks.', start) config.write_text(text[:start] + text[end:]) PY cp Scripts/app-task.sh "$work/Scripts/" cat > "$work/Scripts/test-unit.sh" <<'MOCK' #!/bin/bash set -euo pipefail printf '%s\n' test "$@" >> "$TASK_LOG" MOCK for command in bundle check-bundle lint; do # shellcheck disable=SC2016 printf '#!/bin/bash\nset -euo pipefail\nprintf "%%s\\n" "%s" "$@" >> "$TASK_LOG"\n' "$command" > "$work/Scripts/$command.sh" done cat > "$work/Scripts/swift-build.sh" <<'MOCK' #!/bin/sh set -eu exec swift build "$@" MOCK cat > "$work/Scripts/test-lane.sh" <<'MOCK' #!/bin/sh set -eu printf '%s\n' inventory >> "$TASK_LOG" MOCK cat > "$work/Scripts/check-ci-audits.sh" <<'MOCK' #!/bin/bash set -euo pipefail printf '%s\n' audit "$@" >> "$TASK_LOG" exit "${AUDIT_STATUS:-0}" MOCK cat > "$work/bin/gitleaks" <<'MOCK' #!/bin/bash set -euo pipefail printf '%s\n' gitleaks "$@" >> "$TASK_LOG" exit "${SECRET_STATUS:-0}" MOCK for command in open swift; do # shellcheck disable=SC2016 printf '#!/bin/bash\nset -euo pipefail\nprintf "%%s\\n" "%s" "$@" >> "$TASK_LOG"\n' "$command" > "$work/bin/$command" done chmod +x "$work/Scripts/"*.sh "$work/bin/"* export PATH="$work/bin:$PATH" MISE_TRUSTED_CONFIG_PATHS="$work" TASK_LOG="$work/log" cd "$work" project=$PWD mise run build -- -c release printf '%s\n' swift build -c release > "$work/expected" cmp "$work/expected" "$TASK_LOG" printf '' > "$TASK_LOG" mise run check-app release printf '%s\n' bundle release check-bundle > "$work/expected" cmp "$work/expected" "$TASK_LOG" printf '' > "$TASK_LOG" mise run run debug printf '%s\n' bundle debug open build/Parcel.app > "$work/expected" cmp "$work/expected" "$TASK_LOG" printf '' > "$TASK_LOG" mise run test -- --filter 'One suite' grep -Fxq -- '--filter' "$TASK_LOG" grep -Fxq -- 'One suite' "$TASK_LOG" printf '' > "$TASK_LOG" mise run test:serial grep -Fxq -- '--no-parallel' "$TASK_LOG" printf '' > "$TASK_LOG" mise run check build_line=$(grep -n -m 1 -Fx build "$TASK_LOG" | cut -d: -f1) test_line=$(grep -n -m 1 -Fx test "$TASK_LOG" | cut -d: -f1) lint_line=$(grep -n -m 1 -Fx lint "$TASK_LOG" | cut -d: -f1) [[ $build_line -lt $test_line && $test_line -lt $lint_line ]] printf '' > "$TASK_LOG" mise run audit printf '%s\n' gitleaks git --redact --report-format sarif --report-path build/gitleaks.sarif . audit "$project" "$project/build/ci-audits" > "$work/expected" diff -u "$work/expected" "$TASK_LOG" for gate in SECRET AUDIT; do printf '' > "$TASK_LOG" status=0 env "${gate}_STATUS=9" mise run audit > "$work/failure.log" 2>&1 || status=$? [[ $status != 0 ]] if [[ $gate == SECRET ]] && grep -Fxq audit "$TASK_LOG"; then printf 'Audit continued after the secret scan failed.\n' >&2 exit 1 fi done printf '' > "$TASK_LOG" mise run check:push printf 'inventory\nlint\n' > "$work/expected" cmp "$work/expected" "$TASK_LOG" python3 -I - lefthook.yml <<'PY' import sys from pathlib import Path hook = Path(sys.argv[1]).read_text().split('pre-push:\n', 1)[1] assert 'run: mise run check:push' in hook assert 'run: mise run check\n' not in hook and 'mise run test:scripts' not in hook PY printf 'Task dispatch checks passed: 10\n'