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
Some checks failed
Deploy Nexus / deploy (push) Failing after 3s
This commit is contained in:
@@ -11,59 +11,12 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 2
|
|
||||||
|
|
||||||
- name: "HARD RULE: Net lines added must be <= 10"
|
- name: Validate Python syntax
|
||||||
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
|
|
||||||
run: |
|
run: |
|
||||||
FAIL=0
|
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
|
for f in $(find . -name '*.py' -not -path './venv/*'); do
|
||||||
if ! node --check "$f" 2>/dev/null; then
|
if ! python3 -c "import py_compile; py_compile.compile('$f', doraise=True)" 2>/dev/null; then
|
||||||
echo "FAIL: $f"
|
echo "FAIL: $f"
|
||||||
FAIL=1
|
FAIL=1
|
||||||
else
|
else
|
||||||
@@ -75,7 +28,7 @@ jobs:
|
|||||||
- name: Validate JSON
|
- name: Validate JSON
|
||||||
run: |
|
run: |
|
||||||
FAIL=0
|
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
|
if ! python3 -c "import json; json.load(open('$f'))"; then
|
||||||
echo "FAIL: $f"
|
echo "FAIL: $f"
|
||||||
FAIL=1
|
FAIL=1
|
||||||
@@ -85,38 +38,32 @@ jobs:
|
|||||||
done
|
done
|
||||||
exit $FAIL
|
exit $FAIL
|
||||||
|
|
||||||
- name: "HARD RULE: No JS file over 777 lines"
|
- name: Validate YAML
|
||||||
run: |
|
run: |
|
||||||
echo "=== File Size Budget: 777 lines max per JS file ==="
|
pip install pyyaml -q
|
||||||
FAIL=0
|
FAIL=0
|
||||||
for f in $(find . -name '*.js' -not -path './node_modules/*' -not -path './test-*' -not -path './tests/*'); do
|
for f in $(find . -name '*.yaml' -o -name '*.yml' | grep -v '.gitea/'); do
|
||||||
LINES=$(wc -l < "$f" | tr -d ' ')
|
if ! python3 -c "import yaml; yaml.safe_load(open('$f'))"; then
|
||||||
if [ "$LINES" -gt 777 ]; then
|
echo "FAIL: $f"
|
||||||
echo "FAIL: $f is $LINES lines (max: 777)"
|
|
||||||
FAIL=1
|
FAIL=1
|
||||||
else
|
else
|
||||||
echo "OK: $f ($LINES lines)"
|
echo "OK: $f"
|
||||||
fi
|
fi
|
||||||
done
|
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
|
exit $FAIL
|
||||||
|
|
||||||
- name: Check file size budget (bytes)
|
- name: "HARD RULE: 10-line net addition limit"
|
||||||
run: |
|
run: |
|
||||||
FAIL=0
|
ADDITIONS=$(git diff --numstat origin/main...HEAD | awk '{s+=$1} END {print s+0}')
|
||||||
for f in $(find . -name '*.js' -not -path './node_modules/*'); do
|
DELETIONS=$(git diff --numstat origin/main...HEAD | awk '{s+=$2} END {print s+0}')
|
||||||
SIZE=$(wc -c < "$f")
|
NET=$((ADDITIONS - DELETIONS))
|
||||||
if [ "$SIZE" -gt 512000 ]; then
|
echo "Additions: +$ADDITIONS | Deletions: -$DELETIONS | Net: $NET"
|
||||||
echo "FAIL: $f is ${SIZE} bytes (budget: 512000)"
|
if [ "$NET" -gt 10 ]; then
|
||||||
FAIL=1
|
echo ""
|
||||||
else
|
echo "═══════════════════════════════════════════════════"
|
||||||
echo "OK: $f (${SIZE} bytes)"
|
echo " BLOCKED: Net addition is $NET lines (max: 10)."
|
||||||
fi
|
echo " Delete code elsewhere to compensate."
|
||||||
done
|
echo "═══════════════════════════════════════════════════"
|
||||||
exit $FAIL
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "✓ Net addition ($NET) within 10-line limit."
|
||||||
|
|||||||
Reference in New Issue
Block a user