Skip to content

codecov/codecov-ats

Use this GitHub Action with your project

Add this Action to an existing workflow or create a new one.

View on Marketplace
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
November 28, 2023 11:12
app
September 21, 2023 16:30
November 28, 2023 10:50
November 10, 2023 14:29
src
November 28, 2023 10:50
November 28, 2023 11:12
September 14, 2023 15:40
November 8, 2023 10:28
November 10, 2023 15:06
November 10, 2023 15:12
September 22, 2023 17:48
September 20, 2023 16:44

codecov-ats

GitHub Action that uploads returns selected test labels to CI ☂️

This Action is currently in beta. Currently, it has only been tested on linux and macos builds using python and pytest.

If you have feedback or issues with running this action, please don't hesitate to let us know by creating a Github Issue against this repo.

Usage

  1. Update the checkout step in GitHub actions to include fetch-depth: 0
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
  1. Add in CODECOV_TOKEN and CODECOV_STATIC_TOKEN secrets from the Codecov UI to GitHub. You can find the CODECOV_STATIC_TOKEN as the Static analysis token

Set the Static analysis token to CODECOV_STATIC_TOKEN in your repository secrets.

  1. Update your codecov.yml by adding the following
flag_management:
  individual_flags:
    - name: smart-tests
      carryforward: true
      carryforward_mode: "labels"
      statuses:
        - type: "project"
        - type: "patch"

cli:
  plugins:
    pycoverage:
      report_type: "json"
  1. If pytest-cov is not a dependency, add it to your requirements.txt file, or run the following after you install your python dependencies in your GitHub Actions workflow.
- name: Install pytest
  run: pip install pytest-cov
  1. Add the Codecov ATS Action to your CI. This should happen after you install python dependencies, but before you run tests.
- name: Run ATS
  uses: codecov/codecov-ats@v0
  env:
    CODECOV_STATIC_TOKEN: ${{ secrets.CODECOV_STATIC_TOKEN }}
    CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# This is an example, do not copy below.
# - name: Run tests.
#   run: pytest ...
  1. Update your pytest run to include the tests selected from ATS. You will need to add the CODECOV_ATS_TESTS variable like below.
- name: Run tests and collect coverage
  run: pytest --cov app ${{ env.CODECOV_ATS_TESTS }}
  1. If you are not already using the Codecov CLI to upload coverage, you can update the Codecov Action to v4-beta
- name: Upload coverage to Codecov
  uses: codecov/codecov-action@v4-beta
  env:
    CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  with:
    flags: smart-tests
    plugins: pycoverage,compress-pycoverage
  1. Run your CI! On your first run, Codecov will not have any labels data and will have to run all tests. However, once all following commits or pull requests are rebased on top of this commit, you should be able to see the benefits of ATS.