-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
Β·133 lines (112 loc) Β· 3.51 KB
/
pre-commit
File metadata and controls
executable file
Β·133 lines (112 loc) Β· 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bash
#
# Git pre-commit hook that runs all CI checks
# This hook dynamically reads the GitHub Actions workflow file and executes
# the same lint and test commands that run in CI.
#
# This hook is installed automatically by the Claude Code session-start hook
# IMPORTANT: These checks mirror CI - if they fail here, the PR will fail CI.
# Always fix the issues rather than bypassing this hook.
#
set -e
echo "π Running pre-commit checks..."
echo ""
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored status messages
print_status() {
echo -e "${GREEN}β${NC} $1"
}
print_error() {
echo -e "${RED}β${NC} $1"
}
print_warning() {
echo -e "${YELLOW}β ${NC} $1"
}
print_info() {
echo -e "${BLUE}βΉ${NC} $1"
}
# Check if uv is available
if ! command -v uv &> /dev/null; then
print_error "uv is not installed. Please install uv: https://docs.astral.sh/uv/"
exit 1
fi
# Get repository root
REPO_ROOT=$(git rev-parse --show-toplevel)
WORKFLOW_FILE="$REPO_ROOT/.github/workflows/ci.yml"
PARSER_SCRIPT="$REPO_ROOT/hooks/parse_ci_workflow.py"
# Check if workflow file exists
if [ ! -f "$WORKFLOW_FILE" ]; then
print_error "CI workflow file not found: $WORKFLOW_FILE"
exit 1
fi
# Check if parser script exists
if [ ! -f "$PARSER_SCRIPT" ]; then
print_error "Workflow parser script not found: $PARSER_SCRIPT"
exit 1
fi
print_info "Reading checks from GitHub Actions workflow: .github/workflows/ci.yml"
echo ""
# Track overall status
FAILED=0
# Extract and run lint commands
echo "ββββββββββββββββββββββββββββββββββββββββ"
echo "π Lint Checks (from CI)"
echo "ββββββββββββββββββββββββββββββββββββββββ"
echo ""
# Read lint commands from workflow (bash 3.2 compatible)
LINT_COMMANDS=()
while IFS= read -r line; do
LINT_COMMANDS+=("$line")
done < <(uv run python "$PARSER_SCRIPT" --job lint)
# Run each lint command
for cmd in "${LINT_COMMANDS[@]}"; do
echo "Running: $cmd"
if eval "$cmd"; then
print_status "Passed: $cmd"
else
print_error "Failed: $cmd"
FAILED=1
fi
echo ""
done
# Extract and run test commands
echo "ββββββββββββββββββββββββββββββββββββββββ"
echo "π§ͺ Tests (from CI)"
echo "ββββββββββββββββββββββββββββββββββββββββ"
echo ""
# Read test commands from workflow (bash 3.2 compatible)
TEST_COMMANDS=()
while IFS= read -r line; do
TEST_COMMANDS+=("$line")
done < <(uv run python "$PARSER_SCRIPT" --job test)
# Run each test command
for cmd in "${TEST_COMMANDS[@]}"; do
echo "Running: $cmd"
if eval "$cmd"; then
print_status "Passed: $cmd"
else
print_error "Failed: $cmd"
FAILED=1
fi
echo ""
done
echo "ββββββββββββββββββββββββββββββββββββββββ"
# Exit with appropriate status
if [ $FAILED -eq 1 ]; then
echo ""
print_error "Pre-commit checks failed!"
print_warning "Fix the issues above before committing"
print_warning "To bypass this hook (not recommended): git commit --no-verify"
echo ""
exit 1
else
echo ""
print_status "All pre-commit checks passed! β¨"
echo ""
exit 0
fi