Skip to content

Commit

Permalink
add coverage report
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Rezchykov committed Sep 14, 2021
1 parent dc71bf6 commit 38e30ee
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/test-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,22 @@ jobs:
path: |
**/${{ github.event.inputs.connector }}/build/reports/tests/**/**
**/${{ github.event.inputs.connector }}/acceptance_tests_logs/**
**/${{ github.event.inputs.connector }}/htmlcov/**
**/normalization_test_output/**/dbt_output.log
**/normalization_test_output/**/destination_output.log
**/normalization_test_output/**/build/compiled/airbyte_utils/**
**/normalization_test_output/**/build/run/airbyte_utils/**
**/normalization_test_output/**/models/generated/**
- name: Test coverage reports artifacts
if: github.event.inputs.comment-id && success()
uses: actions/upload-artifact@v2
with:
name: test-reports
path: |
**/${{ github.event.inputs.connector }}/htmlcov/**
retention-days: 3

- name: Report Status
if: github.ref == 'refs/heads/master' && always()
run: ./tools/status/report.sh ${{ github.event.inputs.connector }} ${{github.repository}} ${{github.run_id}} ${{steps.test.outcome}}
Expand All @@ -208,6 +219,8 @@ jobs:
comment-id: ${{ github.event.inputs.comment-id }}
body: |
> :white_check_mark: ${{github.event.inputs.connector}} https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
${{env.COVERAGE_REPORT}}
- name: Add Failure Comment
if: github.event.inputs.comment-id && failure()
uses: peter-evans/create-or-update-comment@v1
Expand Down
17 changes: 9 additions & 8 deletions buildSrc/src/main/groovy/airbyte-python.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ class AirbytePythonConfiguration {
class Helpers {
static addTestTaskIfTestFilesFound(Project project, String testFilesDirectory, String taskName, taskDependencies) {
"""
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
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
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
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
like:
like:
```
def make_ci_pass_test():
assert True
```
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)
to selectively run pytest based on whether there seem to be test files in that directory.
Namely, if the directory contains a file whose name is test_*.py or *_test.py then it's a test.
to selectively run pytest based on whether there seem to be test files in that directory.
Namely, if the directory contains a file whose name is test_*.py or *_test.py then it's a test.
See https://github.com/airbytehq/airbyte/issues/4979 for original context
"""
if (project.file(testFilesDirectory).exists()) {

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

Expand Down
16 changes: 12 additions & 4 deletions tools/bin/ci_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ else
elif [[ "$connector" == *"connectors"* ]]; then
connector_name=$(echo $connector | cut -d / -f 2)
selected_integration_test=$(echo "$all_integration_tests" | grep "^$connector_name$" || echo "")
integrationTestCommand="$(_to_gradle_path "airbyte-integrations/$connector" integrationTest)"
integrationTestCommand="$(_to_gradle_path "airbyte-integrations/$connector" unitTest)"
else
selected_integration_test=$(echo "$all_integration_tests" | grep "^$connector$" || echo "")
integrationTestCommand=":airbyte-integrations:connectors:$connector:integrationTest"
Expand All @@ -46,10 +46,18 @@ run | tee build.out
# return status of "run" command, not "tee"
# https://tldp.org/LDP/abs/html/internalvariables.html#PIPESTATUSREF
run_status=${PIPESTATUS[0]}

test $run_status == "0" || {
# Build failed
link=$(cat build.out | grep -A1 "Publishing build scan..." | tail -n1 | tr -d "\n")
# Save gradle scan link to github GRADLE_SCAN_LINK variable for next job.
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
LINK=$(cat build.out | grep -A1 "Publishing build scan..." | tail -n1 | tr -d "\n")
echo "GRADLE_SCAN_LINK=$LINK" >> $GITHUB_ENV
echo "GRADLE_SCAN_LINK=$link" >> $GITHUB_ENV
exit $run_status
}
exit $run_status

# Build successed
coverage_report=`sed -n '/--- coverage: /,/TOTAL /p' build.out | tr '\n' ',' | sed 's/,/\<br\/\>/g'`
#echo "COVERAGE_REPORT=\"$coverage_report\"" >> $GITHUB_ENV
echo "COVERAGE_REPORT=\"$coverage_report\"" > report.sh

9 changes: 9 additions & 0 deletions tools/python/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[run]
omit =
.venv/*
main.py
setup.py
unit_tests/*
integration_tests/*
[pathes]
source = ./

0 comments on commit 38e30ee

Please sign in to comment.