From de2bab13c61b26b99e24772740e973a809230c3d Mon Sep 17 00:00:00 2001 From: Arjun Rajappa Date: Thu, 21 Aug 2025 18:31:34 +0530 Subject: [PATCH 1/7] ci: enable sonar scanning and report results to sonacloud.io Signed-off-by: Arjun Rajappa --- .circleci/config.yml | 39 +++++++++++++++++++++++---------------- sonar-project.properties | 6 +++--- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 57495e70..aa5ce38a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -90,29 +90,36 @@ commands: steps: - attach_workspace: at: . - - run: - name: Install Java - command: | - sudo apt-get update - sudo apt-get install openjdk-11-jdk - run: name: Run SonarQube to report the coverage command: | . venv/bin/activate coverage combine ./coverage_results coverage xml -i - wget -O /tmp/sonar-scanner-cli.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.1.3023.zip - unzip -d /tmp /tmp/sonar-scanner-cli.zip - if [[ -n "${CIRCLE_PR_NUMBER}" ]]; then - /tmp/sonar-scanner-4.8.1.3023/bin/sonar-scanner \ - -Dsonar.host.url=${SONARQUBE_URL} \ - -Dsonar.login="${SONARQUBE_LOGIN}" \ - -Dsonar.pullrequest.key="${CIRCLE_PR_NUMBER}" \ + + PR_NUMBER=$(echo ${CIRCLE_PULL_REQUEST} | sed 's/.*\///') + SONAR_SCANNER_VERSION=7.2.0.5079 + export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux-x64 + SONAR_TOKEN=${SONAR_TOKEN} + + curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux-x64.zip + unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ + export PATH=$SONAR_SCANNER_HOME/bin:$PATH + export SONAR_SCANNER_OPTS="-server" + if [[ -n "${PR_NUMBER}" ]]; then + sonar-scanner \ + -Dsonar.organization=instana \ + -Dsonar.projectKey=instana_python-sensor \ + -Dsonar.sources=. \ + -Dsonar.host.url="${SONARQUBE_URL}" \ + -Dsonar.pullrequest.key="${PR_NUMBER}" \ -Dsonar.pullrequest.branch="${CIRCLE_BRANCH}" else - /tmp/sonar-scanner-4.8.1.3023/bin/sonar-scanner \ - -Dsonar.host.url=${SONARQUBE_URL} \ - -Dsonar.login="${SONARQUBE_LOGIN}" \ + sonar-scanner \ + -Dsonar.organization=instana \ + -Dsonar.projectKey=instana_python-sensor \ + -Dsonar.sources=. \ + -Dsonar.host.url="${SONARQUBE_URL}" \ -Dsonar.branch.name="${CIRCLE_BRANCH}" fi - store_artifacts: @@ -296,7 +303,7 @@ jobs: - pip-install-deps - pip-install-tests-deps - store-pytest-results - # - run_sonarqube + - run_sonarqube workflows: tests: diff --git a/sonar-project.properties b/sonar-project.properties index 56b3d211..fcb6f56d 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,5 +1,6 @@ -sonar.projectKey=Python-Tracer -sonar.projectName=Python Tracer +sonar.projectKey=instana_python-sensor +sonar.organization=instana +sonar.projectName=python-sensor sonar.sourceEncoding=utf-8 sonar.sources=src/instana/ sonar.tests=tests/ @@ -8,4 +9,3 @@ sonar.python.version=3 sonar.links.homepage=https://github.com/instana/python-sensor/ sonar.links.ci=https://circleci.com/gh/instana/python-sensor sonar.links.issue=https://github.com/instana/python-sensor/issues -sonar.links.scm=https://github.com/instana/python-sensor/ From d6e52216671151da746752c6cb3f23bd9782e1ec Mon Sep 17 00:00:00 2001 From: Arjun Rajappa Date: Thu, 21 Aug 2025 18:42:08 +0530 Subject: [PATCH 2/7] ci: update test inclusions in sonar scan Signed-off-by: Arjun Rajappa --- sonar-project.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/sonar-project.properties b/sonar-project.properties index fcb6f56d..217abbee 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -4,6 +4,7 @@ sonar.projectName=python-sensor sonar.sourceEncoding=utf-8 sonar.sources=src/instana/ sonar.tests=tests/ +sonar.test.inclusions=test/**/* sonar.python.coverage.reportPaths=coverage.xml sonar.python.version=3 sonar.links.homepage=https://github.com/instana/python-sensor/ From 70aef0145bef02ecf681c6d1d697db92ede0c541 Mon Sep 17 00:00:00 2001 From: Arjun Rajappa Date: Fri, 22 Aug 2025 12:53:37 +0530 Subject: [PATCH 3/7] ci: update pyhton dep Installation Signed-off-by: Arjun Rajappa --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index aa5ce38a..a9ae1237 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -93,9 +93,9 @@ commands: - run: name: Run SonarQube to report the coverage command: | + python -m venv venv . venv/bin/activate - coverage combine ./coverage_results - coverage xml -i + pip install --upgrade pip coverage PR_NUMBER=$(echo ${CIRCLE_PULL_REQUEST} | sed 's/.*\///') SONAR_SCANNER_VERSION=7.2.0.5079 From ddf8c1083a502fc9352dede22353cc917d056199 Mon Sep 17 00:00:00 2001 From: Arjun Rajappa Date: Fri, 22 Aug 2025 13:09:08 +0530 Subject: [PATCH 4/7] ci: use python 3.13 for final_job Signed-off-by: Arjun Rajappa --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a9ae1237..12d9d010 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -295,7 +295,7 @@ jobs: final_job: docker: - - image: public.ecr.aws/docker/library/python:3.9 + - image: public.ecr.aws/docker/library/python:3.13 working_directory: ~/repo steps: - checkout From d53eb8a7cebdba99edc8277f50cbebcb6e87d90e Mon Sep 17 00:00:00 2001 From: Arjun Rajappa Date: Mon, 25 Aug 2025 09:44:13 +0530 Subject: [PATCH 5/7] ci: use pysonar scanner a python library to scan the repo Signed-off-by: Arjun Rajappa --- .circleci/config.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 12d9d010..deb16ed6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -96,18 +96,17 @@ commands: python -m venv venv . venv/bin/activate pip install --upgrade pip coverage + coverage combine ./coverage_results + coverage xml -i PR_NUMBER=$(echo ${CIRCLE_PULL_REQUEST} | sed 's/.*\///') - SONAR_SCANNER_VERSION=7.2.0.5079 - export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux-x64 SONAR_TOKEN=${SONAR_TOKEN} - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux-x64.zip - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ - export PATH=$SONAR_SCANNER_HOME/bin:$PATH + pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ pysonar-scanner export SONAR_SCANNER_OPTS="-server" + if [[ -n "${PR_NUMBER}" ]]; then - sonar-scanner \ + pysonar-scanner \ -Dsonar.organization=instana \ -Dsonar.projectKey=instana_python-sensor \ -Dsonar.sources=. \ @@ -115,7 +114,7 @@ commands: -Dsonar.pullrequest.key="${PR_NUMBER}" \ -Dsonar.pullrequest.branch="${CIRCLE_BRANCH}" else - sonar-scanner \ + pysonar-scanner \ -Dsonar.organization=instana \ -Dsonar.projectKey=instana_python-sensor \ -Dsonar.sources=. \ From 999156f01b9dc74b55e495f9319af16fb3e64db9 Mon Sep 17 00:00:00 2001 From: Arjun Rajappa Date: Mon, 25 Aug 2025 10:21:37 +0530 Subject: [PATCH 6/7] ci: read sonar.sources from properties file Signed-off-by: Arjun Rajappa --- .circleci/config.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index deb16ed6..b921433e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -93,9 +93,7 @@ commands: - run: name: Run SonarQube to report the coverage command: | - python -m venv venv . venv/bin/activate - pip install --upgrade pip coverage coverage combine ./coverage_results coverage xml -i @@ -109,7 +107,6 @@ commands: pysonar-scanner \ -Dsonar.organization=instana \ -Dsonar.projectKey=instana_python-sensor \ - -Dsonar.sources=. \ -Dsonar.host.url="${SONARQUBE_URL}" \ -Dsonar.pullrequest.key="${PR_NUMBER}" \ -Dsonar.pullrequest.branch="${CIRCLE_BRANCH}" @@ -117,7 +114,6 @@ commands: pysonar-scanner \ -Dsonar.organization=instana \ -Dsonar.projectKey=instana_python-sensor \ - -Dsonar.sources=. \ -Dsonar.host.url="${SONARQUBE_URL}" \ -Dsonar.branch.name="${CIRCLE_BRANCH}" fi From 6c594514ade5d196ae8f9bb318212bef96cfd89a Mon Sep 17 00:00:00 2001 From: Arjun Rajappa Date: Mon, 25 Aug 2025 14:25:51 +0530 Subject: [PATCH 7/7] ci: remove unwanted steps from final job Signed-off-by: Arjun Rajappa --- .circleci/config.yml | 6 +++--- sonar-project.properties | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b921433e..6be64dba 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -93,7 +93,10 @@ commands: - run: name: Run SonarQube to report the coverage command: | + python -m venv venv . venv/bin/activate + + pip install --upgrade pip coverage coverage combine ./coverage_results coverage xml -i @@ -295,9 +298,6 @@ jobs: steps: - checkout - check-if-tests-needed - - pip-install-deps - - pip-install-tests-deps - - store-pytest-results - run_sonarqube workflows: diff --git a/sonar-project.properties b/sonar-project.properties index 217abbee..b373d6be 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,8 +3,6 @@ sonar.organization=instana sonar.projectName=python-sensor sonar.sourceEncoding=utf-8 sonar.sources=src/instana/ -sonar.tests=tests/ -sonar.test.inclusions=test/**/* sonar.python.coverage.reportPaths=coverage.xml sonar.python.version=3 sonar.links.homepage=https://github.com/instana/python-sensor/