2 - Getting a Codecov account and uploading coverage
Pull the latest frommain
andcreate a new branchstep2
git checkout maingit pullgit checkout -b 'step2
Before we continue, let’s create an account and set up our repository onCodecov
Create a Codecov account
Create an account on Codecov through oursignup page. We willConfigure
Codecov for our demo repository in the next steps, for now just make sure your groups and repositories are syncing.
Set up theTeam Bot, make sure theRole
allows the team bot to comment on PRs.
Now that we have set up our Codecov accounts, let’s upload coverage reports.
Add the Codecov token
For more information on tokens, seethe documentation.
ClickConfigure
on our demo repo, selectUsing Codecov's CLI
. We will only doStep 1
since we are using GitLabCI for this demo.
Toadd repository token as a secret to your CI Provider
, from the demo repository's page on GitLab, go toSettings -> CI/CD
. UnderVariables
,Add Variable
to add your token as shown below.
SelectAdd variable
to save.
Create GitLabCI pipeline
We need to create a configuration file for GitLabCI. The CI workflow below will checkout the code, install requirements, run tests, and upload the coverage reports to Codecov.
Add the following code to a new.gitlab-ci.yml
file at the root of your project
api: image: python:latest script: - pip install -r api/requirements.txt - pytest --cov api/ - curl -Os https://cli.codecov.io/latest/linux/codecov - chmod +x codecov - ./codecov upload-process -t $CODECOV_TOKEN
Commit the changes and run the CI workflow
Let’s commit our code and open a pull request. Run
git add .git commit -m 'step2: upload coverage reports to Codecov'git push origin step2
Next, go to the demo repository on GitLab and open a merge request, which will run our GitLabCI pipeline for the first time.
When opening merge requests, be sure to select your own repository as the target branch, orset your project's default target branch
🚧
Token not found
You should expect to see
['info'] -> Token found by environment variables
in the logs in your CI. If you are not seeing this, make sure that you have added the variable and that the CI pipeline has access to the variable.
You will see status checks on the MR from the CI. You can click on them to see the progress of the CI/CD. Once complete, you will receive status checks and a comment from Codecov.

codecov/patch
andcodecov/project
status checks
codecov/patch
andcodecov/project
status checksOne of Codecov’s core uses is getting code coverage information directly in a developer’s workflow. The status checks shown above are part of that.
- The
patch
check is used for code changed in a PR, this is enabled by default. - The
project
check is used to maintain a coverage percentage across an entire codebase, we will add this check in the next step.
A more mature repository may have a strictproject
percentage, while a project new to code coverage may only expect new code to be well-tested (patch
coverage). We will be setting some of these values in this section, but you can read more about status checkshere.
If you go to the project on Codecov, you will notice that the dashboard is blank. This is because no coverage information has been uploaded onto the main branch. We can fix this by merging the pull request!
Merge the MR on GitLab and wait for the CI/CD to complete.
When opening merge requests, be sure to select your own repository as the target branch, orset your project's default target branch
Updated 9 months ago