forked from liupeirong/MLOpsManufacturing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
python-code-validation.yml
105 lines (90 loc) · 3.02 KB
/
python-code-validation.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Python validation steps template
parameters:
- name: workingDir
type: string
- name: pythonVersion
type: string
- name: requirementPaths
type: string
default: ''
- name: validationPath
type: string
default: ''
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: ${{ parameters.pythonVersion }}
- script: |
python -m pip install --upgrade pip setuptools wheel
displayName: 'Install tools'
- script: |
if ! [ -z '${{ parameters.requirementPaths }}' ]
then
requirement_files='${{ parameters.requirementPaths }}'
else
requirement_files=$(find . -type f -name 'requirements.txt')
fi
for file in $requirement_files
do
echo Install $file
python -m pip install -r $file
done
displayName: 'Install requirements'
workingDirectory: ${{ parameters.workingDir }}
- script: |
validationPath='.'
if ! [ -z '${{ parameters.validationPath }}' ]
then
validationPath='${{ parameters.validationPath }}'
fi
echo Validation path: $validationPath
flake8 $validationPath --output-file=$(Common.TestResultsDirectory)/test-linter-results.txt
flake8_junit $(Common.TestResultsDirectory)/test-linter-results.txt $(Common.TestResultsDirectory)/test-linter-results.xml
displayName: 'Run linter'
condition: succeededOrFailed()
workingDirectory: ${{ parameters.workingDir }}
- task: PublishTestResults@2
displayName: 'Publish linter results'
condition: succeededOrFailed()
inputs:
testResultsFiles: '**/test-linter-results.xml'
testRunTitle: 'Linter tests'
failTaskOnFailedTests: true
searchFolder: $(Common.TestResultsDirectory)
- script: |
validationPath='.'
if ! [ -z '${{ parameters.validationPath }}' ]
then
validationPath='${{ parameters.validationPath }}'
fi
echo Validation path: $validationPath
python -m pytest \
--junitxml=$(Common.TestResultsDirectory)/test-unittest-results.xml \
--cov=. \
--cov-report=xml:$(Common.TestResultsDirectory)/coverage.xml \
$validationPath
# If there are no unit tests, don't fail because of that
ret=$?
if [ "$ret" = 5 ]; then
echo "No tests collected. Exiting with 0 (instead of 5)."
exit 0
fi
exit "$ret"
displayName: 'Run unit tests'
condition: succeededOrFailed()
workingDirectory: ${{ parameters.workingDir }}
- task: PublishTestResults@2
displayName: 'Publish unit test results'
condition: succeededOrFailed()
inputs:
testResultsFiles: '**/test-unittest-results.xml'
testRunTitle: 'Unit tests'
failTaskOnFailedTests: true
searchFolder: $(Common.TestResultsDirectory)
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage results'
condition: succeededOrFailed()
inputs:
codeCoverageTool: cobertura
pathToSources: ${{ parameters.workingDir }}
summaryFileLocation: '$(Common.TestResultsDirectory)/**/coverage.xml'