Skip to content

Upload to Codecov

Upload to Codecov #25

name: Upload to Codecov
on:
workflow_run:
workflows:
- Checks
types:
- completed
jobs:
show-info:
runs-on: ubuntu-latest
steps:
- name: Show event payload
uses: actions/github-script@v7
with:
script: |
txt = JSON.stringify(context.payload.workflow_run, null, 4);
core.summary.addCodeBlock(txt, 'json');
core.summary.write()
upload:
name: Upload coverage reports
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_sha }}
- name: Display codecov.yml file
run: cat codecov.yml
- name: Download artifacts from triggering workflow
run: |
ls -lahR
gh run download ${{ github.event.workflow_run.id }} \
--repo ${{ github.repository }} \
--pattern 'coverage-report-*'
ls -lahR
- name: Collect information from triggered event payload
id: event-info
run: |
gh run download ${{ github.event.workflow_run.id }} \
--repo ${{ github.repository }} \
--name event-payload
ls -lah
# if there's no .number key in the JSON (i.e. when the triggering event is not `pull_request` or `pull_request_target`),
# the jq command will not error out and pr_number will be set to ''
# this is OK for the purposes of codecov-action@v4 inputs (set PR number if event is PR; otherwise don't),
# so we don't need to add a conditional to run this step only for PR events
pr_number="$(jq < event.json '.number')"
echo "pr-number=$pr_number" >> "$GITHUB_OUTPUT"
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
name: ${{ github.event.workflow_run.id }}
job_code: ${{ github.event.workflow_run.name }}
override_build: ${{ github.event.workflow_run.id }}
override_build_url: ${{ github.event.workflow_run.html_url }}
override_commit: ${{ github.event.workflow_run.head_sha }}
override_branch: ${{ github.event.workflow_run.head_branch }}
override_pr: ${{ steps.event-info.outputs.pr-number }}