SIENTIAPDE-1111: refactor sonarqube pipeline.

This commit is contained in:
Bruno Domingues
2025-06-23 12:21:55 -03:00
parent 6d3cbb1a1b
commit 2be78b1aea
2 changed files with 17 additions and 41 deletions

View File

@@ -3,19 +3,17 @@ name: Quality gate
on:
push:
branches:
- '**'
- main
pull_request:
branches:
- '**'
- main
types: [ opened, synchronize, reopened ]
jobs:
sonar:
name: SonarQube Analysis
runs-on: ubuntu-latest
permissions:
contents: read
permissions: write-all
steps:
- name: ⬇️ Checkout Code
uses: actions/checkout@v4
@@ -64,46 +62,13 @@ jobs:
python -m pip install --upgrade pip
pip install -r ${{ steps.prepare-requirements.outputs.PROCESSED_REQUIREMENTS_FILE }}
pip install pytest pytest-cov pytest-asyncio
- name: ⬇️ Setup Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18
- name: 📥 Setup SonarScanner
uses: warchant/setup-sonar-scanner@v7
- name: 🧪 Run Tests with Pytest
run: |
set +e
pytest tests --junitxml=pytest.xml --cov=laborious --cov-report=xml --cov-report=term
PYTEST_EXIT_CODE=$?
set -e
if [ $PYTEST_EXIT_CODE -eq 0 ]; then
echo "Pytest executado com sucesso."
elif [ $PYTEST_EXIT_CODE -eq 5 ]; then
echo "Pytest finalizado com código 5 (Nenhum teste encontrado). Tratando como sucesso para este workflow."
exit 0
else
echo "Pytest falhou com código de saída $PYTEST_EXIT_CODE."
exit $PYTEST_EXIT_CODE
fi
- name: 📊 Run SonarQube Analysis
- name: Run SonarQube Analysis
uses: SonarSource/sonarqube-scan-action@v5
env:
SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner \
-Dsonar.projectKey=$SONAR_PROJECT_KEY \
-Dsonar.sources=laborious \
-Dsonar.tests=tests \
-Dsonar.python.coverage.reportPaths=coverage.xml \
-Dsonar.python.xunit.reportPath=pytest.xml \
-Dsonar.host.url=$SONAR_HOST_URL \
-Dsonar.token=$SONAR_TOKEN \
-Dsonar.python.version=3.11 \
-Dsonar.projectVersion=1.0.0 \
-Dsonar.coverage.exclusions=laborious/worker/worker.py
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}