name: SonarCloud on: push: branches: [main] pull_request: branches: [main] jobs: sonarcloud: name: SonarCloud Analysis runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: # SonarCloud needs full history for accurate blame/new-code detection fetch-depth: 0 # --- Backend: generate coverage.xml so Sonar can report Python coverage --- - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.12" cache: pip cache-dependency-path: backend/requirements-dev.txt - name: Install backend dependencies working-directory: backend run: | python -m pip install --upgrade pip pip install -r requirements-dev.txt - name: Run pytest with coverage working-directory: backend run: | python -m pytest \ --cov=app \ --cov-report=xml \ -p no:warnings # Don't fail the whole Sonar run just because a test flaked; # Sonar will simply show stale/no coverage for this run instead. continue-on-error: true # --- Frontend: optional ESLint report for Sonar's JS/TS rules --- - name: Set up Node uses: actions/setup-node@v4 with: node-version: "20" cache: npm cache-dependency-path: frontend/package-lock.json - name: Install frontend dependencies working-directory: frontend run: npm ci - name: Run ESLint (JSON report for Sonar) working-directory: frontend run: npx eslint . --format json --output-file eslint-report.json continue-on-error: true # --- SonarCloud scan --- - name: SonarCloud Scan uses: SonarSource/sonarqube-scan-action@v4 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}