-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (49 loc) · 1.75 KB
/
Copy pathpre-commit.yml
File metadata and controls
59 lines (49 loc) · 1.75 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
name: Pre-commit Checks
on:
pull_request:
branches: [ main, develop ]
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install pre-commit
run: |
python -m pip install --upgrade pip
pip install pre-commit
- name: Check for trailing whitespace
run: |
# Find files with trailing whitespace (warning only)
if git grep -I --line-number '\s$' -- '*.py' '*.md' '*.html' '*.css' '*.js'; then
echo "WARNING: Found trailing whitespace in files above"
fi
- name: Check for merge conflicts
run: |
# Check for unresolved merge conflict markers. Match the exact marker
# shapes (<<<<<<< ref / ======= alone / >>>>>>> ref) so ASCII banner
# lines like ============ in docs don't false-positive.
if git grep -n -E '^(<<<<<<< |=======$|>>>>>>> )' -- . ':!.github'; then
echo "ERROR: Found merge conflict markers"
exit 1
fi
- name: Validate Python syntax
run: |
python -m py_compile config.py app.py
- name: Check file encodings
run: |
# Ensure all Python files are UTF-8
for file in *.py; do
if [ -f "$file" ]; then
file -b --mime-encoding "$file" | grep -q utf-8 || echo "WARNING: $file may not be UTF-8"
fi
done
- name: Check for print statements
run: |
# Find print() calls (should use logging instead in production)
if git grep -n 'print(' -- '*.py' | grep -v '# DEBUG' || true; then
echo "INFO: Consider using logging instead of print() for production code"
fi