name: SonarCloud Analysis
on:
push:
branches:
- main
- develop
- 'feature/**'
- 'bugfix/**'
- 'release/**'
- 'hotfix/**'
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
- develop
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
PYTHON_VERSION: "3.14"
jobs:
sonarcloud:
runs-on: ubuntu-latest
timeout-minutes: 15
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && secrets.SONAR_TOKEN != ''
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for better analysis
- name: Cache uv dependencies
uses: actions/cache@v4
with:
path: ~/.cache/uv
key: ${{ runner.os }}-uv-${{ hashFiles('**/uv.lock') }}
restore-keys: |
${{ runner.os }}-uv-
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Install dependencies
run: uv sync --all-extras --dev
- name: Run tests with coverage
run: |
uv run pytest --cov=souschef --cov-report=xml --cov-report=term-missing
continue-on-error: true
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.projectKey=kpeacocke_souschef
-Dsonar.organization=kpeacocke
-Dsonar.sources=souschef
-Dsonar.tests=tests
-Dsonar.python.coverage.reportPaths=coverage.xml
-Dsonar.python.version=3.14
-Dsonar.exclusions=**/__pycache__/**,**/htmlcov/**,**/.pytest_cache/**,**/souschef.egg-info/**
-Dsonar.test.inclusions=tests/**
-Dsonar.coverage.exclusions=tests/**,**/__init__.py