-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlefthook.yml
More file actions
182 lines (167 loc) · 5.82 KB
/
lefthook.yml
File metadata and controls
182 lines (167 loc) · 5.82 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Lefthook Configuration for Rails Error Dashboard
# https://github.com/evilmartians/lefthook
#
# This runs quality checks on CHANGED files only for fast feedback.
#
# Installation:
# gem install lefthook
# lefthook install
#
# Skip hooks temporarily:
# LEFTHOOK=0 git commit -m "message"
# git commit -m "message" --no-verify
# ============================================================================
# PRE-COMMIT (Piped stages: fast checks first, chaos tests last)
# ============================================================================
pre-commit:
piped: true # Run stages sequentially — if fast checks fail, chaos tests don't run
commands:
# Stage 1: Fast parallel checks on changed files
# 1. RuboCop - Only staged files (exclude ERB templates)
rubocop-staged:
priority: 1
glob: "*.rb"
exclude:
- "lib/generators/**/templates/*"
run: bundle exec rubocop {staged_files}
# 2. RSpec - Only changed spec files
rspec-changed:
priority: 1
glob: "*_spec.rb"
run: |
if [ -n "{staged_files}" ]; then
echo "Running tests for changed specs..."
COVERAGE=false bundle exec rspec {staged_files}
fi
# 3. Bundle audit - Check for vulnerable dependencies
bundle-audit:
priority: 1
run: |
echo "Checking for vulnerable dependencies..."
gem list bundler-audit -i > /dev/null || gem install bundler-audit --conservative
bundle audit check --update
# 4. Check for debugger statements in staged Ruby files
no-debuggers:
priority: 1
glob: "*.rb"
run: |
if echo "{staged_files}" | xargs grep -Hn "binding\.pry\|byebug\|debugger" 2>/dev/null; then
echo "Found debugger statement! Remove before committing."
exit 1
fi
# 5. Check for trailing whitespace in staged files
trailing-whitespace:
priority: 1
glob: "*.{rb,yml,js,md}"
run: |
if echo "{staged_files}" | xargs grep -Hn "[[:space:]]$" 2>/dev/null; then
echo "Found trailing whitespace! Run: bundle exec rubocop -A"
exit 1
fi
# Stage 2: Full pre-release chaos tests (runs AFTER fast checks pass)
# Builds 4 temp Rails apps, runs 1000+ assertions in production mode.
# Takes ~4-5 min. Skip with: LEFTHOOK_EXCLUDE=chaos-tests git commit -m "msg"
chaos-tests:
priority: 2
run: |
echo "Running pre-release chaos tests (4 apps, 1000+ assertions)..."
echo "Skip with: LEFTHOOK_EXCLUDE=chaos-tests git commit -m \"msg\""
bin/pre-release-test all
# ============================================================================
# PRE-PUSH (Disabled - too slow and problematic)
# ============================================================================
# We rely on GitHub Actions CI instead of pre-push hooks
# ============================================================================
# COMMIT-MSG (Validate commit messages - optional)
# ============================================================================
# commit-msg:
# commands:
# conventional-commits:
# run: |
# commit_msg=$(cat {1})
# if ! echo "$commit_msg" | grep -qE "^(feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert)(\(.+\))?: .+"; then
# echo "❌ Commit message must follow conventional commits format"
# exit 1
# fi
# ============================================================================
# CUSTOM COMMANDS (Run manually with: lefthook run <command>)
# ============================================================================
# Run all quality checks like CI (comprehensive)
qa:
parallel: false
commands:
rubocop:
run: bundle exec rubocop
rspec:
run: bundle exec rspec
bundle-audit:
run: |
gem list bundler-audit -i > /dev/null || gem install bundler-audit --conservative
bundle audit check --update
# Quick check on changed files only (fast)
quick:
parallel: true
commands:
rubocop-changed:
run: |
changed_files=$(git diff --name-only --diff-filter=AM HEAD | grep "\.rb$" || true)
if [ -n "$changed_files" ]; then
echo "$changed_files" | xargs bundle exec rubocop
else
echo "No Ruby files changed"
fi
rspec-changed:
run: |
changed_specs=$(git diff --name-only --diff-filter=AM HEAD | grep "_spec\.rb$" || true)
if [ -n "$changed_specs" ]; then
echo "🧪 Running changed specs..."
COVERAGE=false bundle exec rspec $changed_specs
else
echo "No spec files changed"
fi
# Fix auto-correctable RuboCop issues
fix:
commands:
rubocop-autofix:
run: bundle exec rubocop -A
# Run full test suite (like CI)
full:
parallel: false
commands:
rubocop:
run: bundle exec rubocop
rspec:
run: bundle exec rspec
audit:
run: |
gem list bundler-audit -i > /dev/null || gem install bundler-audit --conservative
bundle audit check --update
# ============================================================================
# USAGE EXAMPLES
# ============================================================================
# Normal commit (fast checks + chaos tests):
# git add . && git commit -m "message"
#
# Skip chaos tests only (fast checks still run):
# LEFTHOOK_EXCLUDE=chaos-tests git commit -m "message"
#
# Run full checks manually:
# lefthook run qa
# lefthook run full
#
# Run chaos tests standalone:
# bin/pre-release-test all
# bin/pre-release-test full_http # just HTTP tests
#
# Quick check on current changes:
# lefthook run quick
#
# Fix RuboCop issues:
# lefthook run fix
#
# Skip all hooks:
# LEFTHOOK=0 git commit -m "message"
# git commit --no-verify -m "message"
#
# Skip specific command:
# LEFTHOOK_EXCLUDE=rspec-changed git commit -m "message"