@@ -22,14 +22,15 @@ concurrency:
2222
2323permissions :
2424 contents : read
25+ pull-requests : write
2526
2627# hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
2728env :
2829 SEGMENT_DOWNLOAD_TIMEOUT_MINS : 5
2930
3031jobs :
3132 test :
32- name : python ${{ matrix.python-version }}, ${{ matrix.test-path }}, ignore ${{ matrix.ignore-path }}
33+ name : python ${{ matrix.python-version }}, ${{ matrix.name }}
3334 runs-on : ubuntu-latest
3435 timeout-minutes : 90
3536
4142 include :
4243 - test-path : " tests/unitary"
4344 ignore-path : " tests/unitary/with_extras/model"
45+ name : " unitary"
46+ - test-path : " tests/unitary/with_extras/model"
47+ name : " model"
48+ - python-version : " 3.8"
49+ cov-reports : --cov=ads --cov-report=xml --cov-report=html
4450
4551 steps :
4652 - uses : actions/checkout@v3
@@ -82,10 +88,11 @@ jobs:
8288 shell : bash
8389 run : |
8490 set -x # print commands that are executed
91+
8592 sudo apt-get install libkrb5-dev graphviz
8693 $CONDA/bin/conda init
8794 source /home/runner/.bashrc
88- pip install setuptools
95+
8996 pip install -r dev-requirements.txt
9097
9198 - name : " Run unitary tests folder with maximum ADS dependencies"
@@ -95,16 +102,123 @@ jobs:
95102 NB_SESSION_COMPARTMENT_OCID : ocid1.compartment.oc1.<unique_ocid>
96103 CONDA_PREFIX : /usr/share/miniconda
97104 run : |
105+ set -x # print commands that are executed
106+
107+ # Setup project and tests folder for cov reports to not be overwritten by another parallel step
108+ if [[ ! -z "${{ matrix.cov-reports }}" ]]; then
109+ mkdir -p cov-${{ matrix.name }}
110+ cd cov-${{ matrix.name }}
111+ ln -s ../tests tests
112+ ln -s ../ads ads
113+ ln -s ../.coveragerc .coveragerc
114+ fi
115+
116+ # Run tests
98117 python -m pytest -v -p no:warnings --durations=5 \
118+ -n auto --dist loadfile ${{ matrix.cov-reports }} \
99119 ${{ matrix.test-path }} \
100- --ignore "${{ matrix.ignore-path }}" \
101- --cov --cov-append --cov-report=html
120+ --ignore "${{ matrix.ignore-path }}"
121+
122+ - name : " Save coverage files"
123+ uses : actions/upload-artifact@v3
124+ if : ${{ matrix.cov-reports }}
125+ with :
126+ name : cov-reports-${{ matrix.name }}
127+ path : |
128+ cov-${{ matrix.name }}/htmlcov/
129+ cov-${{ matrix.name }}/.coverage
130+ cov-${{ matrix.name }}/coverage.xml
131+
132+ coverage-report :
133+ name : " Coverage report"
134+ runs-on : ubuntu-latest
135+ continue-on-error : true
136+ needs : test
137+ if : ${{ success() }} && ${{ github.event.issue.pull_request }}
138+ env :
139+ COMPARE_BRANCH : develop
140+
141+ steps :
142+ - name : " Checkout current branch"
143+ uses : actions/checkout@v3
144+ with :
145+ fetch-depth : 0
146+ - name : " Download coverage files"
147+ uses : actions/download-artifact@v3
148+ - name : " Calculate overall coverage"
149+ run : |
150+ set -x # print commands that are executed
151+
152+ # Prepare default cov body text
153+ COV_BODY_INTRO="📌 Overall coverage:\n\n"
154+ echo COV_BODY="$COV_BODY_INTRO No success to gather report. 😿" >> $GITHUB_ENV
155+
156+ # Combine coverage files
157+ pip install coverage
158+ coverage combine cov-reports-unitary/.coverage cov-reports-model/.coverage
159+
160+ # Make html report
161+ coverage html
162+
163+ # Calculate overall coverage and update body message
164+ COV=$(grep -E 'pc_cov' htmlcov/index.html | cut -d'>' -f 2 | cut -d'%' -f 1)
165+ if [[ ! -z $COV ]]; then
166+ if [[ $COV < 50 ]]; then COLOR=red; elif [[ $COV < 80 ]]; then COLOR=yellow; else COLOR=green; fi
167+ echo COV_BODY="$COV_BODY_INTRO " >> $GITHUB_ENV
168+ fi
169+
170+ - name : " Calculate coverage diff"
171+ if : always()
172+ run : |
173+ set -x # print commands that are executed
174+
175+ # Prepare default diff body text
176+ DIFF_BODY_INTRO="📌 Cov diff with **${{ env.COMPARE_BRANCH }}**:\n\n"
177+ echo DIFF_BODY="$BODY_INTRO No success to gather report. 😿" >> $GITHUB_ENV
178+
179+ # Prepare file paths to coverage xml files
180+ # Filenames taken from job.test last step with name - "Save coverage files"
181+ FILE1="cov-reports-unitary/coverage.xml"; [[ ! -f $FILE1 ]] && FILE1=""
182+ FILE2="cov-reports-model/coverage.xml"; [[ ! -f $FILE2 ]] && FILE2=""
183+ echo "FILE1=$FILE1" >> $GITHUB_ENV
184+ echo "FILE2=$FILE2" >> $GITHUB_ENV
185+
186+ # Calculate coverage diff and update body message
187+ pip install diff_cover
188+ diff-cover $FILE1 $FILE2 --compare-branch=origin/${{ env.COMPARE_BRANCH }}
189+ DIFF=$(diff-cover $FILE1 $FILE2 \
190+ --compare-branch=origin/${{ env.COMPARE_BRANCH }} | grep Coverage: | cut -d' ' -f 2 | cut -d'%' -f 1)
191+ if [[ -z $DIFF ]]; then
192+ DIFF_INFO=$(diff-cover $FILE1 $FILE2 \
193+ --compare-branch=origin/${{ env.COMPARE_BRANCH }} | grep "No lines");
194+ echo DIFF_BODY="$DIFF_BODY_INTRO $DIFF_INFO">> $GITHUB_ENV
195+ else
196+ if [[ $DIFF < 50 ]]; then COLOR=red; elif [[ $DIFF < 80 ]]; then COLOR=yellow; else COLOR=green; fi
197+ echo DIFF_BODY="$DIFF_BODY_INTRO " >> $GITHUB_ENV
198+ fi
102199
103- # Uploading test artifacts
104- # https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts#uploading-build-and-test-artifacts
105- - name : " Save html coverage report"
200+ - name : " Add comment with cov diff to PR"
201+ uses : actions/github-script@v6
202+ if : always()
203+ with :
204+ github-token : ${{ github.token }}
205+ script : |
206+ github.rest.issues.createComment({
207+ issue_number: context.issue.number,
208+ owner: context.repo.owner,
209+ repo: context.repo.repo,
210+ body: '${{ env.DIFF_BODY }}\n\n${{ env.COV_BODY }}'
211+ })
212+ - name : " Generate html difference report"
213+ run : |
214+ diff-cover ${{ env.FILE1 }} ${{ env.FILE2 }} \
215+ --compare-branch=origin/${{ env.COMPARE_BRANCH }} \
216+ --html-report=cov-diff.html
217+ - name : " Save coverage difference report"
106218 uses : actions/upload-artifact@v3
107219 with :
108- name : code-coverage-report
109- path : htmlcov/
220+ name : cov-html-reports
221+ path : |
222+ cov-diff.html
223+ htmlcov/
110224 retention-days : 10
0 commit comments