-
Notifications
You must be signed in to change notification settings - Fork 54
/
pre-commit.sh
47 lines (36 loc) · 1.23 KB
/
pre-commit.sh
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
#!/bin/sh
# shellcheck disable=SC2034
# Load git diff once for slight performance improvements
git_changes=$(git diff --name-only)
execute_or_run() {
folder="$1"
container_name="$2"
service="$3"
cmd="$4"
use_cmd_as_entrypoint="${5:-false}" # default to false if not provided
if echo "$git_changes" | grep -qE "^$folder/"; then
if docker inspect --format="{{.State.Running}}" "$container_name" 2>/dev/null | grep -q "true"; then
docker compose exec -d "$service" $cmd
else
# Check if we should use the command as the entrypoint
if $use_cmd_as_entrypoint; then
docker compose run --rm -d --entrypoint="$cmd" "$service"
else
docker compose run -d "$service" $cmd
fi
fi
fi
}
# Frontend
execute_or_run "frontend" "ecamp3-frontend" "frontend" "npm run lint" &
# API/PHP
execute_or_run "api" "ecamp3-api" "php" "composer cs-fix" &
# Print
execute_or_run "print" "ecamp3-print" "print" "npm run lint" &
# PDF
execute_or_run "pdf" "ecamp3-pdf" "pdf" "npm run lint" &
# E2E
execute_or_run "e2e" "ecamp3-e2e" "e2e" "npm run lint" true
# Wait for all parallel jobs to complete
wait
echo "eCamp v3 Git-Hook run finished"