name: CI on: pull_request: branches: - main jobs: validate: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - 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'); 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/*'); 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: Check file size budget 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 auto-merge: needs: validate runs-on: ubuntu-latest steps: - name: Merge PR env: GITEA_TOKEN: ${{ secrets.MERGE_TOKEN }} run: | PR_NUM=$(echo "${{ github.event.pull_request.number }}") REPO="${{ github.repository }}" API="http://143.198.27.163:3000/api/v1" echo "CI passed. Auto-merging PR #${PR_NUM}..." # Squash merge RESULT=$(curl -s -w "\n%{http_code}" -X POST \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/json" \ -d '{"Do":"squash","delete_branch_after_merge":true}' \ "${API}/repos/${REPO}/pulls/${PR_NUM}/merge") HTTP_CODE=$(echo "$RESULT" | tail -1) BODY=$(echo "$RESULT" | head -n -1) if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "405" ]; then echo "Merged successfully (or already merged)" else echo "Merge failed: HTTP ${HTTP_CODE}" echo "$BODY" # Don't fail the job — PR stays open for manual review fi