-
Notifications
You must be signed in to change notification settings - Fork 1
/
azure-pipelines.yml
233 lines (225 loc) · 7.66 KB
/
azure-pipelines.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
trigger:
branches:
include:
- master
- staging
- feature/*
tags:
include:
- v*
parameters:
- name: 'python_build_version'
displayName: 'Python Build Version'
default: '3.8'
- name: 'is_release_tag'
displayName: 'Is Release Tag'
default: startsWith(variables['Build.SourceBranch'], 'refs/tags/v')
variables:
PIP_CACHE_DIR: $(Pipeline.Workspace)/.pip
stages:
- stage: build
displayName: Build
jobs:
- job:
displayName: 'Static Analysis'
pool:
vmImage: 'ubuntu-18.04'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '${{ parameters.python_build_version }}'
- task: Cache@2
inputs:
key: '"python${{ parameters.python_build_version }}" | "$(Agent.OS)" | requirements.dev.txt | requirements.txt'
restoreKeys: |
"python${{ parameters.python_build_version }}" | "$(Agent.OS)"
"python${{ parameters.python_build_version }}"
path: $(PIP_CACHE_DIR)
displayName: Cache pip packages
- script: |
pip install -c requirements.dev.txt wheel
pip install -c requirements.dev.txt -r requirements.dev.in
python setup.py --version
pip install -c requirements.txt .
displayName: 'Install package and dependencies'
- script: |
invoke lint
displayName: 'Run pylint'
- script: |
invoke mypy
displayName: 'Run mypy'
condition: succeededOrFailed()
- script: |
invoke bandit
displayName: 'Run bandit'
condition: succeededOrFailed()
- script: |
invoke yapf
displayName: 'Run yapf'
condition: succeededOrFailed()
- script: |
invoke isort
displayName: 'Run isort'
condition: succeededOrFailed()
- job:
displayName: 'Run Tests:'
pool:
vmImage: 'ubuntu-18.04'
strategy:
matrix:
'Python 3.6':
python.version: '3.6'
'Python 3.7':
python.version: '3.7'
'Python 3.8':
python.version: '3.8'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
- task: Cache@2
inputs:
key: '"python$(python.version)" | "$(Agent.OS)" | requirements.dev.txt | requirements.txt'
restoreKeys: |
"python$(python.version)" | "$(Agent.OS)"
"python$(python.version)"
path: $(PIP_CACHE_DIR)
displayName: Cache pip packages
- script: |
pip install -c requirements.dev.txt wheel
pip install -c requirements.dev.txt -r requirements.dev.in
python setup.py --version
pip install -c requirements.txt .
displayName: 'Install package and dependencies'
- script: |
invoke coverage-xml -- --junitxml="junit/test-results-$(python.version).xml"
displayName: 'Run tests and generate code coverage results'
- task: PublishTestResults@2
displayName: 'Publish test results for Python $(python.version)'
condition: succeededOrFailed()
inputs:
testRunTitle: 'Python $(python.version)'
testResultsFormat: 'JUnit'
testResultsFiles: 'junit/test-results-$(python.version).xml'
failTaskOnFailedTests: true
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage results for Python $(python.version)'
condition: eq(variables['python.version'], '${{ parameters.python_build_version }}')
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml'
- stage: package
displayName: Package
dependsOn: build
jobs:
- job:
displayName: 'Build Package'
pool:
vmImage: 'ubuntu-18.04'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '${{ parameters.python_build_version }}'
- task: Cache@2
inputs:
key: '"python${{ parameters.python_build_version }}" | "$(Agent.OS)" | requirements.dev.txt | requirements.txt'
restoreKeys: |
"python${{ parameters.python_build_version }}" | "$(Agent.OS)"
"python${{ parameters.python_build_version }}"
path: $(PIP_CACHE_DIR)
displayName: Cache pip packages
- script: |
pip install -c requirements.dev.txt wheel
pip install -c requirements.dev.txt -r requirements.dev.in
python setup.py sdist bdist_wheel
displayName: 'Build package'
- publish: '$(System.DefaultWorkingDirectory)/dist'
artifact: monocat
displayName: 'Publish Package Build Artifacts'
- stage: release
displayName: Release
dependsOn: package
condition: ${{ parameters.is_release_tag }}
jobs:
- job: validate_tag
displayName: 'Validate Release Tag'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '${{ parameters.python_build_version }}'
- task: Cache@2
inputs:
key: '"python${{ parameters.python_build_version }}" | "$(Agent.OS)" | requirements.dev.txt | requirements.txt'
restoreKeys: |
"python${{ parameters.python_build_version }}" | "$(Agent.OS)"
"python${{ parameters.python_build_version }}"
path: $(PIP_CACHE_DIR)
displayName: Cache pip packages
- script: |
pip install -c requirements.dev.txt setuptools_scm
python setup.py --version
python setup.py validate_tag --output-azure-variables
name: tag
displayName: 'Validate Release Tag'
- job: github_release
displayName: 'GitHub Release'
dependsOn: validate_tag
variables:
is_prerelease: $[ dependencies.validate_tag.outputs['tag.is_prerelease'] ]
steps:
- download: current
artifact: monocat
patterns: '*'
displayName: 'Download Package Build Artifacts'
- script: |
if [ "$(git cat-file -t '$(Build.SourceBranch)')" == "tag" ]; then
git for-each-ref --format='# %(contents)' '$(Build.SourceBranch)' > /tmp/annotation.md
else
echo '# Release $(Build.SourceBranchName)' > /tmp/annotation.md
fi
displayName: 'Prepare Release Notes'
- task: GitHubRelease@0 # See: <https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/github-release?view=azure-devops>
displayName: 'Create GitHub Release'
inputs:
gitHubConnection: 'github-jwilges'
repositoryName: '$(Build.Repository.Name)'
action: 'create'
target: '$(Build.SourceVersion)'
tagSource: 'auto'
title: '$(Build.SourceBranchName)'
releaseNotesSource: 'file'
releaseNotesFile: /tmp/annotation.md
assets: '$(Pipeline.Workspace)/monocat/*'
assetUploadMode: 'delete'
isDraft: false
isPreRelease: '$(is_prerelease)'
addChangeLog: true
compareWith: 'lastFullRelease'
- job: pypi_release
displayName: 'PyPI Release'
dependsOn: [validate_tag, github_release]
steps:
- checkout: none
- download: current
artifact: monocat
patterns: '*'
displayName: 'Download Package Build Artifacts'
- task: UsePythonVersion@0
inputs:
versionSpec: '${{ parameters.python_build_version }}'
- task: Cache@2
inputs:
key: '"python${{ parameters.python_build_version }}" | "$(Agent.OS)"'
restoreKeys: |
"python${{ parameters.python_build_version }}" | "$(Agent.OS)"
"python${{ parameters.python_build_version }}"
path: $(PIP_CACHE_DIR)
displayName: Cache pip packages
- task: TwineAuthenticate@1
displayName: 'Authenticate Twine'
inputs:
pythonUploadServiceConnection: pypi
- script: |
pip install twine
python -m twine upload --repository "pypi" --config-file $(PYPIRC_PATH) "$(Pipeline.Workspace)/monocat/*"
displayName: 'Upload package to PyPI'