diff --git a/tests/test_deploy_bake.py b/tests/test_deploy_bake.py index 714ba9f..5677e25 100644 --- a/tests/test_deploy_bake.py +++ b/tests/test_deploy_bake.py @@ -113,23 +113,6 @@ def rtd_api_request(endpoint): assert build["commit"] == sha -def codecov_api_verification(remote_url, token, sha): - def codecov_api_request(endpoint): - resp = requests.get('https://codecov.io/api/{}/{}'.format(remote_url, endpoint), - headers={'Authorization': 'token {}'.format(token)} - ) - return resp.json() - - # Poll the codecov.io API - commit = codecov_api_request('commit/{}'.format(sha))['commit'] - while commit['state'] != 'complete': - time.sleep(5) - commit = codecov_api_request('commit/{}'.format(sha))['commit'] - - # Assert 100% coverage - assert commit['totals']['c'] == '100' - - @pytest.mark.integrations @pytest.mark.flaky(max_runs=3, min_passes=1, rerun_filter=wait_five_seconds) @pytest.mark.timeout(120) @@ -139,25 +122,14 @@ def test_codecovio_github_deploy(): repo = gh.get_repo('dokempf/test-gha-cookiecutter') sha = repo.get_branch('main').commit.sha - codecov_api_verification( - 'gh/dokempf/test-gha-cookiecutter', - os.getenv('CODECOV_GH_API_ACCESS_TOKEN'), - sha - ) - - -@pytest.mark.integrations -@pytest.mark.flaky(max_runs=3, min_passes=1, rerun_filter=wait_five_seconds) -@pytest.mark.timeout(60) -def test_codecovio_gitlab_deploy(): - # Authenticate with Gitlab API - gl = gitlab.Gitlab('https://gitlab.com', private_token=os.getenv("GL_API_ACCESS_TOKEN")) - gl.auth() - project = gl.projects.get('dokempf/test-gitlab-ci-cookiecutter-cpp-project') - sha = project.branches.get('main').commit['id'] + # Ask CodeCov API for coverage information + resp = requests.get( + f'https://api.codecov.io/api/v2/github/dokempf/repos/test-gha-cookiecutter/totals', + headers={ + 'authorization': f'Bearer {os.getenv("CODECOV_GH_API_ACCESS_TOKEN")}' + }, + params={"sha": sha} + ).json() - codecov_api_verification( - 'gl/dokempf/test-gitlab-ci-cookiecutter-cpp-project', - os.getenv('CODECOV_GL_API_ACCESS_TOKEN'), - sha - ) + # Assert 100% coverage + assert resp['totals']['coverage'] == 100 diff --git a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml index 59a954e..2934245 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml @@ -205,5 +205,12 @@ jobs: working-directory: ${{ "{{runner.workspace}}" }} run: | 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" + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + fail_ci_if_error: true + files: ${{ "{{runner.workspace}}" }}/coverage.info + env: + CODECOV_TOKEN: ${{ "{{ secrets.CODECOV_TOKEN }}" }} {% endif %} diff --git a/{{cookiecutter.project_slug}}/TODO.md b/{{cookiecutter.project_slug}}/TODO.md index adde789..fae38f3 100644 --- a/{{cookiecutter.project_slug}}/TODO.md +++ b/{{cookiecutter.project_slug}}/TODO.md @@ -58,9 +58,10 @@ The following tasks need to be done to get a fully working project: {%- endif %} {%- 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. This will - allow you to have automatic coverage reports on pull requests, but is not necessary to display - the coverage badge in the README. + 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. {%- endif %} {%- if cookiecutter.sonarcloud == "Yes" %} * Enable the integration with `sonarcloud.io` by heading to the [Sonarcloud.io Website](https://sonarcloud.io),