Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update action to do local processing #58

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Workflow for Codecov Action
on: [pull_request]
jobs:
run:
permissions: read-all
permissions: write-all
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -19,29 +19,18 @@ jobs:
uses: ./
with:
files: ./demo/calculator/junit.xml
flags: ${{ matrix.os }}
verbose: true
token: ${{ secrets.CODECOV_ORG_TOKEN }}
- name: Upload test results to Codecov (demo)
uses: ./
with:
files: ./demo/coverage-test/junit.xml
flags: ${{ matrix.os }}
verbose: true
token: ${{ secrets.CODECOV_ORG_TOKEN }}
- name: Upload test results to Codecov (calculator) (staging)
uses: ./
with:
files: ./demo/calculator/junit.xml
flags: ${{ matrix.os }}
verbose: true
url: ${{ secrets.CODECOV_STAGING_URL }}
token: ${{ secrets.CODECOV_ORG_TOKEN_STAGING }}
- name: Upload test results to Codecov (demo) (staging)
uses: ./
with:
url: ${{ secrets.CODECOV_STAGING_URL }}
token: ${{ secrets.CODECOV_ORG_TOKEN_STAGING }}
files: ./demo/coverage-test/junit.xml
flags: ${{ matrix.os }}
verbose: true
148 changes: 70 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,105 +17,97 @@ steps:
with:
fail_ci_if_error: true # optional (default = false)
files: ./junit1.xml,./junit2.xml # optional
flags: py3.11 # optional
name: codecov-umbrella # optional
token: ${{ secrets.CODECOV_TOKEN }} # required
token: ${{ secrets.CODECOV_GITHUB_TOKEN }} # optional (default = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by default I think we call this CODECOV_TOKEN everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case it's not actually a "codecov token" anymore, it needs to be a github personal access token, "codecov token" usually means then token you can get from the codecov website

verbose: true # optional (default = false)
```

The Codecov token can also be passed in via environment variables:
### IMPORTANT NOTES
It's important that this action only runs once during your CI, as every run of the action will overwrite the comment left by the previous run.

If you are generating test result reports in many jobs/steps then the upload-artifact will be essential. Using this action you can temporarily store reports,
and download them for later use. In our case, we can generate as many reports as we'd like and store them, and at the end of CI we can download them all and
use the test results action. Here's an example of what this would look like for a CI workflow that uses multiple jobs and the matrix strategy to generate multiple
test reports. It's crucial that both the name of the artifact and name of the files are unique.

You can find the repository for the upload-artifact [here](https://github.com/actions/upload-artifact).

It is also important that the test-results-action has access to a github token with permissions to write to pull requests. This can easily be done by giving the
default GITHUB_TOKEN generated for the action permission to write to pull requests. This can be done by adding the following.

```yaml
steps:
- uses: actions/checkout@master
- uses: codecov/test-results-action@v0
with:
fail_ci_if_error: true # optional (default = false)
files: ./junit1.xml,./junit2.xml # optional
flags: python3.10 # optional
name: codecov-umbrella # optional
verbose: true # optional (default = false)
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
permissions:
pull-requests: write
```

The docs for permissions for github actions are [here](https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs).

```yaml
name: Example workflow
on: [pull_request]

jobs:
frontend:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Run tests
run: npx vitest --reporter=junit

- name: Store results
uses: actions/upload-artifact@v4
with:
name: codecov-frontend-junit-${{ matrix.os }}
path: frontend-${{ matrix.os }}-junit.xml
backend:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Run tests
run: pytest --junit-xml=backend-${{ matrix.os }}-junit.xml
- name: Store results
uses: actions/upload-artifact@v4
with:
name: codecov-backend-junit-${{ matrix.os }}
path: backend-${{ matrix.os }}-junit.xml

