Codecov: Make event payload upload more generic #36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Upload to Codecov | |
run-name: 'Codecov: ${{ github.event.workflow_run.display_title }}' | |
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: | |
if: github.event.workflow_run.conclusion == 'success' | |
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 | |
# without // empty, jq will return the empty string when called interactively, | |
# but the string "null" when called e.g. through $() | |
# we need the string to be empty for the logic to work correctly in the following step(s) | |
pr_number="$(jq < event.json '.number // empty')" | |
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 }} |