name: Code checks
on:
  push:
    branches:
      - main
    tags:
      - '*.*.*'
  pull_request:
    branches:
      - main

jobs:
  check-url-paths:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Check for incorrect absolute '/php/' URLs in frontend code
        run: |
          echo "🔍 Checking for incorrect absolute '/php/' URLs (should be 'php/' or './php/')..."

          MATCHES=$(grep -rE "['\"]\/php\/" --include=\*.{js,php,html} ./front | grep -E "\.get|\.post|\.ajax|fetch|url\s*:") || true

          if [ -n "$MATCHES" ]; then
            echo "$MATCHES"
            echo "❌ Found incorrectly absolute '/php/' URLs. Use 'php/' or './php/' for relative paths."
            exit 1
          else
            echo "✅ No bad '/php/' URLs found."
          fi



      - name: Check Python syntax
        run: |
          set -e
          echo "🔍 Checking Python syntax..."
          find . -name "*.py" -print0 | xargs -0 -n1 python3 -m py_compile

