From 4503bd75a60900243fcc04f41d7f194a2e0e44ab Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Tue, 15 Apr 2025 10:33:52 -0400 Subject: [PATCH 1/3] Add stuff to help SonarCloud maybe work --- .github/workflows/ci.yml | 4 ++-- requirements_dev.txt | 4 +++- sonar-project.properties | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 sonar-project.properties diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb4c73e3..7e25dc99 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,8 +26,8 @@ jobs: - name: Install dispatcherd run: pip install -e .[pg_notify,metrics] - run: make postgres - - run: pip install pytest pytest-asyncio httpx - - run: pytest tests/unit tests/integration -vv -s + - run: pip install -r requirements_dev.txt + - run: pytest tests/unit tests/integration --cov=. --cov-report=xml:coverage.xml --cov-report=html --cov-report=json -vv -s black: name: Run black diff --git a/requirements_dev.txt b/requirements_dev.txt index c4916284..96ab8aab 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,3 +1,5 @@ pytest pytest-asyncio -pytest-benchmark \ No newline at end of file +pytest-benchmark # for benchmark tests +pytest-cov # for SonarCloud +httpx # used for the metrics server test diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..ff594420 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,32 @@ +# Complete documentation with many more options at: +# https://docs.sonarqube.org/latest/analysis/analysis-parameters/ + +#sonar.host.url=https://sonarqube.corp.redhat.com + +## The unique project identifier. This is mandatory. +# Do not duplicate or reuse! +# Available characters: [a-zA-Z0-9_:\.\-] +# Must have least one non-digit. +# Recommended format: : +sonar.projectKey=ansible-dispatcherd + +sonar.organization=ansible + +# Customize what paths to scan. Default is . +sonar.sources=. +# Excluse test directories from sources +sonar.exclusions=tools/** +# Set tests root directory +sonar.tests=tests + +# Verbose name of project displayed in WUI. Default is set to the projectKey. This field is optional. +sonar.projectName=dispatcherd + +# Version of project. This field is optional. +#sonar.projectVersion=1.0 + +# Tell sonar scanner where coverage files exist +sonar.python.coverage.reportPaths=coverage.xml + +# Only scan with python3 +sonar.python.version=3.11,3.13 From 5bfc01ccff6d24193efe974b7a5d6d9d608a0ff4 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Tue, 15 Apr 2025 12:47:59 -0400 Subject: [PATCH 2/3] Add step to upload to sonarcloud --- .github/workflows/ci.yml | 12 ++++++++++++ sonar-project.properties | 32 -------------------------------- 2 files changed, 12 insertions(+), 32 deletions(-) delete mode 100644 sonar-project.properties diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e25dc99..4021f871 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,18 @@ jobs: - run: pip install -r requirements_dev.txt - run: pytest tests/unit tests/integration --cov=. --cov-report=xml:coverage.xml --cov-report=html --cov-report=json -vv -s + - name: SonarCloud Scan + uses: SonarSource/sonarqube-scan-action@master + if: github.event_name == 'pull_request' + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} + -Dsonar.pullrequest.key=${{ env.PR_NUMBER }} + -Dsonar.pullrequest.branch=${{ env.PR_HEAD }} + -Dsonar.pullrequest.base=${{ env.PR_BASE }} + black: name: Run black runs-on: ubuntu-latest diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index ff594420..00000000 --- a/sonar-project.properties +++ /dev/null @@ -1,32 +0,0 @@ -# Complete documentation with many more options at: -# https://docs.sonarqube.org/latest/analysis/analysis-parameters/ - -#sonar.host.url=https://sonarqube.corp.redhat.com - -## The unique project identifier. This is mandatory. -# Do not duplicate or reuse! -# Available characters: [a-zA-Z0-9_:\.\-] -# Must have least one non-digit. -# Recommended format: : -sonar.projectKey=ansible-dispatcherd - -sonar.organization=ansible - -# Customize what paths to scan. Default is . -sonar.sources=. -# Excluse test directories from sources -sonar.exclusions=tools/** -# Set tests root directory -sonar.tests=tests - -# Verbose name of project displayed in WUI. Default is set to the projectKey. This field is optional. -sonar.projectName=dispatcherd - -# Version of project. This field is optional. -#sonar.projectVersion=1.0 - -# Tell sonar scanner where coverage files exist -sonar.python.coverage.reportPaths=coverage.xml - -# Only scan with python3 -sonar.python.version=3.11,3.13 From 337bbada865c02a0d3cc396492224ef056cd6428 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Tue, 15 Apr 2025 13:00:38 -0400 Subject: [PATCH 3/3] Use other token --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4021f871..beb9ee7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: uses: SonarSource/sonarqube-scan-action@master if: github.event_name == 'pull_request' env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_TOKEN: ${{ secrets.CICD_ORG_SONAR_TOKEN_CICD_BOT }} with: args: > -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}