Skip to content

Commit 0ef088d

Browse files
authored
PYSCAN-72 Replace sonar-scanner by pysonar-scanner in CI pipeline (#74)
1 parent 542b203 commit 0ef088d

File tree

5 files changed

+6
-11
lines changed

5 files changed

+6
-11
lines changed

.cirrus.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ analysis_task:
8484
name: "SC Analysis"
8585
analysis_script:
8686
- poetry run pytest --cov-report=xml:coverage.xml --cov-config=pyproject.toml --cov=src --cov-branch tests
87-
- sonar-scanner -Dsonar.organization=sonarsource -DbuildNumber=${CI_BUILD_NUMBER}
87+
- poetry install
88+
- poetry run pysonar-scanner -Dsonar.organization=sonarsource -DbuildNumber=${CI_BUILD_NUMBER}
8889
always:
8990
pytest_artifacts:
9091
path: "coverage.xml"

.cirrus/poetry.Dockerfile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ FROM ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-latest
33

44
USER root
55

6-
ARG SCANNER_VERSION=5.0.1.3006
76
ARG PYTHON_VERSION=3.12.1
87

98
# install required dependencies to build Python from source see: https://devguide.python.org/getting-started/setup-building/#install-dependencies
@@ -17,15 +16,9 @@ RUN cd /usr/local/bin \
1716
&& ln -s pip${PYTHON_VERSION%.*} pip \
1817
&& ln -s pip${PYTHON_VERSION%.*} pip3
1918

20-
RUN curl "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SCANNER_VERSION}.zip" -o /tmp/sonar-scanner.zip \
21-
&& unzip -d /opt /tmp/sonar-scanner.zip \
22-
&& mv /opt/sonar-scanner-${SCANNER_VERSION} /opt/sonar-scanner \
23-
&& rm /tmp/sonar-scanner.zip
24-
2519
USER sonarsource
2620

2721
RUN curl -sSL https://install.python-poetry.org | python3 -
28-
ENV PATH="${PATH}:/opt/sonar-scanner/bin"
2922
ENV PATH="${PATH}:/home/sonarsource/.local/bin"
3023

3124
ENV SONARCLOUD_ANALYSIS true

its/tests/test_analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_minimal_project_read_poetry_data(sonarqube_client: SonarQubeClient):
4646
def test_minimal_project_unexpected_arg(sonarqube_client: SonarQubeClient):
4747
process = CliClient().run_analysis(sonarqube_client, params=["-unexpected"], sources_dir="minimal")
4848
assert process.returncode == 0
49-
assert "ERROR: Unrecognized option: -unexpected" in process.stdout
49+
assert "ERROR Unrecognized option: -unexpected" in process.stdout
5050

5151

5252
def test_minimal_project_wrong_home(sonarqube_client: SonarQubeClient):

its/utils/cli_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ class CliClient():
2929
SOURCES_FOLDER_PATH: str = os.path.join(
3030
os.path.dirname(__file__), "../sources")
3131

32-
def run_analysis(self, client: SonarQubeClient, params: list[str] = None, sources_dir: str = None) -> CompletedProcess:
32+
def run_analysis(self, client: SonarQubeClient, params: list[str] = [], sources_dir: str = None) -> CompletedProcess:
3333
if params is None:
3434
params = []
35+
params.append("-Dsonar.host.url=http://localhost:9000")
3536
workdir = os.path.join(self.SOURCES_FOLDER_PATH, sources_dir)
3637
command = [self.SCANNER_CMD] + params
3738
process = subprocess.run(command, stdout=subprocess.PIPE,

src/pysonar_scanner/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Configuration:
4141
def __init__(self):
4242
self.log = ApplicationLogger.get_logger()
4343
self.sonar_scanner_path = ".scanner"
44-
self.sonar_scanner_version = "6.1.0.4477"
44+
self.sonar_scanner_version = "6.0.0.4432"
4545
self.sonar_scanner_executable_path = ""
4646
self.scan_arguments = []
4747
self.wrapper_arguments = argparse.Namespace(debug=False, read_project_config=False)

0 commit comments

Comments
 (0)