Skip to content

Upload coverage report #93

Upload coverage report

Upload coverage report #93

name: Upload coverage report
on:
workflow_run:
workflows: ["Test"]
types:
- completed
jobs:
upload-coverage:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: 'Download artifact'
uses: actions/[email protected]
with:
script: |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "coverage"
})[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/coverage.zip', Buffer.from(download.data));
- run: unzip coverage.zip
- name: Find associated PR
id: pr
uses: actions/[email protected]
with:
script: |
const response = await github.rest.search.issuesAndPullRequests({
q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}',
per_page: 1,
})
const items = response.data.items
if (items.length < 1) {
console.error('No PRs found')
return
}
const pullRequestNumber = items[0].number
console.info("Pull request number is", pullRequestNumber)
return pullRequestNumber
- uses: codecov/codecov-action@v4
name: Upload coverage report
with:
files: ./coverage.xml
fail_ci_if_error: true
override_pr: ${{ steps.pr.outputs.result }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}