Skip to content

Commit b223db1

Browse files
committed
ODSC-42785. Add coverage report message to PRs
- added .coveragerc to setup coverage reporting - added addopts to pytest.ini - added coverage report steps into run-tests.yml
1 parent b392157 commit b223db1

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

.coveragerc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[run]
2+
omit =
3+
**/*.jinja2
4+
**/__init__.py
5+
container-image/*
6+
docs/*
7+
tests/*
8+
9+
[report]
10+
exclude_lines =
11+
pragma: no cover
12+
def __repr__
13+
if __name__ == .__main__.:
14+
@(abc\.)?abstractmethod
15+
raise AssertionError
16+
raise NotImplementedError
17+
omit =
18+
**/*.jinja2
19+
**/__init__.py
20+
container-image/*
21+
docs/*
22+
tests/*
23+
show_missing = true
24+
skip_empty = true
25+
precision = 2
26+
27+
[html]
28+
directory = htmlcov

.github/workflows/run-tests.yml

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ jobs:
3434
fail-fast: false
3535
matrix:
3636
python-version: ["3.8", "3.9", "3.10"]
37+
include:
38+
- python-version: "3.9"
39+
cov-reports: --cov=ads --cov-report=xml --cov-report=html
40+
3741

3842
steps:
3943
- uses: actions/checkout@v3
@@ -71,13 +75,50 @@ jobs:
7175
cat $HOME_RUNNER_DIR/.oci/config
7276
7377
- name: "Run tests"
74-
timeout-minutes: 15
78+
timeout-minutes: 5
7579
shell: bash
76-
env:
77-
NoDependency: True
7880
run: |
7981
set -x # print commands that are executed
8082
$CONDA/bin/conda init
8183
source /home/runner/.bashrc
8284
pip install -r test-requirements.txt
83-
python -m pytest -v -p no:warnings --durations=5 tests
85+
python -m pytest ${{ matrix.cov-reports }} tests
86+
87+
- name: "Save coverage files"
88+
uses: actions/upload-artifact@v3
89+
if: ${{ matrix.cov-reports }}
90+
with:
91+
name: cov-reports-${{ matrix.name }}
92+
path: |
93+
htmlcov/
94+
.coverage
95+
coverage.xml
96+
97+
- name: "Add comment with coverage info to PR"
98+
if: ${{ success() }} && ${{ github.event.issue.pull_request }}
99+
run: |
100+
set -x # print commands that are executed
101+
102+
# Prepare default cov body text
103+
COV_BODY_INTRO="📌 Overall coverage:\n\n"
104+
echo COV_BODY="$COV_BODY_INTRO No success to gather report. 😿" >> $GITHUB_ENV
105+
106+
# Calculate overall coverage and update body message
107+
COV=$(grep -E 'pc_cov' htmlcov/index.html | cut -d'>' -f 2 | cut -d'%' -f 1)
108+
if [[ ! -z $COV ]]; then
109+
if [[ $COV -lt 50 ]]; then COLOR=red; elif [[ $COV -lt 80 ]]; then COLOR=yellow; else COLOR=green; fi
110+
echo COV_BODY="$COV_BODY_INTRO ![Coverage-$COV%](https://img.shields.io/badge/coverage-$COV%25-$COLOR)" >> $GITHUB_ENV
111+
fi
112+
113+
- name: "Add comment with cov diff to PR"
114+
uses: actions/github-script@v6
115+
if: ${{ success() }} && ${{ github.event.issue.pull_request }}
116+
with:
117+
github-token: ${{ github.token }}
118+
script: |
119+
github.rest.issues.createComment({
120+
issue_number: context.issue.number,
121+
owner: context.repo.owner,
122+
repo: context.repo.repo,
123+
body: '${{ env.COV_BODY }}'
124+
})

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[pytest]
2+
addopts = -v -p no:warnings --durations=5
23
testpaths = tests
34
pythonpath = . oci_mlflow
45
env =

0 commit comments

Comments
 (0)