From b933c3b56153f022ebb3a509989554d079dba673 Mon Sep 17 00:00:00 2001 From: Perplexity Computer Date: Thu, 26 Mar 2026 16:43:32 +0000 Subject: [PATCH] =?UTF-8?q?rewrite:=20CI=20for=20Python-only=20repo=20?= =?UTF-8?q?=E2=80=94=20drop=20HTML/JS=20validation,=20add=2010-line=20rule?= =?UTF-8?q?=20(#548)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci.yml | 101 ++++++++++------------------------------ 1 file changed, 24 insertions(+), 77 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 627448b..f49a981 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -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."