| name: Bayan CI/CD | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| validate: | |
| name: Validate Code | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Check Python syntax (all .py files) | |
| run: | | |
| echo "Checking Python syntax..." | |
| find . -name "*.py" -not -path "./.git/*" -not -path "./archive/*" | while read f; do | |
| python -m py_compile "$f" 2>&1 && echo " ✅ $f" || { echo " ❌ $f"; exit 1; } | |
| done | |
| echo "✅ All Python files have valid syntax" | |
| - name: Verify critical files exist | |
| run: | | |
| for f in src/app.py src/model_loader.py src/hf_inference.py src/index.html \ | |
| src/nlp/__init__.py src/nlp/spelling/araspell_service.py \ | |
| src/nlp/grammar/grammar_service.py src/nlp/punctuation/punctuation_service.py \ | |
| Dockerfile Procfile requirements.txt; do | |
| test -f "$f" && echo " ✅ $f" || { echo " ❌ MISSING: $f"; exit 1; } | |
| done | |
| echo "✅ All critical files present" | |
| - name: Verify API routes defined in app.py | |
| run: | | |
| for route in "/api/health" "/api/analyze" "/api/summarize" "/api/spelling" \ | |
| "/api/grammar" "/api/punctuation" "/api/quran"; do | |
| grep -q "$route" src/app.py && echo " ✅ $route" || { echo " ❌ MISSING ROUTE: $route"; exit 1; } | |
| done | |
| echo "✅ All API routes defined" | |
| - name: Validate Supabase meta tags in index.html | |
| run: | | |
| grep -q 'supabase-url' src/index.html && echo " ✅ supabase-url meta tag" || exit 1 | |
| grep -q 'supabase-anon-key' src/index.html && echo " ✅ supabase-anon-key meta tag" || exit 1 | |
| echo "✅ Supabase tags present" | |
| - name: Validate Dockerfile | |
| run: | | |
| grep -q 'EXPOSE' Dockerfile && echo " ✅ EXPOSE directive" || exit 1 | |
| grep -q 'gunicorn\|CMD' Dockerfile && echo " ✅ Startup command" || exit 1 | |
| echo "✅ Dockerfile valid" | |
| health-check: | |
| name: Post-Deploy Health Check | |
| needs: validate | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Wait for HuggingFace Spaces to deploy | |
| run: sleep 120 | |
| - name: Check backend health | |
| run: | | |
| HEALTH_URL="${{ secrets.BACKEND_URL }}/api/health" | |
| if [ -z "${{ secrets.BACKEND_URL }}" ]; then | |
| HEALTH_URL="https://bayan10-bayan-api.hf.space/api/health" | |
| fi | |
| echo "Checking: $HEALTH_URL" | |
| response=$(curl -s -w "\n%{http_code}" "$HEALTH_URL") | |
| http_code=$(echo "$response" | tail -n1) | |
| body=$(echo "$response" | head -n -1) | |
| echo "Status: $http_code" | |
| echo "Body: $body" | |
| if [ "$http_code" = "200" ] || [ "$http_code" = "503" ]; then | |
| echo "✅ Backend is responding" | |
| else | |
| echo "❌ Backend health check failed" | |
| exit 1 | |
| fi | |