Codecov: GitHub Actions

Using Codecov with GitHub Actions, including adding CODECOV_TOKEN secret

To use CodeCov.io with GitHub Actions, you need two things:

Obtaining the Upload Token

To obtain the upload token, first be sure that you are logged in at https://codecov.io with you GitHub account.

Then, navigate to https://codecov.io/gh/ORG-NAME-HERE/REPO-NAME-HERE, for example

You should see a screen with an upload token.

On that page, there should be a so-called upload-token value, a series of letters and numbers like a very long password. You’ll need to copy/paste that value, so keep that window open.

If you can’t find the upload token there, try this URL instead:

If neither of those, works, try the “troubleshooting page” linked to below.

Setting the Secret

Adding codecov.io to your GitHub Actions workflow

For Java repos, here is an example of a maven.yml that uploads codecov information from a Jacoco report to codecov.

name: Java CI

on:
  pull_request:
  push:
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11.0.x
      - name: Build with Maven
        run: mvn test jacoco:report
      - name: Upload to Codecov
        env:
          CODECOV_TOKEN: $
        run: bash <(curl -s https://codecov.io/bash)
      - name: Pitest
        run: mvn test org.pitest:pitest-maven:mutationCoverage
      - name: Upload Pitest to Artifacts
        uses: actions/upload-artifact@v2
        with:
          name: pitest-mutation-testing
          path: target/pit-reports/**/*  

The following lines are the one that generate a jacoco report (which is something we can upload to codecov). Different lines would be needed instead (or in addition) to also generate reports from JavaScript code (e.g. jest).

      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11.0.x
      - name: Build with Maven
        run: mvn test jacoco:report

These are the lines that upload the report to codecov. The env part is what gets the secret from GitHub and then loads it into an environment variable used by the script.
The line run: bash <(curl -s https://codecov.io/bash) automatically gets an appropriate script from the url https://codecov.io/bash and then executes it.

     - name: Upload to Codecov
        env:
          CODECOV_TOKEN: $
        run: bash <(curl -s https://codecov.io/bash)

Related topics:

  • Codecov: —Integrated tools to group, merge, archive, and compare coverage reports (commerical, free for open-source)
  • Codecov: GitHub Actions—Using Codecov with GitHub Actions, including adding CODECOV_TOKEN secret
  • Codecov: Troubleshooting—Solutions to problems that commonly arise with Codecov