Skip to content

Comment coverage

Comment coverage #323

name: Comment coverage
on:
workflow_run:
workflows: [Tests]
types:
- completed
permissions:
pull-requests: write
jobs:
comment:
name: Comment coverage
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion != 'cancelled'
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: coverage
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Find associated pull request
id: pr
uses: actions/github-script@v7
if: ${{ github.event.workflow_run.pull_requests[0].number == null }}
with:
script: |
const response = await github.rest.pulls.list({
owner: "${{ github.repository_owner }}",
repo: "${{ github.event.workflow_run.repository.name }}",
state: "open",
head: "${{ github.event.workflow_run.head_repository.owner.login }}:${{ github.event.workflow_run.head_branch }}",
});
return response.data[0]?.number ?? "";
retries: 3
- name: Comment coverage
uses: MishaKav/pytest-coverage-comment@a1fe18e2b00c64a765568e2edb9f1706eb8fc88b
with:
pytest-xml-coverage-path: coverage.xml
junitxml-path: coverage-junit.xml
issue-number: ${{ github.event.workflow_run.pull_requests[0].number || steps.pr.outputs.result }}
report-only-changed-files: ${{ !github.event.workflow_run.head_repository.fork }} # This does not currently work for forks