-
Notifications
You must be signed in to change notification settings - Fork 345
63 lines (58 loc) · 1.94 KB
/
unittest.yml
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
name: Python Unittest Coverage
on: [push, pull_request]
jobs:
test:
if: false == contains(github.event.pull_request.title, 'WIP')
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.9']
env:
OS: ${{ matrix.os }}
PYTHON: '3.9'
timeout-minutes: 20
steps:
- uses: actions/checkout@master
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@master
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
pip install -q -e .[full]
- name: Run tests with coverage
run: |
coverage run tests/run.py
- name: Generate coverage report
run: |
coverage report -m > coverage.txt
- name: Update or Post coverage report as PR comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v3
with:
token: ${{secrets.CODE_COV_PAT}}
script: |
const fs = require('fs');
const report = fs.readFileSync('coverage.txt', {encoding:'utf8', flag:'r'});
const commentIdentifier = '<!-- coverage-comment -->';
const commentBody = `${commentIdentifier}\n📊 **Coverage Report**:\n\`\`\`\n${report}\n\`\`\``;
const issue_number = context.issue.number;
const comments = await github.issues.listComments({
...context.repo,
issue_number
});
const coverageComment = comments.data.find(comment => comment.body.includes(commentIdentifier));
if (coverageComment) {
await github.issues.updateComment({
...context.repo,
comment_id: coverageComment.id,
body: commentBody
});
} else {
await github.issues.createComment({
...context.repo,
issue_number,
body: commentBody
});
}