From 59a3dc946b978bbeb7858b2cf53ddd8d112c61e9 Mon Sep 17 00:00:00 2001 From: Dominic Kempf Date: Thu, 9 Jan 2025 12:58:13 +0100 Subject: [PATCH] Restrict codecov integration to GHA and make it tokenless --- cookiecutter.json | 2 +- hooks/pre_gen_project.py | 5 ++++ tests/test_bake_project.py | 6 ++++ .../.github/workflows/ci.yml | 28 ++----------------- {{cookiecutter.project_slug}}/.gitlab-ci.yml | 17 ----------- {{cookiecutter.project_slug}}/TODO.md | 5 ++-- 6 files changed, 17 insertions(+), 46 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index 32e1f4c..2b3d80a 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -14,7 +14,7 @@ "cxx_minimum_standard": ["11", "14", "17", "20"], "python_bindings": ["No", "Yes"], "pypi_release": "{{ cookiecutter.python_bindings }}", - "codecovio": ["Yes", "No"], + "codecovio": ["{%- if cookiecutter.github_actions_ci == 'Yes' -%}Yes{%- else -%}No{%- endif -%}", "{%- if cookiecutter.github_actions_ci == 'Yes' -%}No{%- else -%}Yes{%- endif -%}"], "_extensions": [ "local_extensions.PrecommitExtension", "local_extensions.ShortcutExtension", diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py index fd9576f..3998bcb 100644 --- a/hooks/pre_gen_project.py +++ b/hooks/pre_gen_project.py @@ -38,3 +38,8 @@ 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.codecovio }}" == "Yes" and "{{ cookiecutter.github_actions_ci }}" == "No", + "Coverage reports for codecov.io are only supported for Github Actions CI" +) diff --git a/tests/test_bake_project.py b/tests/test_bake_project.py index 29a7026..31d9195 100644 --- a/tests/test_bake_project.py +++ b/tests/test_bake_project.py @@ -205,6 +205,12 @@ def test_codecov_without_license(cookies): assert bake.exit_code != 0 +@pytest.mark.local +def test_codecov_without_github_actions(cookies): + bake = cookies.bake(extra_context={'github_actions_ci': 'No', 'codecovio': 'Yes'}) + assert bake.exit_code != 0 + + @pytest.mark.local @pytest.mark.parametrize( "remote_url", diff --git a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml index d3fe73d..2eba7b4 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml @@ -140,8 +140,7 @@ jobs: sudo apt-get install -y lcov {% if cookiecutter.use_submodules == "No" %} - - name: Install Catch2 (Linux + MacOS) - if: runner.os != 'Windows' + - name: Install Catch2 run: | git clone -b v$CATCH2_VERSION https://github.com/catchorg/Catch2.git cd Catch2 @@ -150,17 +149,8 @@ jobs: cmake -DBUILD_TESTING=OFF .. sudo cmake --build . --target install - - name: Install Catch2 (Windows) - if: runner.os == 'Windows' - run: | - git clone -b v$Env:CATCH2_VERSION https://github.com/catchorg/Catch2.git - cd Catch2 - mkdir build - cd build - cmake -DBUILD_TESTING=OFF .. - cmake --build . --target install {% if cookiecutter.python_bindings == "Yes" %} - - name: Install Pybind11 (Linux + MacOS) + - name: Install Pybind11 if: runner.os != 'Windows' run: | git clone -b v$PYBIND11_VERSION https://github.com/pybind/pybind11.git @@ -169,16 +159,6 @@ jobs: cd build cmake -DBUILD_TESTING=OFF .. sudo cmake --build . --target install - - - name: Install Pybind11 (Windows) - if: runner.os == 'Windows' - run: | - git clone -b v$Env:PYBIND11_VERSION https://github.com/pybind/pybind11.git - cd pybind11 - mkdir build - cd build - cmake -DBUILD_TESTING=OFF .. - cmake --build . --target install {%- endif %} {%- endif %} @@ -207,10 +187,8 @@ jobs: lcov --directory ./build{% if cookiecutter.header_only == "No" %}/src{% endif %} --capture --output-file coverage.info - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v5 with: fail_ci_if_error: true files: ${{ "{{github.workspace}}" }}/coverage.info - env: - CODECOV_TOKEN: ${{ "{{ secrets.CODECOV_TOKEN }}" }} {% endif %} diff --git a/{{cookiecutter.project_slug}}/.gitlab-ci.yml b/{{cookiecutter.project_slug}}/.gitlab-ci.yml index 3dde5d8..7b5fa71 100644 --- a/{{cookiecutter.project_slug}}/.gitlab-ci.yml +++ b/{{cookiecutter.project_slug}}/.gitlab-ci.yml @@ -43,20 +43,3 @@ build-and-test:gcc: build-and-test:clang: image: conanio/clang10 <<: *template - -{% if cookiecutter.codecovio == "Yes" -%} -generate-coverage-report: - image: conanio/gcc7 - <<: *template - script: - - sudo apt-get update - - sudo apt-get install -yy lcov - - cmake -E make_directory build - - cd build - - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="--coverage" -DBUILD_DOCS=OFF .. - - cmake --build . - - ctest - - cd .. - - lcov --directory ./build{% if cookiecutter.header_only == "No" %}/src{% endif %} --capture --output-file coverage.info - - bash <(curl --connect-timeout 10 --retry 5 -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports" -{%- endif %} diff --git a/{{cookiecutter.project_slug}}/TODO.md b/{{cookiecutter.project_slug}}/TODO.md index ab73358..b1f5e45 100644 --- a/{{cookiecutter.project_slug}}/TODO.md +++ b/{{cookiecutter.project_slug}}/TODO.md @@ -59,7 +59,6 @@ The following tasks need to be done to get a fully working project: {%- if cookiecutter.codecovio == "Yes" %} * Enable the integration with `codecov.io` by heading to the [Codecov.io Website](https://codecov.io), log in (e.g. with your Github credentials) and enable integration for your repository. In order to do - so, you need to select it from the list of repositories (potentially re-syncing with GitHub) and head - 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. + so, you need to select it from the list of repositories (potentially re-syncing with GitHub). Then, head + to the "Settings" Tab and select "Global Upload Token". Here, you should select the "not required" option. {%- endif %}