From 7dcc4fcf3af39f458dcd92f9b3fc94724684ec57 Mon Sep 17 00:00:00 2001 From: Dominic Kempf Date: Mon, 19 Aug 2024 10:42:24 +0200 Subject: [PATCH] Remove sonarcloud integration --- README.md | 6 -- cookiecutter.json | 4 +- hooks/post_gen_project.py | 2 - hooks/pre_gen_project.py | 15 ---- tests/test_bake_project.py | 22 ----- tests/test_deploy_bake.py | 2 - .../.github/workflows/sonarcloud.yml | 84 ------------------- .../FILESTRUCTURE.md | 8 -- {{cookiecutter.project_slug}}/README.md | 3 - {{cookiecutter.project_slug}}/TODO.md | 8 -- .../sonar-project.properties | 19 ----- 11 files changed, 1 insertion(+), 172 deletions(-) delete mode 100644 {{cookiecutter.project_slug}}/.github/workflows/sonarcloud.yml delete mode 100644 {{cookiecutter.project_slug}}/sonar-project.properties diff --git a/README.md b/README.md index 162e626..6379085 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ The core features of our C++ Cookiecutter in a nutshell: * CI-based deployment of Python wheels to PyPI * Generated [pre-commit](https://pre-commit.com/) configuration is added if you have `pre-commit` installed * Integration with coverage testing from [codecov.io](https://codecov.io) -* Integration with code quality analysis from [sonarcloud.io](https://sonarcloud.io/) * Based on an established tool: [Cookiecutter](https://github.com/cookiecutter/cookiecutter) has >15k stars on Github! # Prerequisites @@ -84,11 +83,6 @@ This cookiecutter accepts the following configuration options: generated in the Github UI. * `codecovio`: Whether an automatic integration with coverage checking from [codecov.io](https://codecov.io) should be set up. This requires an Open Source license in order to be free to use. -* `sonarcloud`: Whether an automatic integration with code quality analysis from [sonarcloud.io](https://sonarcloud.io/) - should be set up. Sonarcloud requires an Open Source license in order to be free to use. - This feature requires a bit of setup, but will give you access to a very powerful code - analysis tool. Currently, we only support SonarCloud analysis in combination with Github - Actions CI and a Github remote repository. If you are using `cookiecutter-cpp-project` a lot, you can customize your default values by providing a `.cookiecutterrc` file in your home directory, for more details see the diff --git a/cookiecutter.json b/cookiecutter.json index da5cc5a..32e1f4c 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -15,7 +15,6 @@ "python_bindings": ["No", "Yes"], "pypi_release": "{{ cookiecutter.python_bindings }}", "codecovio": ["Yes", "No"], - "sonarcloud": ["No", "Yes"], "_extensions": [ "local_extensions.PrecommitExtension", "local_extensions.ShortcutExtension", @@ -24,6 +23,5 @@ "__python_module": "{{ cookiecutter|modname }}", "_catch_version": "2.13.10", "_cibuildwheel_version": "2.13.1", - "_pybind_version": "2.10.4", - "_sonarscanner_version": "4.7.0.2747" + "_pybind_version": "2.10.4" } diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 79eb732..1db99ec 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -79,8 +79,6 @@ def conditional_remove(condition, path): conditional_remove("{{ cookiecutter.python_bindings }}" == "No", "tests/python") conditional_remove("{{ cookiecutter.pypi_release }}" != "Yes", ".github/workflows/pypi.yml") conditional_remove("{{ cookiecutter.codecovio }}" == "No", "codecov.yml") -conditional_remove("{{ cookiecutter.sonarcloud }}" == "No", "sonar-project.properties") -conditional_remove("{{ cookiecutter.sonarcloud }}" == "No", ".github/workflows/sonarcloud.yml") conditional_remove("{{ cookiecutter.github_actions_ci }}" == "No", ".github") conditional_remove("{{ cookiecutter.external_dependency }}" == "None", "{{ cookiecutter.project_slug }}Config.cmake.in") conditional_remove(not {{ have_precommit }}, ".pre-commit-config.yaml") diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py index 0b986ee..fd9576f 100644 --- a/hooks/pre_gen_project.py +++ b/hooks/pre_gen_project.py @@ -38,18 +38,3 @@ def fail_if(condition, message): "{{ cookiecutter.codecovio }}" == "Yes" and "{{ cookiecutter.license }}" == "None", "Coverage reports for codecov.io require an open source license for your project" ) - -fail_if( - "{{ cookiecutter.sonarcloud }}" == "Yes" and "{{ cookiecutter.license }}" == "None", - "Code quality analysis from sonarcloud.io requires an open source license for your project" -) - -fail_if( - "{{ cookiecutter.sonarcloud }}" == "Yes" and "{{ cookiecutter.github_actions_ci }}" == "No", - "Code quality analysis from sonarcloud.io is currently only supported in combination with Github Actions CI" -) - -fail_if( - "{{ cookiecutter.sonarcloud }}" == "Yes" and "github.com" not in "{{ cookiecutter.remote_url }}", - "Code quality analysis from sonarcloud.io is currently only supported in combination with a Github remote repository" -) diff --git a/tests/test_bake_project.py b/tests/test_bake_project.py index cea2afc..29a7026 100644 --- a/tests/test_bake_project.py +++ b/tests/test_bake_project.py @@ -52,7 +52,6 @@ def test_ctest_run(cookies, submodules, header_only): 'project_slug': 'test_project', 'use_submodules': submodules, 'header_only': header_only, - 'sonarcloud': 'No', } ) check_bake(bake) @@ -67,14 +66,12 @@ def test_cmake_installation(cookies, header_only): extra_context={ 'project_slug': 'downstream', 'header_only': 'No', - 'sonarcloud': 'No', } ) upstream_bake = cookies.bake( extra_context={ 'project_slug': 'upstream', 'header_only': header_only, - 'sonarcloud': 'No', } ) with inside_bake(upstream_bake): @@ -122,7 +119,6 @@ def test_readthedocs(cookies): bake = cookies.bake( extra_context={ 'readthedocs': 'Yes', - 'sonarcloud': 'No', } ) check_bake(bake) @@ -136,7 +132,6 @@ def test_doxygen(cookies): bake = cookies.bake( extra_context={ 'doxygen': 'Yes', - 'sonarcloud': 'No', } ) check_bake(bake) @@ -153,14 +148,12 @@ def test_github_actions_ci(cookies): 'github_actions_ci': 'Yes', 'python_bindings': 'Yes', 'pypi_release': 'Yes', - 'sonarcloud': 'Yes', } ) check_bake(bake) with inside_bake(bake): check_file_against_schemastore(".github/workflows/ci.yml", "https://json.schemastore.org/github-workflow") check_file_against_schemastore(".github/workflows/pypi.yml", "https://json.schemastore.org/github-workflow") - check_file_against_schemastore(".github/workflows/sonarcloud.yml", "https://json.schemastore.org/github-workflow") @pytest.mark.local @@ -168,7 +161,6 @@ def test_gitlabci(cookies): bake = cookies.bake( extra_context={ 'gitlab_ci': 'Yes', - 'sonarcloud': 'No', } ) check_bake(bake) @@ -184,7 +176,6 @@ def test_python(cookies, virtualenv, submodules): 'project_slug': 'my-project', 'python_bindings': 'Yes', 'submodules': submodules, - 'sonarcloud': 'No', } ) check_bake(bake) @@ -214,18 +205,6 @@ def test_codecov_without_license(cookies): assert bake.exit_code != 0 -@pytest.mark.local -def test_sonarcloud_without_license(cookies): - bake = cookies.bake(extra_context={'license': 'None', 'sonarcloud': 'Yes'}) - assert bake.exit_code != 0 - - -@pytest.mark.local -def test_sonarcloud_without_github(cookies): - bake = cookies.bake(extra_context={'github_actions_ci': 'No', 'sonarcloud': 'Yes'}) - assert bake.exit_code != 0 - - @pytest.mark.local @pytest.mark.parametrize( "remote_url", @@ -243,7 +222,6 @@ def test_remote_urls(cookies, remote_url): "github_actions_ci": "Yes", "gitlab_ci": "Yes", "remote_url": remote_url, - "sonarcloud": "No", } ) check_bake(bake) diff --git a/tests/test_deploy_bake.py b/tests/test_deploy_bake.py index 5677e25..36feb96 100644 --- a/tests/test_deploy_bake.py +++ b/tests/test_deploy_bake.py @@ -23,7 +23,6 @@ def test_push_remote(cookies): 'pypi_release': 'Yes', 'use_submodules': 'No', 'codecovio': 'Yes', - 'sonarcloud': 'Yes', } ) with inside_bake(bake): @@ -59,7 +58,6 @@ def check_workflow(name): assert workflow.conclusion == 'success' check_workflow("ci.yml") - check_workflow("sonarcloud.yml") @pytest.mark.integrations diff --git a/{{cookiecutter.project_slug}}/.github/workflows/sonarcloud.yml b/{{cookiecutter.project_slug}}/.github/workflows/sonarcloud.yml deleted file mode 100644 index 646c8cd..0000000 --- a/{{cookiecutter.project_slug}}/.github/workflows/sonarcloud.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: SonarCloud Analysis - -on: - push: - branches: - - main - pull_request: - types: - - opened - - synchronize - - reopened - -env: -{%- if cookiecutter.use_submodules == "No" %} - CATCH2_VERSION: {{ cookiecutter._catch_version }} -{%- if cookiecutter.python_bindings == "Yes" %} - PYBIND11_VERSION: {{ cookiecutter._pybind_version }} -{%- endif %} -{%- endif %} - SONAR_SCANNER_VERSION: {{ cookiecutter._sonarscanner_version }} - -jobs: - sonarcloud: - name: SonarCloud - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - submodules: 'recursive' - -{% if cookiecutter.use_submodules == "No" %} - - name: Install Catch2 - run: | - git clone -b v$CATCH2_VERSION https://github.com/catchorg/Catch2.git - cd Catch2 - mkdir build - cd build - cmake -DBUILD_TESTING=OFF .. - sudo cmake --build . --target install -{% if cookiecutter.python_bindings == "Yes" %} - - name: Install Pybind11 - run: | - git clone -b v$PYBIND11_VERSION https://github.com/pybind/pybind11.git - cd pybind11 - mkdir build - cd build - cmake -DBUILD_TESTING=OFF .. - sudo cmake --build . --target install -{%- endif %} -{%- endif %} - - name: Install the SonarCloud Client + build wrapper - run: | - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ - curl --create-dirs -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/ - - - name: Cache SonarCloud analysis results across runs - uses: actions/cache@v3 - with: - path: $HOME/.sonarcache - key: sonar-${{ "{{ github.job }}" }}-{{ "${{ runner.os }}" }}-${{ "{{ github.sha }}" }} - restore-keys: sonar-${{ "{{ github.job }}" }}-${{ "{{ runner.os }}" }}- - - - name: Compile, Run and Analyse the tests - run: | - mkdir build - cd build - cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="--coverage" -DBUILD_DOCS=OFF - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output cmake --build . - ctest - mkdir gcov - cd gcov -{%- if cookiecutter.header_only == "Yes" %} - gcov -p ../tests/CMakeFiles/tests.dir/*.cpp.gcno > /dev/null -{%- else %} - gcov -p ../tests//CMakeFiles/{{ cookiecutter.project_slug }}.dir/*.cpp.gcno > /dev/null -{%- endif %} - cd ../.. - $HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux/bin/sonar-scanner - env: - SONAR_TOKEN: ${{ "{{ secrets.SONAR_TOKEN }}" }} - GITHUB_TOKEN: ${{ "{{secrets.GITHUB_TOKEN }}" }} diff --git a/{{cookiecutter.project_slug}}/FILESTRUCTURE.md b/{{cookiecutter.project_slug}}/FILESTRUCTURE.md index b8e710d..be2f14b 100644 --- a/{{cookiecutter.project_slug}}/FILESTRUCTURE.md +++ b/{{cookiecutter.project_slug}}/FILESTRUCTURE.md @@ -82,14 +82,6 @@ generated for you: provided file is the default configuration plus suitable exclusions. For more options, check their [configuration reference](https://docs.codecov.io/docs/codecov-yaml). {%- endif %} -{%- if cookiecutter.sonarcloud == "Yes" %} - * `sonar-project.properties` configures the code analysis on SonarCloud. The provided - default parameters should be sufficient for most users. If they are not for you, - you should have a look at the [Analysis Parameters Reference](https://docs.sonarqube.org/latest/analysis/analysis-parameters/) - and at the [Documentation for C/C++/Objective-C](https://docs.sonarqube.org/latest/analysis/languages/cfamily/). - * `.github/workflows/sonarcloud.yml` is the Github workflow that triggers the SonarCloud - analysis. The provided default should be sufficient for most users. -{%- endif %} * Markdown files with meta information on the project. [Markdown](https://www.markdownguide.org/basic-syntax/) is a good language for these files, as it is easy to write and rendered into something beautiful by your git repository hosting provider. diff --git a/{{cookiecutter.project_slug}}/README.md b/{{cookiecutter.project_slug}}/README.md index 934e9bc..17912f6 100644 --- a/{{cookiecutter.project_slug}}/README.md +++ b/{{cookiecutter.project_slug}}/README.md @@ -34,9 +34,6 @@ {% if cookiecutter.codecovio == "Yes" -%} [![codecov](https://codecov.io/{{ cookiecutter|provider_acronym }}/{{ cookiecutter|username }}/{{ cookiecutter|remote_slug }}/branch/main/graph/badge.svg)](https://codecov.io/{{ cookiecutter|provider_acronym }}/{{ cookiecutter|username }}/{{ cookiecutter|remote_slug }}) {%- endif %} -{% if cookiecutter.sonarcloud == "Yes" -%} -[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project={{ cookiecutter|username }}_{{ cookiecutter|remote_slug }}&metric=alert_status)](https://sonarcloud.io/dashboard?id={{ cookiecutter|username }}_{{ cookiecutter|remote_slug }}) -{%- endif %} {{ "\n" -}} # Prerequisites diff --git a/{{cookiecutter.project_slug}}/TODO.md b/{{cookiecutter.project_slug}}/TODO.md index fae38f3..ab73358 100644 --- a/{{cookiecutter.project_slug}}/TODO.md +++ b/{{cookiecutter.project_slug}}/TODO.md @@ -63,11 +63,3 @@ The following tasks need to be done to get a fully working project: to the Settings Tab. Within setting, get your token for this repository and put store it as a secret called `CODECOV_TOKEN` for GitHub Actions. {%- endif %} -{%- if cookiecutter.sonarcloud == "Yes" %} -* Enable the integration with `sonarcloud.io` by heading to the [Sonarcloud.io Website](https://sonarcloud.io), - log in (e.g. with your Github credentials), add the repository and select *Github Actions* as the - preferred method of integration. Follow step 1 and set up the secret variable `SONAR_TOKEN`. Step 2 - and 3 are already taken care of by this cookiecutter. In order to have the SonarCloud badge in the - README show something meaningful, a *New Code Definition* needs to be configured in Sonarcloud under - *Administration/New Code*. -{%- endif %} \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/sonar-project.properties b/{{cookiecutter.project_slug}}/sonar-project.properties deleted file mode 100644 index fbda169..0000000 --- a/{{cookiecutter.project_slug}}/sonar-project.properties +++ /dev/null @@ -1,19 +0,0 @@ -{%- set username = "None" if cookiecutter.remote_url == "None" else cookiecutter.remote_url.split("/")[-2].split(":")[-1] -%} -{%- set remote_slug = "None" if cookiecutter.remote_url == "None" else cookiecutter.remote_url.replace(".git", "").split("/")[-1] -%} -sonar.projectKey={{ username }}_{{ remote_slug }} -sonar.organization={{ username }} -sonar.host.url=https://sonarcloud.io - -# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. -sonar.sources={% if cookiecutter.header_only == "Yes" %}tests,include{% else %}src{% endif %} - -# Exclusions -sonar.coverage.exclusions=tests/*,ext/* -sonar.test.exclusions=tests/* - -# Properties specific to the C/C++ analyzer: -sonar.cfamily.threads=2 -sonar.cfamily.cache.enabled=true -sonar.cfamily.cache.path=/home/runner/.sonarcache -sonar.cfamily.build-wrapper-output=build/bw-output -sonar.cfamily.gcov.reportsPath=build/gcov