From 2be78b1aea1bd1d0a40b3cc87d2bcca2ccfdaed9 Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Mon, 23 Jun 2025 12:21:55 -0300 Subject: [PATCH] SIENTIAPDE-1111: refactor sonarqube pipeline. --- .github/workflows/quality-gate.yml | 47 ++++-------------------------- sonar-project.properties | 11 +++++++ 2 files changed, 17 insertions(+), 41 deletions(-) create mode 100644 sonar-project.properties diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index 579b770..9212f77 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -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 }} diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..b332c70 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,11 @@ +sonar.projectKey=Aignosi_sientia-dataops-laborious_temporal_beaec423-6c42-4f26-8134-b676287b499d +sonar.projectName=sientia-dataops-laborious_temporal +sonar.sources=laborious +sonar.tests=tests +sonar.projectVersion=1.0.0 +sonar.coverage.exclusions=laborious/worker/worker.py +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