codecov-action
codecov-action copied to clipboard
Codecov is using default branch for coverage and tests reports with workflows on feature branch push event
I have 2 separate workflow files, one for build and the other one is for tests; once the build on commit parent finished successfully the test workflow will be triggered on the commit parent ( in this case it is a feature branch push).
Checking the checkout step I can confirm github runner pulled the correct feature branch. In the Codecov step though, with verbose turned on I can see the branch was develop.
What is the configuration that I need to let Codecov pick up the commit parent (feature branch) here?
@qiuxiaomu can you give more details here? A link to the CI or the output from the Codecov step?
Sure thing @thomasrockhu-codecov; it is however a private project, so the CI link might not be accessible; but here's the verbose log from codecov, and thanks for taking the time to look into this!
Run codecov/codecov-action@v5
Run CC_ACTION_VERSION=$(cat ${GITHUB_ACTION_PATH}/src/version)
==> Running Action version 5.1.2
Run git config --global --add safe.directory /home/runner/work/demo/demo
Run CC_FORK="false"
Run if [ "false" == 'true' ] && [ "$CC_FORK" != 'true' ];
==> Token set from input
Run if [ -z "$CC_BRANCH" ] && [ -z "$CC_TOKEN" ] && [ "$CC_FORK" == 'true' ]
Run if [ -z "$CC_SHA" ];
Run ${GITHUB_ACTION_PATH}/dist/codecov.sh
_____ _
/ ____| | |
| | ___ __| | ___ ___ _____ __
| | / _ \ / _` |/ _ \/ __/ _ \ \ / /
| |___| (_) | (_| | __/ (_| (_) \ V /
\_____\___/ \__,_|\___|\___\___/ \_/
Wrapper-0.0.31
==> Detected linux
-> Downloading https://cli.codecov.io/latest/linux/codecov
==> Finishing downloading linux:latest
Version: v9.1.1
gpg: directory '/home/runner/.gnupg' created
gpg: keybox '/home/runner/.gnupg/pubring.kbx' created
gpg: /home/runner/.gnupg/trustdb.gpg: trustdb created
gpg: key 806BB28AED779869: public key "Codecov Uploader (Codecov Uploader Verification Key) <[email protected]>" imported
gpg: Total number processed: 1
gpg: imported: 1
==> Verifying GPG signature integrity
-> Downloading https://cli.codecov.io/latest/linux/codecov.SHA256SUM
-> Downloading https://cli.codecov.io/latest/linux/codecov.SHA256SUM.sig
gpg: Signature made Sat Dec 7 16:07:53 20[24](https://github.com/qiuxiaomu/demo/actions/runs/12476145973/job/34820542326#step:7:25) UTC
gpg: using RSA key 27034E7FDB850E0BBC2C62FF806BB28AED779869
gpg: Good signature from "Codecov Uploader (Codecov Uploader Verification Key) <[email protected]>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 2703 4E7F DB85 0E0B BC2C 62FF 806B B28A ED77 9869
codecov: OK
==> CLI integrity verified
-> Token of length 36 detected
==> Running upload-coverage
./codecov --verbose upload-coverage -t <redacted> --git-service github --gcov-executable gcov
info - 2024-12-24 02:56:33,008 -- ci service found: github-actions
debug - 2024-12-24 02:56:33,010 -- versioning system found: <class 'codecov_cli.helpers.versioning_systems.GitVersioningSystem'>
debug - 2024-12-24 02:56:33,012 -- versioning system found: <class 'codecov_cli.helpers.versioning_systems.GitVersioningSystem'>
warning - 2024-12-24 02:56:33,014 -- No config file could be found. Ignoring config.
debug - 2024-12-24 02:56:33,014 -- No codecov_yaml found
debug - 2024-12-24 02:56:33,016 -- Starting upload coverage --- {"verbose": true, "auto_load_params_from": null, "codecov_yml_path": null, "enterprise_url": null, "version": "cli-9.1.1", "command": "upload-coverage", "git_service": "github", "gcov_executable": "gcov", "commit_sha": "f[35](https://github.com/qiuxiaomu/demo/actions/runs/12476145973/job/34820542326#step:7:37)20576f3293ffe4826aa0fc4ae07a8659dcfe6", "fail_on_error": false, "slug": "qiuxiaomu/demo", "report_code": "default", "network_root_folder": "/home/runner/work/demo/demo", "files_search_root_folder": "/home/runner/work/demo/demo", "files_search_exclude_folders": [], "files_search_explicitly_listed_files": [], "disable_search": false, "disable_file_fixes": false, "build_code": "12476145973", "build_url": "https://github.com/qiuxiaomu/demo/actions/runs/12476145973", "job_code": "Demo Unit Tests", "name": "12476145973", "branch": "develop", "pull_request_number": null, "env_vars": {}, "flags": [], "plugin_names": ["xcode", "gcov", "pycoverage"], "dry_run": false, "use_legacy_uploader": false, "handle_no_reports_found": false, "report_type": "coverage", "network_filter": null, "network_prefix": null, "gcov_args": null, "gcov_ignore": null, "gcov_include": null, "swift_project": null, "parent_sha": null}
debug - 2024-12-24 02:56:33,017 -- Selected preparation plugins --- {"selected_plugins": ["<class 'codecov_cli.plugins.xcode.XcodePlugin'>", "<class 'codecov_cli.plugins.gcov.GcovPlugin'>", "<class 'codecov_cli.plugins.pycoverage.Pycoverage'>"], "cli_config": {}}
debug - 2024-12-24 02:56:33,017 -- Running preparation plugin: <class 'codecov_cli.plugins.xcode.XcodePlugin'>
debug - 2024-12-24 02:56:33,017 -- Running xcode plugin...
warning - 2024-12-24 02:56:33,017 -- xcrun is not installed or can't be found.
debug - 2024-12-24 02:56:33,017 -- Running preparation plugin: <class 'codecov_cli.plugins.gcov.GcovPlugin'>
debug - 2024-12-24 02:56:33,017 -- Running gcov plugin...
warning - 2024-12-24 02:56:33,032 -- No gcov data found.
debug - 2024-12-24 02:56:33,032 -- Running preparation plugin: <class 'codecov_cli.plugins.pycoverage.Pycoverage'>
warning - 2024-12-24 02:56:33,032 -- coverage.py is not installed or can't be found.
debug - 2024-12-24 02:56:33,032 -- Collecting relevant files
info - 2024-12-24 02:56:33,065 -- Found 1 coverage files to report
info - 2024-12-24 02:56:33,065 -- > /home/runner/work/demo/demo/coverage.xml
debug - 2024-12-24 02:56:33,067 -- Selected uploader to use: <class 'codecov_cli.services.upload.upload_sender.UploadSender'>
debug - 2024-12-24 02:56:33,071 -- Sending upload request to Codecov
info - 2024-12-24 02:56:33,656 -- Your upload is now processing. When finished, results will be available at: https://app.codecov.io/github/qiuxiaomu/demo/commit/f3520576f3293ffe4826aa0fc4ae07a8659dcfe6
debug - 2024-12-24 02:56:33,656 -- Upload request to Codecov complete. --- {"response": {"raw_upload_location": "https://storage.googleapis.com/codecov-production/shelter/github/qiuxiaomu%3A%3A%3A%3Ademo/f3520576f3293ffe4826aa0fc4ae07a8659dcfe6/7c67492f-42a6-4fb1-b9fe-0245e5fe2e6d.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=GOOG1EJWQHUGIBILH4J7Q6ZUSCIFNEOLYSNDS7L3B4N5SIBQ2J4YLYE5CRFCD%2F20241224%2Fus%2Fs3%2Faws4_request&X-Amz-Date=20241224T025633Z&X-Amz-Expires=30&X-Amz-SignedHeaders=host&X-Amz-Signature=d965d4aa3b9a80c91f2419b322960f3d7e0c07fdb0dab791ffd61[46](https://github.com/qiuxiaomu/demo/actions/runs/12476145973/job/34820542326#step:7:49)ffe72b5bb", "url": "https://app.codecov.io/github/qiuxiaomu/demo/commit/f3520576f3293ffe4826aa0fc4ae07a8[65](https://github.com/qiuxiaomu/demo/actions/runs/12476145973/job/34820542326#step:7:69)9dcfe6"}}
debug - 2024-12-24 02:56:33,656 -- Sending upload to storage
info - 2024-12-24 02:56:33,743 -- Process Upload complete
debug - 2024-12-24 02:56:33,743 -- Upload result --- {"result": "RequestResult(error=None, warnings=[], status_code=200, text='')"}
Here's the yml for my test workflow:
name: Demo Unit Tests
on:
workflow_run:
workflows: [Demo Build]
types:
- completed
jobs:
unit-test:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
strategy:
max-parallel: 2
steps:
- name: Check out repo
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Set up ta-lib
run: |
export DEBIAN_FRONTEND=noninteractive
wget https://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar -xzf ta-lib-0.4.0-src.tar.gz
cd ta-lib/
sudo ./configure --prefix=/usr
sudo make
sudo make install
cd -
- name: Set up Poetry
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --no-root
- name: Test with pytest
run: poetry run pytest --cov --cov-report=xml --junitxml=unit_test_report.xml tests -o junit_family=legacy
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
flags: py312
name: demo-py312
here's the build workflow:
name: Demo Build
on:
push:
branches: ["*"]
pull_request:
branches: ["develop"]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Check out repo
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Set up ta-lib
run: |
export DEBIAN_FRONTEND=noninteractive
wget https://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar -xzf ta-lib-0.4.0-src.tar.gz
cd ta-lib/
sudo ./configure --prefix=/usr
sudo make
sudo make install
cd -
- name: Set up Poetry
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --no-root
- name: Build with Poetry
run: |
poetry build
rm -rf dist
- name: Lint with Ruff
uses: astral-sh/ruff-action@v2
with:
args: 'check --select E9 --select F63 --select F7 --select F82'
It seems that Codecov did pick up the changes made on the commit parent as the coverage percentage got updated along with test reports; it's just the branch was still showing develop, the commit parent wasn't even in the list.
[!IMPORTANT] Disclaimer: I am a fellow user on GitHub and not affiliated with this project. My comments are based on my own experiences and understanding.
@qiuxiaomu, Regarding your question:
What is the configuration that I need to let Codecov pick up the commit parent (feature branch) here?
I had a similar issue with a similar setup with separate build, and test jobs where the build job triggers the tests. The critical configuration point was the following on the test workflow:
- name: Checkout repository # yours was called "Check out repo" which is fine
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pinned to v4.2.2 - yours was v4 which should also be fine
with:
persist-credentials: false # for security hardening
fetch-depth: 0 # this is to force fetching the parents and rest of the repo
submodules: true # this is to force fetching the submodules and rest of the repo
repository: reactive-firewall-org/multicast # CHANGE THIS TO YOUR github-user/repo-name, (or omit to allow forks to use the workflow, etc.)
token: ${{ inputs.token }} # probably the "${{ github.token }}" value in your case
ref: # yours used "${{ github.event.workflow_run.head_branch }}" which should also be fine on PRs only
- id: output_branch_name
if: ${{ !cancelled() }}
shell: bash
run: |
printf "branch-name=%s\n" $(git name-rev --name-only HEAD | cut -d~ -f1-1) >> "$GITHUB_OUTPUT"
- id: output_sha
shell: bash
run: printf "sha=%s\n" $(git rev-parse --verify HEAD) >> "$GITHUB_OUTPUT" # or if you don't need detached HEAD support: "$(git log -1 --format=%H)" will list the current sha too
subsequent steps in the same job can now use '${{ steps.output_sha.outputs.sha }}' and '${{ steps.output_branch_name.outputs.branch-name }}' for the actual commit sha and branch-name checked out. Which is needed for codecov/codecov-action in my case like this:
- name: Upload Python ${{ matrix.python-version }} integration coverage to Codecov
id: simplified-example-codecov-upload
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3 - yours used v5 which is fine too
with:
token: ${{ secrets.CODECOV_TOKEN }} # or use OCID instead
job_code: ${{ needs.check_mats.outputs.build_id }}-${{ github.run_number }} # I like to tie the builds to the test coverage uploads, but this is optional
override_commit: ${{ steps.output_sha.outputs.sha }} # THIS IS THE KEY SETTING for linking the upload to the checked-out commit instead of the default commit of the workflow itself)
override_branch: ${{ steps.output_branch_name.outputs.branch-name }} # THIS IS THE KEY SETTING for linking the upload to the checked-out branch instead of the default commit's branch of the workflow itself)
files: ./test-reports/coverage_supplement.xml,./test-reports/coverage_doctests.xml,./test-reports/coverage.xml # etc.
directory: .
name: multicast-github-${{ matrix.os }}-${{ matrix.python-version }}
verbose: true
key points:
- by default
GITHUB_SHAis the workflow's own commit (ALWAYS the default branch's copy when triggered byworkflow_runas mentioned here in github's docs - likewise for the
GITHUB_REF - your use-case probably needs BOTH overridden for codecov :shrug:
If nothing else this should help debug further. However, I imagine you could use a similar pattern like mine to get the parent commit. Perhaps something like:
- id: output_branch_name
if: ${{ !cancelled() }}
shell: bash
run: |
printf "parent-branch-name=%s\n" "$(git merge-base $(git log -1 --format=%H) refs/remotes/origin/stable)" >> "$GITHUB_OUTPUT" # replace stable with your main branch
:bow: Hopefully this is helpful