From: Lott, Christopher (cl778h) Date: Tue, 15 Oct 2019 18:17:36 +0000 (-0400) Subject: Support sonarcloud in python projects X-Git-Tag: v0.46.0~7^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=79687552a7378b650a06d55245c83f699e787c7b;p=releng%2Fglobal-jjb.git Support sonarcloud in python projects Extend lf_tox_sonar with sonarcloud, sonarcloud-project-key, sonarcloud-project-organization, sonarcloud-api-token, tox-dir and tox-envs properties; also with lf-infra-tox-parameters macro. Use new sonarcloud property as guard for conditional builder step, if true use lf-infra-maven-sonarcloud, else use lf-infra-maven-sonar. Issue: RELENG-2418 Change-Id: Iafa2720da7f939a126374bc83191c328edcdc40b Signed-off-by: Lott, Christopher (cl778h) --- diff --git a/docs/jjb/lf-python-jobs.rst b/docs/jjb/lf-python-jobs.rst index 2e490fb1..0ef27d9b 100644 --- a/docs/jjb/lf-python-jobs.rst +++ b/docs/jjb/lf-python-jobs.rst @@ -128,7 +128,7 @@ Python Sonar with Tox Sonar scans for Python based repos. This job invokes tox to run tests and gather coverage statistics from the test results, then invokes -Maven to publish the results to a Sonar server. +Maven to publish the results to either a Sonar server or SonarCloud. To get the Sonar coverage results, file tox.ini must exist and contain coverage commands to run. @@ -137,8 +137,8 @@ The coverage commands define the code that gets executed by the test suites. Checking coverage does not guarantee that the tests execute properly, but it identifies code that is not executed by any test. -This job reuses the Sonar builder used in Java/Maven projects which -runs maven twice. The first invocation does nothing for Python +This job reuses the Sonar builders used for Java/Maven projects which +run maven twice. The first invocation does nothing for Python projects, so the job uses the goal 'validate' by default. The second invocation publishes results using the goal 'sonar:sonar' by default. @@ -196,6 +196,12 @@ https://docs.sonarqube.org/display/PLUG/Python+Coverage+Results+Import (default: a string with a shell comment) :python-version: Python version to invoke pip install of tox-pyenv (default: python2) + :sonarcloud: Whether or not to use SonarCloud ``true|false``. + (default: false) + :sonarcloud-project-key: SonarCloud project key. (default: '') + :sonarcloud-project-organization: SonarCloud project organization. + (default: '') + :sonarcloud-api-token: SonarCloud API Token. (default: '') :sonar-mvn-goal: The Maven goal to run the Sonar plugin. (default: sonar:sonar) :stream: Keyword used to represent a release code-name. Often the same as the branch. (default: master) @@ -205,6 +211,11 @@ https://docs.sonarqube.org/display/PLUG/Python+Coverage+Results+Import (default: 10) :submodule-disable: Disable submodule checkout operation. (default: false) + :tox-dir: Directory containing the project's tox.ini relative to + the workspace. The default uses tox.ini at the project root. + (default: '.') + :tox-envs: Tox environments to run. If blank run everything described + in tox.ini. (default: '') :gerrit_sonar_triggers: Override Gerrit Triggers. :gerrit_trigger_file_paths: Override file paths used to filter which file modifications trigger a build. Refer to JJB documentation for "file-path" details. diff --git a/jjb/lf-python-jobs.yaml b/jjb/lf-python-jobs.yaml index 7cae5b8a..df82d8fd 100644 --- a/jjb/lf-python-jobs.yaml +++ b/jjb/lf-python-jobs.yaml @@ -267,10 +267,16 @@ pre-build-script: "# pre-build script goes here" python-version: python3 sonar-mvn-goal: "sonar:sonar" + sonarcloud: false + sonarcloud-project-key: "" + sonarcloud-project-organization: "" + sonarcloud-api-token: "" stream: master submodule-recursive: true submodule-timeout: 10 submodule-disable: false + tox-dir: "." + tox-envs: "" gerrit_trigger_file_paths: - compare-type: REG_EXP @@ -291,6 +297,9 @@ project: "{project}" branch: "{branch}" stream: "{stream}" + - lf-infra-tox-parameters: + tox-dir: "{tox-dir}" + tox-envs: "{tox-envs}" - string: name: ARCHIVE_ARTIFACTS default: "{archive-artifacts}" @@ -320,11 +329,33 @@ - lf-provide-maven-settings: global-settings-file: "{mvn-global-settings}" settings-file: "{mvn-settings}" - - lf-infra-maven-sonar: - java-version: "{java-version}" - mvn-goals: "{mvn-goals}" - mvn-settings: "{mvn-settings}" - mvn-version: "{mvn-version}" + # With SonarCloud + - conditional-step: + condition-kind: boolean-expression + condition-expression: "{sonarcloud}" + steps: + - shell: echo 'Using SonarCloud' + - lf-infra-maven-sonarcloud: + java-version: "{java-version}" + mvn-goals: "{mvn-goals}" + mvn-settings: "{mvn-settings}" + mvn-version: "{mvn-version}" + sonarcloud-project-key: "{sonarcloud-project-key}" + sonarcloud-project-organization: "{sonarcloud-project-organization}" + sonarcloud-api-token: "{sonarcloud-api-token}" + # With SonarQube + - conditional-step: + condition-kind: not + condition-operand: + condition-kind: boolean-expression + condition-expression: "{sonarcloud}" + steps: + - shell: echo 'Using SonarQube' + - lf-infra-maven-sonar: + java-version: "{java-version}" + mvn-goals: "{mvn-goals}" + mvn-settings: "{mvn-settings}" + mvn-version: "{mvn-version}" publishers: - lf-infra-publish diff --git a/releasenotes/notes/sonarcloud-in-python-80ae1dcacff54ba5.yaml b/releasenotes/notes/sonarcloud-in-python-80ae1dcacff54ba5.yaml new file mode 100644 index 00000000..aa2fc578 --- /dev/null +++ b/releasenotes/notes/sonarcloud-in-python-80ae1dcacff54ba5.yaml @@ -0,0 +1,8 @@ +--- +upgrade: + - | + Extend lf_tox_sonar with sonarcloud, sonarcloud-project-key, + sonarcloud-project-organization, sonarcloud-api-token, tox-dir + and tox-envs properties; also with lf-infra-tox-parameters macro. + Use new sonarcloud property as guard for conditional builder step, + if true use lf-infra-maven-sonarcloud, else use lf-infra-maven-sonar.