results:
permissions:
pull-requests: write
runs-on: ubuntu-latest
needs: [frontend, backend]
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: codecov-*-junit-*
merge-multiple: true
path: artifact
- name: Process test results
uses: codecov/test-results-action@v0
with:
directory: artifact
```
>**Note**: This assumes that you've set your Codecov token inside *Settings > Secrets* as `CODECOV_TOKEN`. If not, you can [get an upload token](https://docs.codecov.io/docs/frequently-asked-questions#section-where-is-the-repository-upload-token-found-) for your specific repo on [codecov.io](https://www.codecov.io). Keep in mind that secrets are *not* available to forks of repositories.

## Arguments

Codecov's Action supports inputs from the user. These inputs, along with their descriptions and usage contexts, are listed in the table below:

| Input | Description | Required |
| :--- | :--- | :---: |
| `token` | Repository Codecov token. Used to authorize report uploads | *Required
| `codecov_yml_path` | Specify the path to the Codecov YML | Optional
| `commit_parent` | Override to specify the parent commit SHA | Optional
| `token` | Github token to use to authenticate with the Github API to post/edit comments | Optional
| `directory` | Directory to search for test result reports. | Optional
| `disable_search` | Disable search for test result files. This is helpful when specifying what files you want to upload with the --file option. | Optional
| `dry_run` | Don't upload files to Codecov | Optional
| `env_vars` | Environment variables to tag the upload with (e.g. PYTHON \| OS,PYTHON) | Optional
| `exclude` | Folders to exclude from search | Optional
| `fail_ci_if_error` | Specify whether or not CI build should fail if Codecov runs into an error during upload | Optional
| `file` | Path to test result file to upload | Optional
| `files` | Comma-separated list of files to upload | Optional
| `flags` | Flag upload to group test results (e.g. py3.10 | py3.11 | py3.12) | Optional
| `handle_no_reports_found` | Raise no exceptions when no test result reports found | Optional
| `name` | User defined upload name. Visible in Codecov UI | Optional
| `os` | Override the assumed OS. Options are linux \| macos \| windows \| . | Optional
| `override_branch` | Specify the branch name | Optional
| `override_build` | Specify the build number | Optional
| `override_build_url` | The URL of the build where this is running | Optional
| `override_commit` | Specify the commit SHA | Optional
| `override_pr` | Specify the pull request number | Optional
| `report_code` | The code of the report. If unsure, do not include | Optional
| `root_dir` | Used when not in git/hg project to identify project root directory | Optional
| `slug` | Specify the slug manually (Enterprise use) | Optional
| `url` | Specify the base url to upload (Enterprise use) | Optional
| `verbose` | Specify whether the Codecov output should be verbose | Optional
| `version` | Specify which version of the Codecov CLI should be used. Defaults to `latest` | Optional
| `working-directory` | Directory in which to execute codecov.sh | Optional

### Example `workflow.yml` with Codecov Action

```yaml
name: Example workflow for Codecov
on: [push]
jobs:
run:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
env:
OS: ${{ matrix.os }}
PYTHON: '3.10'
steps:
- uses: actions/checkout@master
- name: Setup Python
uses: actions/setup-python@master
with:
python-version: 3.10
- name: Generate coverage and test result report
run: |
pip install pytest
pip install pytest-cov
pytest --cov=./ --cov-report=xml --junitxml=./junit.xml
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
files: ./junit.xml,!./cache
flags: python3.10
name: codecov-umbrella-test-results
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
directory: ./coverage/reports/
env_vars: OS,PYTHON
fail_ci_if_error: true
files: ./coverage1.xml,./coverage2.xml,!./cache
flags: unittests
name: codecov-umbrella
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
```
| `working-directory` | Directory in which to execute codecov.sh | Optional
52 changes: 7 additions & 45 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,36 @@ description: 'GitHub Action that uploads test result reports for your repository
author: 'Codecov'
inputs:
token:
description: 'Repository Codecov token. Used to authorize report uploads'
required: false
codecov_yml_path:
description: 'Specify the path to the Codecov YML'
required: false
commit_parent:
description: 'Override to specify the parent commit SHA'
description: 'Token used to access Github API. Takes value of github.token by default.'
required: false
default: ${{ github.token }}
directory:
description: 'Directory to search for test result reports.'
required: false
disable_search:
description: 'Disable search for test result files. This is helpful when specifying what files you want to upload with the --file option.'
required: false
dry_run:
description: "Don't upload files to Codecov"
required: false
env_vars:
description: 'Environment variables to tag the upload with (e.g. PYTHON | OS,PYTHON)'
required: false
exclude:
description: 'Folders to exclude from search'
required: false
fail_ci_if_error:
description: 'Specify whether or not CI build should fail if Codecov runs into an error during upload'
description: 'Specify whether or not CI build should fail if Codecov runs into an error during processing'
required: false
file:
description: 'Path to test result file to upload'
required: false
files:
description: 'Comma-separated list of files to upload'
required: false
flags:
description: 'Flag upload to group test results (e.g. py3.10 | py3.11 | py3.12)'
required: false
handle_no_reports_found:
description: 'Raise no exceptions when no test result reports found'
required: false
name:
description: 'User defined upload name. Visible in Codecov UI'
required: false
os:
description: 'Override the assumed OS. Options are linux | macos | windows.'
required: false
override_branch:
description: 'Specify the branch name'
required: false
override_build:
description: 'Specify the build number'
required: false
override_build_url:
description: 'The URL of the build where this is running'
required: false
override_commit:
description: 'Specify the commit SHA'
required: false
override_pr:
description: 'Specify the pull request number'
required: false
report_code:
description: 'The code of the report. If unsure, do not include'
required: false
root_dir:
description: 'Used when not in git/hg project to identify project root directory'
required: false
slug:
description: 'Specify the slug manually (Enterprise use)'
required: false
url:
description: 'Specify the base url to upload (Enterprise use)'
required: false
verbose:
description: 'Specify whether the Codecov output should be verbose'
required: false
Expand All @@ -84,10 +43,13 @@ inputs:
description: 'Directory in which to execute codecov.sh'
required: false




branding:
color: 'red'
icon: 'umbrella'

runs:
using: 'node20'
main: 'dist/index.js'
main: 'dist/index.js'
Loading
Loading