Skip to content

Commit 8a3cb2a

Browse files
authored
Merge pull request #5 from swappsco/feat/smart-tests
feat: execute comand skip docker exec interactive
2 parents 4c1b41c + a66175a commit 8a3cb2a

3 files changed

Lines changed: 44 additions & 10 deletions

File tree

.dev-hooks.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ pre-push:
1313
enabled: true
1414
skip_branch_validation: false
1515

16+
# Django smart tests - run tests only for modified apps
17+
django_smart_tests: true
18+
django_test_command: "pytest -n auto"
19+
1620
commands:
1721
- name: "Check CLI"
1822
run: "venv/bin/dev-hooks --version"

src/dev_tools_hooks/hooks/pre-commit

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,33 @@ yaml_get_commands() {
7777
fi
7878

7979
awk -v section="$section" '
80+
function emit() {
81+
if (name != "" && cmd != "") {
82+
print name "|" cmd "|" cmd_docker
83+
name=""; cmd=""; cmd_docker=""
84+
}
85+
}
8086
$0 ~ "^"section":" { in_section=1; next }
81-
in_section && /^[a-zA-Z]/ { in_section=0 }
87+
in_section && /^[a-zA-Z]/ { emit(); in_section=0; in_commands=0 }
8288
in_section && /^ commands:/ { in_commands=1; next }
83-
in_commands && /^ [a-zA-Z]/ { in_commands=0 }
89+
in_commands && /^ [a-zA-Z]/ { emit(); in_commands=0 }
8490
in_commands && /^ - name:/ {
91+
emit()
8592
gsub(/^ - name:[ ]*/, "")
8693
gsub(/^["'\'']|["'\'']$/, "")
8794
name=$0
8895
}
8996
in_commands && /^ run:/ {
9097
gsub(/^ run:[ ]*/, "")
9198
gsub(/^["'\'']|["'\'']$/, "")
92-
print name "|" $0
99+
cmd=$0
100+
}
101+
in_commands && /^ docker:/ {
102+
gsub(/^ docker:[ ]*/, "")
103+
gsub(/^["'\'']|["'\'']$/, "")
104+
cmd_docker=$0
93105
}
106+
END { emit() }
94107
' "$file"
95108
}
96109

@@ -240,14 +253,16 @@ run_commands() {
240253
[ -z "$line" ] && continue
241254

242255
local name="${line%%|*}"
243-
local cmd="${line#*|}"
256+
local rest="${line#*|}"
257+
local cmd="${rest%%|*}"
258+
local cmd_docker="${rest##*|}"
244259

245260
echo -e "${BLUE}${NC} ${WHITE}${BOLD}${name}${NC}"
246261
echo -e " ${DIM}${cmd}${NC}"
247262

248263
local full_cmd="$cmd"
249264

250-
if [ "$docker_enabled" = "true" ]; then
265+
if [ "$docker_enabled" = "true" ] && [ "$cmd_docker" != "false" ]; then
251266
if [ "$docker_compose" = "true" ]; then
252267
full_cmd="docker-compose -f $compose_file exec -T $docker_container $cmd"
253268
else

src/dev_tools_hooks/hooks/pre-push

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,33 @@ yaml_get_commands() {
8686
fi
8787

8888
awk '
89+
function emit() {
90+
if (name != "" && cmd != "") {
91+
print name "|" cmd "|" cmd_docker
92+
name=""; cmd=""; cmd_docker=""
93+
}
94+
}
8995
/^pre-push:/ { in_prepush=1; next }
90-
in_prepush && /^[a-zA-Z]/ { in_prepush=0 }
96+
in_prepush && /^[a-zA-Z]/ { emit(); in_prepush=0; in_commands=0 }
9197
in_prepush && /^ commands:/ { in_commands=1; next }
92-
in_commands && /^ [a-zA-Z]/ { in_commands=0 }
98+
in_commands && /^ [a-zA-Z]/ { emit(); in_commands=0 }
9399
in_commands && /^ - name:/ {
100+
emit()
94101
gsub(/^ - name:[ ]*/, "")
95102
gsub(/^["'\'']|["'\'']$/, "")
96103
name=$0
97104
}
98105
in_commands && /^ run:/ {
99106
gsub(/^ run:[ ]*/, "")
100107
gsub(/^["'\'']|["'\'']$/, "")
101-
print name "|" $0
108+
cmd=$0
109+
}
110+
in_commands && /^ docker:/ {
111+
gsub(/^ docker:[ ]*/, "")
112+
gsub(/^["'\'']|["'\'']$/, "")
113+
cmd_docker=$0
102114
}
115+
END { emit() }
103116
' "$file"
104117
}
105118

@@ -374,14 +387,16 @@ run_commands() {
374387
[ -z "$line" ] && continue
375388

376389
local name="${line%%|*}"
377-
local cmd="${line#*|}"
390+
local rest="${line#*|}"
391+
local cmd="${rest%%|*}"
392+
local cmd_docker="${rest##*|}"
378393

379394
echo -e "${BLUE}${NC} ${WHITE}${BOLD}${name}${NC}"
380395
echo -e " ${DIM}${cmd}${NC}"
381396

382397
local full_cmd="$cmd"
383398

384-
if [ "$docker_enabled" = "true" ]; then
399+
if [ "$docker_enabled" = "true" ] && [ "$cmd_docker" != "false" ]; then
385400
if [ "$docker_compose" = "true" ]; then
386401
full_cmd="docker-compose -f $compose_file exec -T $docker_container $cmd"
387402
else

0 commit comments

Comments
 (0)