Skip to content

Commit b0a33a5

Browse files
authored
Merge pull request #11 from oracle/ODSC-42787/add_workflow_for_tests
Add coverage report message to PRs
2 parents 74ec25d + f85b006 commit b0a33a5

File tree

4 files changed

+77
-8
lines changed

4 files changed

+77
-8
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: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ concurrency:
1919

2020
permissions:
2121
contents: read
22+
pull-requests: write
2223

2324
# hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
2425
env:
@@ -34,6 +35,9 @@ jobs:
3435
fail-fast: false
3536
matrix:
3637
python-version: ["3.8", "3.9", "3.10"]
38+
include:
39+
- python-version: "3.9"
40+
cov-reports: --cov=oci_mlflow --cov-report=xml --cov-report=html
3741

3842
steps:
3943
- uses: actions/checkout@v3
@@ -57,27 +61,65 @@ jobs:
5761
run: |
5862
set -x # print commands that are executed
5963
mkdir -p "$HOME_RUNNER_DIR"/.oci
60-
openssl genrsa -out $HOME_RUNNER_DIR/.oci/oci_ads_user.pem 2048
64+
openssl genrsa -out $HOME_RUNNER_DIR/.oci/oci_mlflow_user.pem 2048
6165
cat <<EOT >> "$HOME_RUNNER_DIR/.oci/config"
6266
[DEFAULT]
6367
user=ocid1.user.oc1..xxx
6468
fingerprint=00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
6569
tenancy=ocid1.tenancy.oc1..xxx
6670
region=test_region
67-
key_file=$HOME_RUNNER_DIR/.oci/oci_ads_user.pem
71+
key_file=$HOME_RUNNER_DIR/.oci/oci_mlflow_user.pem
6872
EOT
6973
ls -lha "$HOME_RUNNER_DIR"/.oci
7074
echo "Test config file:"
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: "Calculate coverage"
88+
if: ${{ success() }} && ${{ github.event.issue.pull_request }}
89+
run: |
90+
set -x # print commands that are executed
91+
92+
# Prepare default cov body text
93+
COV_BODY_INTRO="📌 Overall coverage:\n\n"
94+
echo COV_BODY="$COV_BODY_INTRO No success to gather report. 😿" >> $GITHUB_ENV
95+
96+
# Calculate overall coverage and update body message
97+
COV=$(grep -E 'pc_cov' htmlcov/index.html | cut -d'>' -f 2 | cut -d'%' -f 1)
98+
if [[ ! -z $COV ]]; then
99+
ROUNDED_COV=$(echo $COV | cut -d'.' -f 1)
100+
if [[ $ROUNDED_COV -lt 50 ]]; then COLOR=red; elif [[ $ROUNDED_COV -lt 80 ]]; then COLOR=yellow; else COLOR=green; fi
101+
echo COV_BODY="$COV_BODY_INTRO ![Coverage-$COV%](https://img.shields.io/badge/coverage-$COV%25-$COLOR)" >> $GITHUB_ENV
102+
fi
103+
104+
- name: "Add comment with coverage info to PR"
105+
uses: actions/github-script@v6
106+
if: ${{ success() }} && ${{ github.event.issue.pull_request }}
107+
with:
108+
github-token: ${{ github.token }}
109+
script: |
110+
github.rest.issues.createComment({
111+
issue_number: context.issue.number,
112+
owner: context.repo.owner,
113+
repo: context.repo.repo,
114+
body: '${{ env.COV_BODY }}'
115+
})
116+
117+
- name: "Save coverage files"
118+
uses: actions/upload-artifact@v3
119+
if: ${{ matrix.cov-reports }}
120+
with:
121+
name: cov-reports
122+
path: |
123+
htmlcov/
124+
.coverage
125+
coverage.xml

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 =

test-requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
-e .
2-
coverage
32
faker
43
mock
54
pip
65
pytest
76
pytest-codecov
8-
pytest-xdist

0 commit comments

Comments
 (0)