Skip to content

Commit

Permalink
Merge pull request #125 from ssciwr/tokenless-codecov
Browse files Browse the repository at this point in the history
Restrict codecov integration to GHA and make it tokenless
  • Loading branch information
dokempf authored Jan 9, 2025
2 parents 34fdb78 + 55813dc commit c4a8bfb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 46 deletions.
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"cxx_minimum_standard": ["11", "14", "17", "20"],
"python_bindings": ["No", "Yes"],
"pypi_release": "{{ cookiecutter.python_bindings }}",
"codecovio": ["Yes", "No"],
"codecovio": "{{ cookiecutter.github_actions_ci }}",
"_extensions": [
"local_extensions.PrecommitExtension",
"local_extensions.ShortcutExtension",
Expand Down
5 changes: 5 additions & 0 deletions hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
6 changes: 6 additions & 0 deletions tests/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 3 additions & 25 deletions {{cookiecutter.project_slug}}/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 %}

Expand Down Expand Up @@ -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 %}
17 changes: 0 additions & 17 deletions {{cookiecutter.project_slug}}/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
5 changes: 2 additions & 3 deletions {{cookiecutter.project_slug}}/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
4 changes: 4 additions & 0 deletions {{cookiecutter.project_slug}}/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ comment:
require_changes: no

ignore:
- app
{%- if cookiecutter.python_bindings == "Yes" %}
- python
{%- endif %}
- "**/tests"
- "**/Catch2"

0 comments on commit c4a8bfb

Please sign in to comment.