|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +RED='\033[0;31m' |
| 4 | +GREEN='\033[0;32m' |
| 5 | +YELLOW='\033[0;33m' |
| 6 | +BLUE='\033[0;34m' |
| 7 | +BOLD='\033[1m' |
| 8 | +RESET='\033[0m' |
| 9 | + |
| 10 | +PIDS=() |
| 11 | +PID_LABELS=() |
| 12 | +PID_EXIT_CODES=() |
| 13 | + |
| 14 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 15 | +REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" |
| 16 | +TMP_DIR="$(mktemp -d)" |
| 17 | + |
| 18 | +trap 'rm -rf "${TMP_DIR}"' EXIT INT TERM |
| 19 | + |
| 20 | +run_labeled() { |
| 21 | + local label="$1" |
| 22 | + local color="$2" |
| 23 | + local cmd="$3" |
| 24 | + local exit_code_file="${TMP_DIR}/${label}.exit" |
| 25 | + |
| 26 | + ( |
| 27 | + set -o pipefail |
| 28 | + eval "${cmd}" 2>&1 | while IFS= read -r line; do |
| 29 | + printf "${BOLD}${color}[%s]${RESET} %s\n" "${label}" "${line}" |
| 30 | + done |
| 31 | + echo "${PIPESTATUS[0]}" > "${exit_code_file}" |
| 32 | + ) & |
| 33 | + |
| 34 | + PIDS+=($!) |
| 35 | + PID_LABELS+=("${label}") |
| 36 | +} |
| 37 | + |
| 38 | +check_pid_result() { |
| 39 | + local pid="$1" |
| 40 | + local label="$2" |
| 41 | + local exit_code_file="${TMP_DIR}/${label}.exit" |
| 42 | + local exit_code |
| 43 | + |
| 44 | + wait "${pid}" 2>/dev/null |
| 45 | + exit_code=$? |
| 46 | + |
| 47 | + if [ -f "${exit_code_file}" ]; then |
| 48 | + exit_code="$(cat "${exit_code_file}" 2>/dev/null || echo "${exit_code}")" |
| 49 | + fi |
| 50 | + |
| 51 | + if [ "${exit_code}" -eq 0 ]; then |
| 52 | + printf "${GREEN}✓${RESET} ${GREEN}%s${RESET}\n" "${label}" |
| 53 | + PID_EXIT_CODES+=(0) |
| 54 | + return 0 |
| 55 | + fi |
| 56 | + |
| 57 | + printf "${RED}✗${RESET} ${RED}%s${RESET}\n" "${label}" |
| 58 | + PID_EXIT_CODES+=(1) |
| 59 | + return 1 |
| 60 | +} |
| 61 | + |
| 62 | +START_TIME="$(date +%s)" |
| 63 | + |
| 64 | +printf "${BOLD}${BLUE}Starting concurrent commit checks...${RESET}\n\n" |
| 65 | +printf "${BOLD}Launching checks...${RESET}\n" |
| 66 | + |
| 67 | +run_labeled \ |
| 68 | + "rust:fmt" \ |
| 69 | + "${YELLOW}" \ |
| 70 | + "cd \"${REPO_ROOT}\" && cargo +nightly fmt -- --check" |
| 71 | + |
| 72 | +run_labeled \ |
| 73 | + "rust:clippy" \ |
| 74 | + "${GREEN}" \ |
| 75 | + "cd \"${REPO_ROOT}\" && cargo clippy --all-targets --all-features -- -D warnings" |
| 76 | + |
| 77 | +run_labeled \ |
| 78 | + "docs:mintlify" \ |
| 79 | + "${BLUE}" \ |
| 80 | + "cd \"${REPO_ROOT}/docs\" && mintlify broken-links" |
| 81 | + |
| 82 | +printf "\n${BOLD}Waiting for all checks to complete...${RESET}\n\n" |
| 83 | + |
| 84 | +FAILED_CHECKS=() |
| 85 | +PASSED_CHECKS=() |
| 86 | +ANY_FAILED=0 |
| 87 | + |
| 88 | +for i in "${!PIDS[@]}"; do |
| 89 | + pid="${PIDS[$i]}" |
| 90 | + label="${PID_LABELS[$i]}" |
| 91 | + |
| 92 | + if check_pid_result "${pid}" "${label}"; then |
| 93 | + PASSED_CHECKS+=("${label}") |
| 94 | + else |
| 95 | + FAILED_CHECKS+=("${label}") |
| 96 | + ANY_FAILED=1 |
| 97 | + fi |
| 98 | +done |
| 99 | + |
| 100 | +END_TIME="$(date +%s)" |
| 101 | +ELAPSED="$((END_TIME - START_TIME))" |
| 102 | + |
| 103 | +printf "\n${BOLD}${BLUE}========================================${RESET}\n" |
| 104 | +printf "${BOLD}${BLUE} SUMMARY${RESET}\n" |
| 105 | +printf "${BOLD}${BLUE}========================================${RESET}\n\n" |
| 106 | + |
| 107 | +if [ "${#PASSED_CHECKS[@]}" -gt 0 ]; then |
| 108 | + printf "${BOLD}${GREEN}✓ Passed checks (%s):${RESET}\n" "${#PASSED_CHECKS[@]}" |
| 109 | + for check in "${PASSED_CHECKS[@]}"; do |
| 110 | + printf " ${GREEN}✓${RESET} %s\n" "${check}" |
| 111 | + done |
| 112 | +fi |
| 113 | + |
| 114 | +if [ "${#FAILED_CHECKS[@]}" -gt 0 ]; then |
| 115 | + printf "\n${BOLD}${RED}✗ Failed checks (%s):${RESET}\n" "${#FAILED_CHECKS[@]}" |
| 116 | + for check in "${FAILED_CHECKS[@]}"; do |
| 117 | + printf " ${RED}✗${RESET} %s\n" "${check}" |
| 118 | + done |
| 119 | +fi |
| 120 | + |
| 121 | +printf "\n${BOLD}Time elapsed: %ss${RESET}\n" "${ELAPSED}" |
| 122 | + |
| 123 | +if [ "${ANY_FAILED}" -eq 1 ]; then |
| 124 | + printf "\n${BOLD}${RED}Commit checks failed!${RESET}\n" |
| 125 | + exit 1 |
| 126 | +fi |
| 127 | + |
| 128 | +printf "\n${BOLD}${GREEN}All commit checks passed!${RESET}\n" |
| 129 | +exit 0 |
0 commit comments