Skip to content

Commit 7d18988

Browse files
author
Dmytro Rezchykov
committed
add coverage report
1 parent dc71bf6 commit 7d18988

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

.github/workflows/test-command.yml

+13
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,16 @@ jobs:
194194
**/normalization_test_output/**/build/compiled/airbyte_utils/**
195195
**/normalization_test_output/**/build/run/airbyte_utils/**
196196
**/normalization_test_output/**/models/generated/**
197+
198+
- name: Test coverage reports artifacts
199+
if: github.event.inputs.comment-id && success()
200+
uses: actions/upload-artifact@v2
201+
with:
202+
name: test-reports
203+
path: |
204+
**/${{ github.event.inputs.connector }}/htmlcov/**
205+
retention-days: 3
206+
197207
- name: Report Status
198208
if: github.ref == 'refs/heads/master' && always()
199209
run: ./tools/status/report.sh ${{ github.event.inputs.connector }} ${{github.repository}} ${{github.run_id}} ${{steps.test.outcome}}
@@ -208,6 +218,9 @@ jobs:
208218
comment-id: ${{ github.event.inputs.comment-id }}
209219
body: |
210220
> :white_check_mark: ${{github.event.inputs.connector}} https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
221+
```
222+
${{env.COVERAGE_REPORT}}
223+
```
211224
- name: Add Failure Comment
212225
if: github.event.inputs.comment-id && failure()
213226
uses: peter-evans/create-or-update-comment@v1

buildSrc/src/main/groovy/airbyte-python.gradle

+9-8
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@ class AirbytePythonConfiguration {
1313
class Helpers {
1414
static addTestTaskIfTestFilesFound(Project project, String testFilesDirectory, String taskName, taskDependencies) {
1515
"""
16-
This method verifies if there are test files in a directory before adding the pytest task to run tests on that directory. This is needed
16+
This method verifies if there are test files in a directory before adding the pytest task to run tests on that directory. This is needed
1717
because if there are no tests in that dir and we run pytest on it, it exits with exit code 5 which gradle takes to mean that the process
1818
failed, since it's non-zero. This means that if a module doesn't need a unit or integration test, it still needs to add a dummy test file
19-
like:
20-
19+
like:
20+
2121
```
2222
def make_ci_pass_test():
2323
assert True
2424
```
25-
25+
2626
So we use this method to leverage pytest's test discovery rules (https://docs.pytest.org/en/6.2.x/goodpractices.html#conventions-for-python-test-discovery)
27-
to selectively run pytest based on whether there seem to be test files in that directory.
28-
Namely, if the directory contains a file whose name is test_*.py or *_test.py then it's a test.
29-
27+
to selectively run pytest based on whether there seem to be test files in that directory.
28+
Namely, if the directory contains a file whose name is test_*.py or *_test.py then it's a test.
29+
3030
See https://github.com/airbytehq/airbyte/issues/4979 for original context
3131
"""
3232
if (project.file(testFilesDirectory).exists()) {
3333

3434
project.projectDir.toPath().resolve(testFilesDirectory).traverse(type: FileType.FILES, nameFilter: ~/(^test_.*|.*_test)\.py$/) { file ->
3535
project.task(taskName, type: PythonTask, dependsOn: taskDependencies) {
3636
module = "pytest"
37-
command = "-s ${testFilesDirectory}"
37+
command = "-s ${testFilesDirectory} --cov=./ --cov-config=${project.rootProject.file('tools/python/.coveragerc').absolutePath} --cov-report html --cov-report term"
3838
}
3939
// If a file is found, terminate the traversal, thus causing this task to be declared at most once
4040
return FileVisitResult.TERMINATE
@@ -68,6 +68,7 @@ class AirbytePythonPlugin implements Plugin<Project> {
6868
pip 'mypy:0.812'
6969
pip 'isort:5.6.4'
7070
pip 'pytest:6.1.2'
71+
pip 'pytest-cov:2.12.1'
7172
pip 'pip:21.1.3'
7273
}
7374

tools/bin/ci_integration_test.sh

+12-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,19 @@ run | tee build.out
4646
# return status of "run" command, not "tee"
4747
# https://tldp.org/LDP/abs/html/internalvariables.html#PIPESTATUSREF
4848
run_status=${PIPESTATUS[0]}
49+
4950
test $run_status == "0" || {
51+
# Build failed
52+
link=$(cat build.out | grep -A1 "Publishing build scan..." | tail -n1 | tr -d "\n")
5053
# Save gradle scan link to github GRADLE_SCAN_LINK variable for next job.
5154
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
52-
LINK=$(cat build.out | grep -A1 "Publishing build scan..." | tail -n1 | tr -d "\n")
53-
echo "GRADLE_SCAN_LINK=$LINK" >> $GITHUB_ENV
55+
echo "GRADLE_SCAN_LINK=$link" >> $GITHUB_ENV
56+
exit $run_status
5457
}
55-
exit $run_status
58+
59+
# Build successed
60+
coverage_report=`sed -n '/--- coverage: /,/TOTAL /p' build.out`
61+
62+
echo "COVERAGE_REPORT<<EOF" >> $GITHUB_ENV
63+
echo "$coverage_report" >> $GITHUB_ENV
64+
echo "EOF" >> $GITHUB_ENV

tools/python/.coveragerc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[run]
2+
omit =
3+
.venv/*
4+
main.py
5+
setup.py
6+
unit_tests/*
7+
integration_tests/*

0 commit comments

Comments
 (0)