Improve validation pipeline

This commit is contained in:
Odd Stråbø 2020-10-05 06:27:07 +02:00
parent 28b60d7e06
commit faf7ad4bb3
3 changed files with 42 additions and 7 deletions

View File

@ -7,20 +7,52 @@ steps:
displayName: 'Install dev tools' displayName: 'Install dev tools'
- script: | - script: |
rm flake8.output # Azure pipelines: https://github.com/microsoft/azure-pipelines-tasks/blob/master/docs/authoring/commands.md
flake8 . --statistics --output-file=flake8.output && echo "::set-output name=lint::ok" || echo "::set-output name=lint::error" # GitHub actions: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions
cat flake8.output | awk -F: '{ if ($0 ~ /^\./) { gsub(/^[ \t]+/,"",$4); print "::error file=" $1 ",line=" $2 ",col=" $3 "::" $4 } else { print $0 } }'
rm -f flake8.output
flake8 . --statistics --output-file=flake8.output && {
echo "##vso[task.complete result=Succeeded;]"
} || {
echo "##vso[task.complete result=Failed;]"
}
cat flake8.output | awk -F: '{
if ($0 ~ /^\./) {
gsub(/^[ \t]+/,"",$4);
codesep=index($4, " ");
code=substr($4, 1, codesep-1);
msg=substr($4, codesep+1);
print "##vso[task.logissue type=error;sourcepath=" $1 ";linenumber=" $2 ";columnnumber=" $3 ";code=" code ";]" msg;
} else {
print $0
}
}'
displayName: 'Run Linter' displayName: 'Run Linter'
failOnStderr: false failOnStderr: false
- script: | - script: |
rm ../test_results.xml rm -f test.xml coverage.xml
pytest --junitxml=../test_results.xml coverage run && {
echo "##vso[task.complete result=Succeeded;]"
} || {
echo "##vso[task.complete result=Failed;]"
}
coverage xml
coverage html
coverage report
displayName: 'Run Tests' displayName: 'Run Tests'
failOnStderr: false failOnStderr: false
condition: succeededOrFailed()
- task: PublishTestResults@2 - task: PublishTestResults@2
condition: succeededOrFailed() condition: succeededOrFailed()
inputs: inputs:
testResultsFiles: '../test_results.xml' testResultsFiles: 'test.xml'
testRunTitle: 'Publish test results for Python $(python.version)' testRunTitle: 'Publish test results for Python $(python.version)'
- task: PublishCodeCoverageResults@1
condition: succeededOrFailed()
inputs:
codeCoverageTool: 'cobertura'
summaryFileLocation: 'coverage.xml'

2
.gitignore vendored
View File

@ -50,6 +50,8 @@ coverage.xml
*.py,cover *.py,cover
.hypothesis/ .hypothesis/
.pytest_cache/ .pytest_cache/
flake8.output
test.xml
# Translations # Translations
*.mo *.mo

View File

@ -21,4 +21,5 @@ source =
service.py service.py
.config/generate_xml.py .config/generate_xml.py
omit = tests/* omit = tests/*
command_line = -m pytest branch = True
command_line = -m pytest --junitxml=test.xml