SIENTIAPDE-1111: refactor sonarqube pipeline.

This commit is contained in:
Bruno Domingues
2025-06-23 21:59:08 -03:00
parent b6f3e4f813
commit cff067c517
2 changed files with 17 additions and 41 deletions

View File

@@ -3,19 +3,17 @@ name: Quality gate
on: on:
push: push:
branches: branches:
- '**' - main
pull_request: pull_request:
branches: branches:
- '**' - main
types: [ opened, synchronize, reopened ] types: [ opened, synchronize, reopened ]
jobs: jobs:
sonar: sonar:
name: SonarQube Analysis name: SonarQube Analysis
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions: write-all
contents: read
steps: steps:
- name: ⬇️ Checkout Code - name: ⬇️ Checkout Code
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -63,46 +61,14 @@ jobs:
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install -r ${{ steps.prepare-requirements.outputs.PROCESSED_REQUIREMENTS_FILE }} pip install -r ${{ steps.prepare-requirements.outputs.PROCESSED_REQUIREMENTS_FILE }}
pip install pytest pytest-cov pytest-asyncio pip install pytest pytest-cov
- 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 - name: 🧪 Run Tests with Pytest
run: | run: |
set +e
pytest tests --junitxml=pytest.xml --cov=scouter --cov-report=xml --cov-report=term pytest tests --junitxml=pytest.xml --cov=scouter --cov-report=xml --cov-report=term
PYTEST_EXIT_CODE=$?
set -e
if [ $PYTEST_EXIT_CODE -eq 0 ]; then - name: Run SonarQube Analysis
echo "Pytest executado com sucesso." uses: SonarSource/sonarqube-scan-action@v5
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
env: env:
SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Este é o token do SonarQube
run: |
sonar-scanner \
-Dsonar.projectKey=$SONAR_PROJECT_KEY \
-Dsonar.sources=scouter \
-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

10
sonar-project.properties Normal file
View File

@@ -0,0 +1,10 @@
sonar.projectKey=Aignosi_sientia-dataops-scouter_temporal_f79e575e-be40-4cc6-acce-b7c5ebb9a5b0
sonar.projectName=sientia-dataops-scouter_temporal
sonar.sources=scouter
sonar.tests=tests
sonar.qualitygate.wait=true
sonar.qualitygate.timeout=300
sonar.python.coverage.reportPaths=coverage.xml
sonar.python.xunit.reportPath=pytest.xml
sonar.python.version=3.11
sonar.projectVersion=1.0.0