From 737fe3035f027e63cfebfd99b66eaaf1bf691a09 Mon Sep 17 00:00:00 2001 From: Oyhs-co Date: Sat, 12 Apr 2025 08:51:21 -0500 Subject: [PATCH 1/3] ci: add SonarCloud configuration for code quality analysis --- .github/workflows/sonar.yml | 48 +++++++++++++++++++++++++++++++++++++ sonar-project.properties | 18 ++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 .github/workflows/sonar.yml create mode 100644 sonar-project.properties diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml new file mode 100644 index 0000000..2b27545 --- /dev/null +++ b/.github/workflows/sonar.yml @@ -0,0 +1,48 @@ +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.10' + + - name: Install global test deps + run: | + python -m pip install --upgrade pip + pip install pytest pytest-cov + + - name: Install service dependencies + 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 + 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 From 36ecae046438b9608a23ebc2997f999c109b5468 Mon Sep 17 00:00:00 2001 From: Oyhs-co Date: Sat, 12 Apr 2025 08:56:38 -0500 Subject: [PATCH 2/3] fix: add condition to install service dependencies --- .github/workflows/sonar.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 2b27545..679bd51 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -26,6 +26,7 @@ jobs: 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 From ce0974872970a71916b202b871aaef8c93bad191 Mon Sep 17 00:00:00 2001 From: Oyhs-co Date: Sat, 12 Apr 2025 08:59:24 -0500 Subject: [PATCH 3/3] fix: update Python version to 3.13 in SonarCloud workflow --- .github/workflows/sonar.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 679bd51..47dfa76 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -18,7 +18,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.13' - name: Install global test deps run: | @@ -33,6 +33,7 @@ jobs: 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 \