diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml new file mode 100644 index 0000000..47dfa76 --- /dev/null +++ b/.github/workflows/sonar.yml @@ -0,0 +1,50 @@ +name: Monorepo Test & SonarCloud + +on: + push: + branches: [ main , Development ] + pull_request: + types: [opened, synchronize, reopened] + +jobs: + sonarcloud: + name: Unified Coverage + SonarCloud + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.13' + + - name: Install global test deps + run: | + python -m pip install --upgrade pip + pip install pytest pytest-cov + + - name: Install service dependencies + if: ${{ github.event_name == 'null' }} + run: | + pip install -r auth-service/requirements.txt + pip install -r project-service/requirements.txt + pip install -r notification-service/requirements.txt + + - name: Run all tests with per-service coverage + if: ${{ github.event_name == 'null' }} + run: | + pytest \ + --cov=auth-service \ + --cov=project-service \ + --cov=notification-service \ + --cov-report=xml \ + auth-service/tests project-service/tests notification-service/tests + + - name: SonarCloud Analysis + uses: SonarSource/sonarcloud-github-action@v2 + with: + projectBaseDir: . + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..275874e --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,18 @@ +sonar.projectKey=ISCODEVUTB_TaskHub +sonar.organization=deviscoutb +sonar.host.url=https://sonarcloud.io +sonar.token=${SONAR_TOKEN} + +# Incluye todos los microservicios +sonar.sources=auth-service,project-service,notification-service +sonar.tests=auth-service/tests,project-service/tests,notification-service/tests + +# Incluir solo archivos de test dentro de tests/ +sonar.test.inclusions=**/tests/**/*.py + +# Excluir posibles archivos compilados o cachés +sonar.exclusions=**/__pycache__/**,**/*.pyc + +# Coverage report +# Lo ideal es un coverage.xml generado de forma combinada +sonar.python.coverage.reportPaths=coverage.xml