Repository navigation
Expand file tree
/
Copy pathpython-test-coverage-report.yml
More file actions
85 lines (82 loc) · 3.18 KB
/
Copy pathpython-test-coverage-report.yml
File metadata and controls
85 lines (82 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Python Test Coverage Report
on:
workflow_run:
workflows: ["Python Test Coverage"]
types:
- completed
permissions:
contents: read
actions: read
pull-requests: write
jobs:
python-test-coverage-report:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
continue-on-error: false
defaults:
run:
working-directory: python
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Read and set PR number
id: pr
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const run = context.payload.workflow_run;
if (run.event !== 'pull_request') {
core.warning('Coverage reporting requires a pull request workflow run.');
return;
}
const matchesRun = (pr) =>
pr.state === 'open' &&
pr.base.repo.id === context.payload.repository.id &&
pr.head.sha === run.head_sha &&
pr.head.ref === run.head_branch &&
pr.head.repo?.id != null &&
pr.head.repo.id === run.head_repository?.id;
let candidates = run.pull_requests ?? [];
if (candidates.length === 0) {
candidates = await github.paginate(
github.rest.repos.listPullRequestsAssociatedWithCommit,
{ ...context.repo, commit_sha: run.head_sha, per_page: 100 },
);
candidates = candidates.filter(matchesRun);
}
if (candidates.length !== 1) {
core.warning('Coverage reporting requires exactly one matching pull request.');
return;
}
const { data: pr } = await github.rest.pulls.get({
...context.repo,
pull_number: candidates[0].number,
});
if (!matchesRun(pr)) {
core.warning('The pull request no longer matches the coverage run.');
return;
}
core.setOutput('pr_number', pr.number);
- name: Download coverage report
if: steps.pr.outputs.pr_number != ''
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: python-test-coverage
github-token: ${{ github.token }}
run-id: ${{ github.event.workflow_run.id }}
path: ./python/coverage-report
- name: Pytest coverage comment
if: steps.pr.outputs.pr_number != ''
id: coverageComment
uses: MishaKav/pytest-coverage-comment@1bdbba85fb74a2fdc1ec66383acec1091610f82b # v1.1.57
with:
github-token: ${{ github.token }}
issue-number: ${{ steps.pr.outputs.pr_number }}
pytest-xml-coverage-path: python/coverage-report/python-coverage.xml
title: "Python Test Coverage Report"
badge-title: "Python Test Coverage"
junitxml-title: "Python Unit Test Overview"
junitxml-path: python/coverage-report/pytest.xml
default-branch: "main"
report-only-changed-files: true