Codecov Upload & Compare #1
This file contains hidden or 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: Codecov Upload & Compare | |
| on: | |
| workflow_run: | |
| workflows: | |
| - Coverage Build | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| actions: read | |
| pull-requests: read | |
| jobs: | |
| upload-coverage: | |
| name: Upload Coverage | |
| if: > | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'pull_request' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| pr_number: ${{ steps.pr.outputs.pr_number }} | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v5 # must download source code | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Download coverage artifact | |
| uses: actions/download-artifact@v7 | |
| with: | |
| name: jacoco-coverage | |
| path: coverage | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get PR details | |
| id: pr | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const headSha = context.payload.workflow_run.head_sha; | |
| const headOwner = context.payload.workflow_run.head_repository.owner.login; | |
| const headBranch = context.payload.workflow_run.head_branch; | |
| const { data: pulls } = await github.rest.pulls.list({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'all', | |
| head: `${headOwner}:${headBranch}`, | |
| }); | |
| const pr = pulls.find((p) => p.head.sha === headSha); | |
| if (pr) { | |
| core.setOutput('pr_number', pr.number); | |
| core.setOutput('pr_sha', headSha); | |
| core.setOutput('pr_branch', headBranch); | |
| core.setOutput('base_sha', pr.base.sha); | |
| } else { | |
| core.setFailed(`No pull request found for commit ${headSha}`); | |
| } | |
| - name: Upload to Codecov | |
| if: ${{ steps.pr.outputs.pr_number != '' }} | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| override_commit: ${{ steps.pr.outputs.pr_sha }} | |
| override_branch: ${{ steps.pr.outputs.pr_branch }} | |
| override_pr: ${{ steps.pr.outputs.pr_number }} | |
| fail_ci_if_error: true | |
| verbose: true |