Skip to content

Commit 38e30ee

Browse files
author
Dmytro Rezchykov
committed
add coverage report
1 parent dc71bf6 commit 38e30ee

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

.github/workflows/test-command.yml

+13
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,22 @@ jobs:
189189
path: |
190190
**/${{ github.event.inputs.connector }}/build/reports/tests/**/**
191191
**/${{ github.event.inputs.connector }}/acceptance_tests_logs/**
192+
**/${{ github.event.inputs.connector }}/htmlcov/**
192193
**/normalization_test_output/**/dbt_output.log
193194
**/normalization_test_output/**/destination_output.log
194195
**/normalization_test_output/**/build/compiled/airbyte_utils/**
195196
**/normalization_test_output/**/build/run/airbyte_utils/**
196197
**/normalization_test_output/**/models/generated/**
198+
199+
- name: Test coverage reports artifacts
200+
if: github.event.inputs.comment-id && success()
201+
uses: actions/upload-artifact@v2
202+
with:
203+
name: test-reports
204+
path: |
205+
**/${{ github.event.inputs.connector }}/htmlcov/**
206+
retention-days: 3
207+
197208
- name: Report Status
198209
if: github.ref == 'refs/heads/master' && always()
199210
run: ./tools/status/report.sh ${{ github.event.inputs.connector }} ${{github.repository}} ${{github.run_id}} ${{steps.test.outcome}}
@@ -208,6 +219,8 @@ jobs:
208219
comment-id: ${{ github.event.inputs.comment-id }}
209220
body: |
210221
> :white_check_mark: ${{github.event.inputs.connector}} https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
222+
223+
${{env.COVERAGE_REPORT}}
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-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ else
2626
elif [[ "$connector" == *"connectors"* ]]; then
2727
connector_name=$(echo $connector | cut -d / -f 2)
2828
selected_integration_test=$(echo "$all_integration_tests" | grep "^$connector_name$" || echo "")
29-
integrationTestCommand="$(_to_gradle_path "airbyte-integrations/$connector" integrationTest)"
29+
integrationTestCommand="$(_to_gradle_path "airbyte-integrations/$connector" unitTest)"
3030
else
3131
selected_integration_test=$(echo "$all_integration_tests" | grep "^$connector$" || echo "")
3232
integrationTestCommand=":airbyte-integrations:connectors:$connector:integrationTest"
@@ -46,10 +46,18 @@ 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 | tr '\n' ',' | sed 's/,/\<br\/\>/g'`
61+
#echo "COVERAGE_REPORT=\"$coverage_report\"" >> $GITHUB_ENV
62+
echo "COVERAGE_REPORT=\"$coverage_report\"" > report.sh
63+

tools/python/.coveragerc

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

0 commit comments

Comments
 (0)