Skip to content

Commit 1d290f2

Browse files
committed
feat: add parallel pre-commit and pre-push git hooks
1 parent d023b23 commit 1d290f2

File tree

2 files changed

+151
-6
lines changed

2 files changed

+151
-6
lines changed

.githooks/pre-commit

Lines changed: 107 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,118 @@
1-
#!/bin/sh
1+
#!/bin/bash
2+
set -o pipefail
23

34
echo "Running pre-commit checks..."
45

5-
# Run composer test (lint, phpstan, phpunit)
6-
composer test
6+
TMPDIR=$(mktemp -d)
7+
trap "rm -rf $TMPDIR" EXIT
78

8-
if [ $? -ne 0 ]; then
9+
# Run static analysis tools in parallel (they are independent)
10+
echo "→ Running BE + FE analysis in parallel..."
11+
12+
(
13+
./vendor/bin/pint --test 2>&1
14+
exit "${PIPESTATUS[0]}"
15+
) > "$TMPDIR/pint.out" 2>&1 &
16+
PID_PINT=$!
17+
18+
(
19+
./vendor/bin/rector --dry-run 2>&1
20+
exit "${PIPESTATUS[0]}"
21+
) > "$TMPDIR/rector.out" 2>&1 &
22+
PID_RECTOR=$!
23+
24+
(
25+
./vendor/bin/phpstan analyse --memory-limit=512M 2>&1
26+
exit "${PIPESTATUS[0]}"
27+
) > "$TMPDIR/phpstan.out" 2>&1 &
28+
PID_PHPSTAN=$!
29+
30+
npm run lint > "$TMPDIR/eslint.out" 2>&1 &
31+
PID_ESLINT=$!
32+
33+
npm run typecheck > "$TMPDIR/typecheck.out" 2>&1 &
34+
PID_TYPECHECK=$!
35+
36+
# Wait for all and collect exit codes
37+
wait $PID_PINT; EXIT_PINT=$?
38+
wait $PID_RECTOR; EXIT_RECTOR=$?
39+
wait $PID_PHPSTAN; EXIT_PHPSTAN=$?
40+
wait $PID_ESLINT; EXIT_ESLINT=$?
41+
wait $PID_TYPECHECK; EXIT_TYPECHECK=$?
42+
43+
FAILED=0
44+
45+
if [ $EXIT_PINT -ne 0 ]; then
946
echo ""
10-
echo "Pre-commit checks failed!"
47+
echo "Pint check failed!"
48+
cat "$TMPDIR/pint.out"
1149
echo "Run 'composer fix' to auto-fix code style issues."
50+
FAILED=1
51+
fi
52+
53+
if [ $EXIT_RECTOR -ne 0 ]; then
54+
echo ""
55+
echo "Rector check failed!"
56+
cat "$TMPDIR/rector.out"
57+
echo "Run 'composer rector:fix' to auto-fix issues."
58+
FAILED=1
59+
fi
60+
61+
if [ $EXIT_PHPSTAN -ne 0 ]; then
62+
echo ""
63+
echo "PHPStan check failed!"
64+
cat "$TMPDIR/phpstan.out"
65+
FAILED=1
66+
fi
67+
68+
if [ $EXIT_ESLINT -ne 0 ]; then
69+
echo ""
70+
echo "ESLint check failed!"
71+
cat "$TMPDIR/eslint.out"
72+
echo "Run 'npm run lint:fix' to auto-fix issues."
73+
FAILED=1
74+
fi
75+
76+
if [ $EXIT_TYPECHECK -ne 0 ]; then
1277
echo ""
78+
echo "TypeScript check failed!"
79+
cat "$TMPDIR/typecheck.out"
80+
FAILED=1
81+
fi
82+
83+
if [ $FAILED -ne 0 ]; then
84+
exit 1
85+
fi
86+
87+
# Run BE + FE tests in parallel (after analysis passes)
88+
echo "→ Running tests..."
89+
90+
./vendor/bin/phpunit > "$TMPDIR/phpunit.out" 2>&1 &
91+
PID_PHPUNIT=$!
92+
93+
npm run test:unit > "$TMPDIR/vitest.out" 2>&1 &
94+
PID_VITEST=$!
95+
96+
wait $PID_PHPUNIT; EXIT_PHPUNIT=$?
97+
wait $PID_VITEST; EXIT_VITEST=$?
98+
99+
if [ $EXIT_PHPUNIT -ne 0 ]; then
100+
echo ""
101+
echo "PHP tests failed!"
102+
cat "$TMPDIR/phpunit.out"
103+
FAILED=1
104+
fi
105+
106+
if [ $EXIT_VITEST -ne 0 ]; then
107+
echo ""
108+
echo "Vitest tests failed!"
109+
cat "$TMPDIR/vitest.out"
110+
FAILED=1
111+
fi
112+
113+
if [ $FAILED -ne 0 ]; then
13114
exit 1
14115
fi
15116

16-
echo "All checks passed!"
117+
echo "All pre-commit checks passed!"
17118
exit 0

.githooks/pre-push

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
set -o pipefail
3+
4+
echo "Running pre-push checks (full test suite)..."
5+
6+
TMPDIR=$(mktemp -d)
7+
trap 'rm -rf $TMPDIR' EXIT
8+
9+
# Run BE and FE full test suites in parallel
10+
composer test > "$TMPDIR/be.out" 2>&1 &
11+
PID_BE=$!
12+
13+
npm run test > "$TMPDIR/fe.out" 2>&1 &
14+
PID_FE=$!
15+
16+
wait $PID_BE; EXIT_BE=$?
17+
wait $PID_FE; EXIT_FE=$?
18+
19+
FAILED=0
20+
21+
if [ $EXIT_BE -ne 0 ]; then
22+
echo ""
23+
echo "Backend checks failed!"
24+
cat "$TMPDIR/be.out"
25+
echo "Run 'composer fix' to auto-fix code style issues."
26+
echo "Run 'composer test' to see all failures."
27+
FAILED=1
28+
fi
29+
30+
if [ $EXIT_FE -ne 0 ]; then
31+
echo ""
32+
echo "Frontend checks failed!"
33+
cat "$TMPDIR/fe.out"
34+
echo "Run 'npm run lint:fix' to auto-fix lint issues."
35+
echo "Run 'npm run test' to see all failures."
36+
FAILED=1
37+
fi
38+
39+
if [ $FAILED -ne 0 ]; then
40+
exit 1
41+
fi
42+
43+
echo "All pre-push checks passed!"
44+
exit 0

0 commit comments

Comments
 (0)