Files
the-nexus/.gitea/workflows/ci.yml
Alexander Whitestone 5dbbcd0305
Some checks failed
CI / validate (pull_request) Failing after 3s
feat: add PR size check to CI
Refs #561
2026-03-26 07:06:20 -04:00

123 lines
4.5 KiB
YAML

name: CI
on:
pull_request:
branches:
- main
jobs:
validate:
runs-on: ubuntu-latest
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
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
echo "FAIL: $f"
FAIL=1
else
echo "OK: $f"
fi
done
exit $FAIL
- name: Validate JSON
run: |
FAIL=0
for f in $(find . -name '*.json' -not -path './node_modules/*' -not -path './test-*'); do
if ! python3 -c "import json; json.load(open('$f'))"; then
echo "FAIL: $f"
FAIL=1
else
echo "OK: $f"
fi
done
exit $FAIL
- name: "HARD RULE: No JS file over 777 lines"
run: |
echo "=== File Size Budget: 777 lines max per JS file ==="
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)"
FAIL=1
else
echo "OK: $f ($LINES lines)"
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)
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