-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathpre-commit.sh
More file actions
executable file
·51 lines (39 loc) · 1.25 KB
/
pre-commit.sh
File metadata and controls
executable file
·51 lines (39 loc) · 1.25 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
#!/usr/bin/env bash
set -e
finish() {
result=$?
# Add cleanup code here
if [ $result -eq 0 ]; then
echo "✅ Pre-commit hook completed successfully"
else
echo "❌ Pre-commit hook failed with exit code $result"
fi
exit ${result}
}
trap finish EXIT ERR
# Running check and validate scripts in commits.
# Validates Typescript compilation, formatting, linting
# test cases and attempts prod build.
BRANCH_NAME="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo HEAD)"
if [[ "$BRANCH_NAME" != "HEAD" ]]; then
echo "🔍 Running pre-commit checks on branch: $BRANCH_NAME"
echo "📋 Running check..."
npm run check
echo "🎨 Running format..."
npm run format:staged
echo "🔧 Running lint..."
npm run lint
echo "🔐 Running validate..."
npm run validate:all
echo "🏗️ Running build..."
npm run build
# Continuous test suites require API keys and run separately
echo "⏭️ Skipping tests (continuous test suites require API keys - run manually with pnpm test)"
# Adding formatted files to git stage.
echo "📝 Adding formatted files to git stage..."
files="$(git diff --name-only --diff-filter=d)"
if [[ -n "$files" ]]; then
git add -- $files
fi
echo "🎉 All pre-commit checks passed!"
fi