rewrite: CI for Python-only repo — drop HTML/JS validation, add 10-line rule (#548)
Some checks failed
Deploy Nexus / deploy (push) Failing after 3s

This commit is contained in:
2026-03-26 16:43:32 +00:00
parent 6efe539a78
commit b933c3b561

View File

@@ -11,59 +11,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: "HARD RULE: Net lines added must be <= 10"
run: |
echo "=== PR Size Budget: 10 lines net max ==="
git diff --shortstat HEAD^ HEAD > diffstat.txt
cat diffstat.txt
INSERTIONS=$(grep "insertion" diffstat.txt | awk '{print $4}' | sed 's/([+-])//g' || echo 0)
DELETIONS=$(grep "deletion" diffstat.txt | awk '{print $6}' | sed 's/([+-])//g' || echo 0)
if [ -z "$INSERTIONS" ]; then INSERTIONS=0; fi
if [ -z "$DELETIONS" ]; then DELETIONS=0; fi
NET_LINES=$(($INSERTIONS - $DELETIONS))
echo "--> Insertions: $INSERTIONS"
echo "--> Deletions: $DELETIONS"
echo "--> Net change: $NET_LINES lines"
if [ "$NET_LINES" -gt 10 ]; then
echo ""
echo "══════════════════════════════════════════════════════════════"
echo " BLOCKED: Net lines added must be less than or equal to 10."
echo " Make this PR smaller, or find something to delete."
echo " (See CONTRIBUTING.md for details)"
echo "══════════════════════════════════════════════════════════════"
exit 1
else
echo "OK: Net change is within budget."
fi
- name: Validate HTML
run: |
test -f index.html || { echo "ERROR: index.html missing"; exit 1; }
python3 -c "
import html.parser, sys
class V(html.parser.HTMLParser):
def __init__(self):
super().__init__()
def handle_starttag(self, tag, attrs): pass
def handle_endtag(self, tag): pass
v = V()
try:
v.feed(open('index.html').read())
print('HTML: OK')
except Exception as e:
print(f'HTML: FAIL - {e}')
sys.exit(1)
"
- name: Validate JavaScript
- name: Validate Python syntax
run: |
FAIL=0
for f in $(find . -name '*.js' -not -path './node_modules/*' -not -name 'sw.js' -not -name 'service-worker.js' -not -path './tests/*'); do
if ! node --check "$f" 2>/dev/null; then
for f in $(find . -name '*.py' -not -path './venv/*'); do
if ! python3 -c "import py_compile; py_compile.compile('$f', doraise=True)" 2>/dev/null; then
echo "FAIL: $f"
FAIL=1
else
@@ -75,7 +28,7 @@ jobs:
- name: Validate JSON
run: |
FAIL=0
for f in $(find . -name '*.json' -not -path './node_modules/*' -not -path './test-*'); do
for f in $(find . -name '*.json' -not -path './venv/*'); do
if ! python3 -c "import json; json.load(open('$f'))"; then
echo "FAIL: $f"
FAIL=1
@@ -85,38 +38,32 @@ jobs:
done
exit $FAIL
- name: "HARD RULE: No JS file over 777 lines"
- name: Validate YAML
run: |
echo "=== File Size Budget: 777 lines max per JS file ==="
pip install pyyaml -q
FAIL=0
for f in $(find . -name '*.js' -not -path './node_modules/*' -not -path './test-*' -not -path './tests/*'); do
LINES=$(wc -l < "$f" | tr -d ' ')
if [ "$LINES" -gt 777 ]; then
echo "FAIL: $f is $LINES lines (max: 777)"
for f in $(find . -name '*.yaml' -o -name '*.yml' | grep -v '.gitea/'); do
if ! python3 -c "import yaml; yaml.safe_load(open('$f'))"; then
echo "FAIL: $f"
FAIL=1
else
echo "OK: $f ($LINES lines)"
echo "OK: $f"
fi
done
if [ $FAIL -eq 1 ]; then
echo ""
echo "═══════════════════════════════════════════════════"
echo " BLOCKED: No JS file may exceed 777 lines."
echo " Extract into modules. app.js is a THIN WRAPPER."
echo "═══════════════════════════════════════════════════"
fi
exit $FAIL
- name: Check file size budget (bytes)
- name: "HARD RULE: 10-line net addition limit"
run: |
FAIL=0
for f in $(find . -name '*.js' -not -path './node_modules/*'); do
SIZE=$(wc -c < "$f")
if [ "$SIZE" -gt 512000 ]; then
echo "FAIL: $f is ${SIZE} bytes (budget: 512000)"
FAIL=1
else
echo "OK: $f (${SIZE} bytes)"
fi
done
exit $FAIL
ADDITIONS=$(git diff --numstat origin/main...HEAD | awk '{s+=$1} END {print s+0}')
DELETIONS=$(git diff --numstat origin/main...HEAD | awk '{s+=$2} END {print s+0}')
NET=$((ADDITIONS - DELETIONS))
echo "Additions: +$ADDITIONS | Deletions: -$DELETIONS | Net: $NET"
if [ "$NET" -gt 10 ]; then
echo ""
echo "═══════════════════════════════════════════════════"
echo " BLOCKED: Net addition is $NET lines (max: 10)."
echo " Delete code elsewhere to compensate."
echo "═══════════════════════════════════════════════════"
exit 1
fi
echo "✓ Net addition ($NET) within 10-line limit."