These docs are for v4.6. Click to read the latest docs for v2023.

GH-2 - Getting a Codecov account and uploading coverage

Create a new branch step2

git checkout main
git pull
git checkout -b 'step2'

Before we continue, let’s create an account and set up our repository on Codecov.

Create a Codecov account

Create an account on Codecov by clicking on our signup page and following the prompts.

🚧

GitHub Third-party application access

If you are signing up via GitHub, you may need to request access from an admin to authorize Codecov as a third-party application.

An admin can approve this request in the "Third-party access" tab in the organization's settings page:
https://github.com/organizations/[YOUR_ORG_NAME]/settings/oauth_application_policy.

For more information see GitHub OAuth Admin Authorization or follow our video guide.

Install the Codecov GitHub app integration for the demo repository.

Now that we have set up our Codecov account, let’s upload coverage reports.

Create CI pipeline

Create a configuration file for your CI. The CI workflows below will checkout the code, install requirements, run tests, and upload the coverage reports to Codecov.

GitHub Actions

name: API workflow

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    name: Test python API
    defaults:
      run:
        working-directory: ./api
    steps:
    - uses: actions/checkout@v1
    - uses: actions/setup-python@v2
      with:
        python-version: '3.10'
    - name: Install requirements
      run: pip install -r requirements.txt
    - name: Run tests and collect coverage
      run: pytest --cov=./ --cov-report=xml
    - name: Upload coverage reports to Codecov with GitHub Action
      uses: codecov/codecov-action@v3

The upload step uses the Codecov GitHub action. It is built on top of our uploader. It is recommended to use the action as it automatically runs integrity checks on the binary.

CircleCI

version: 2.1

orbs:
  codecov: codecov/[email protected]

jobs:
  test-api:
    docker:
      - image: cimg/python:3.10.2
    steps:
      - checkout
      - run:
          name: Install requirements
          command: pip install -r api/requirements.txt
      - run:
          name: Run tests and collect coverage
          command: pytest --cov api/
      - codecov/upload

workflows:
  version: 2.1
  build-test:
    jobs:
      - test-api

The upload step uses the Codecov CircleCI Orb. It is built on top of our uploader. It is recommended to use the Orb as it automatically runs integrity checks on the binary.

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 GitHub and open a pull request (PR).

When opening pull requests, be sure to select your own repository as the base branch.

914

You will see status checks on the PR 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.

912

codecov/patch and codecov/project status checks

One 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 project check is used to maintain a coverage percentage across an entire codebase
  • The patch check is used for code changed in a PR.

A more mature repository may have strict a project 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 checks here.

691

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 default branch. We can fix this by merging the pull request.

Merge the pull request on GitHub and wait for the CI/CD to complete.
When opening pull requests, be sure to select your own repository as the base branch.