-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun_scripts.sh
More file actions
149 lines (130 loc) · 4.86 KB
/
run_scripts.sh
File metadata and controls
149 lines (130 loc) · 4.86 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
#!/bin/bash
# Run all scripts in scripts/ with PYAUTOFIT_TEST_MODE=1.
#
# Rules:
# - start_here.py in a folder runs before all other scripts and subfolders in that folder
# - Scripts matching patterns in no_run.yaml [autofit] are skipped
# - Failures are logged to failed/<path>.log; execution continues
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
SCRIPTS_DIR="$SCRIPT_DIR/scripts"
FAILED_DIR="$SCRIPT_DIR/failed"
NO_RUN_YAML="$SCRIPT_DIR/../PyAutoBuild/autobuild/config/no_run.yaml"
PROJECT_KEY="autofit"
export PYAUTOFIT_TEST_MODE=1
export PYAUTO_WORKSPACE_SMALL_DATASETS=1
export PYAUTO_DISABLE_CRITICAL_CAUSTICS=1
export PYAUTO_FAST_PLOTS=1
# ---------------------------------------------------------------------------
# Build ordered script list: within each directory, start_here.py runs first,
# then other .py files alphabetically, before descending into subdirectories.
# ---------------------------------------------------------------------------
mapfile -t ALL_SCRIPTS < <(python3 -c "
import os
from pathlib import Path
scripts_dir = Path('$SCRIPTS_DIR')
result = []
for root, dirs, files in os.walk(scripts_dir):
dirs.sort()
py = sorted(f for f in files if f.endswith('.py') and f != '__init__.py')
if 'start_here.py' in py:
py.remove('start_here.py')
py.insert(0, 'start_here.py')
result.extend(os.path.join(root, f) for f in py)
print('\n'.join(result))
")
# ---------------------------------------------------------------------------
# Parse no_run.yaml: extract patterns and inline comments for PROJECT_KEY.
# Flags patterns as FUTURE_PR if the comment mentions a bug or GitHub issue.
# ---------------------------------------------------------------------------
NO_RUN_DATA=$(python3 -c "
import re
yaml_file = '$NO_RUN_YAML'
project_key = '$PROJECT_KEY'
in_section = False
with open(yaml_file) as f:
for line in f:
stripped = line.strip()
if re.match(r'^' + project_key + r'\s*:', stripped):
in_section = True
continue
if in_section:
if stripped and not stripped.startswith('-') and not stripped.startswith('#'):
break
m = re.match(r'^-\s+(\S+)\s*(?:#\s*(.*))?', stripped)
if m:
pattern = m.group(1)
comment = (m.group(2) or '').strip()
low = comment.lower()
flag = 'FUTURE_PR' if any(k in low for k in ['bug', 'github.com', 'issue', 'fix']) else ''
print(f'{pattern}|{comment}|{flag}')
")
declare -A SKIP_REASON
declare -A SKIP_FLAG
while IFS='|' read -r pattern reason flag; do
[[ -n "$pattern" ]] || continue
SKIP_REASON["$pattern"]="$reason"
SKIP_FLAG["$pattern"]="$flag"
done <<< "$NO_RUN_DATA"
# ---------------------------------------------------------------------------
# Print skip list
# ---------------------------------------------------------------------------
echo "=== Scripts excluded by no_run.yaml [$PROJECT_KEY] ==="
while IFS='|' read -r pattern reason flag; do
[[ -z "$pattern" ]] && continue
if [[ "$flag" == "FUTURE_PR" ]]; then
echo " SKIP [TODO - should run after a future PR]: $pattern -- $reason"
else
echo " SKIP: $pattern -- $reason"
fi
done <<< "$NO_RUN_DATA"
echo ""
# ---------------------------------------------------------------------------
# Check whether a script path matches a no_run pattern.
# Matches on: basename stem == pattern, or full relative stem == pattern,
# or pattern is a suffix segment of the relative stem.
# ---------------------------------------------------------------------------
should_skip() {
local abs_path="$1"
local rel="${abs_path#$SCRIPTS_DIR/}"
local stem="${rel%.py}"
local base
base="$(basename "$stem")"
for pattern in "${!SKIP_REASON[@]}"; do
if [[ "$base" == "$pattern" ]] \
|| [[ "$stem" == "$pattern" ]] \
|| [[ "$stem" == *"/$pattern" ]]; then
return 0
fi
done
return 1
}
# ---------------------------------------------------------------------------
# Run scripts
# ---------------------------------------------------------------------------
pass=0
fail=0
skipped=0
for script in "${ALL_SCRIPTS[@]}"; do
rel="${script#$SCRIPTS_DIR/}"
if should_skip "$script"; then
echo "SKIP: $rel"
skipped=$((skipped + 1))
continue
fi
echo "Running: $rel"
output=$(python3 "$script" 2>&1)
status=$?
if [[ $status -ne 0 ]]; then
log_path="$FAILED_DIR/${rel%.py}.log"
echo " FAILED (logged to failed/${rel%.py}.log)"
mkdir -p "$(dirname "$log_path")"
printf "Script: %s\nExit: %d\n\n%s\n" "$rel" "$status" "$output" > "$log_path"
fail=$((fail + 1))
else
echo " OK"
pass=$((pass + 1))
fi
done
echo ""
echo "Results: $pass passed, $fail failed, $skipped skipped"
[[ $fail -gt 0 ]] && echo "Failure logs in: failed/"