-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathazure-pipelines.yml
210 lines (187 loc) · 7.44 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
# Python Django
# Test a Django project on multiple versions of Python.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/python
variables:
# SPBM in the pipeline
# - wheel: Azure Pipelines recommendation
# - coverage[toml]: coverage that can read pyproject.toml
# - unittest-xml-reporting: XML from Django manage.py test
SPBM_TEST_REQUIREMENTS: >-
wheel coverage[toml] unittest-xml-reporting
# Cache variables
PIP_CACHE_DIR: /home/vsts/.cache/pip
# Other variables
DOCKER_BUILDKIT: 1
GIT_COMMIT_SHA: $(Build.SourceVersion)
GIT_BRANCH: $(Build.SourceBranch)
CI_BRANCH: $(Build.SourceBranch)
CI_BUILD_NUMBER: $(Build.BuildNumber)
CI_BUILD_URL: https://dev.azure.com/thoor/SPBM/_build/results?buildId=$(Build.BuildId)
CI_NAME: "Azure Pipelines"
trigger:
- master
pr:
- master
pool:
vmImage: "ubuntu-18.04"
stages:
- stage: build
displayName: "Build"
jobs:
- job: preNotifyCodeServices
displayName: "Pre-notify QA"
steps:
- script: |
curl -fsSL https://codeclimate.com/downloads/test-reporter/test-reporter-0.6.3-linux-amd64 -o cc-test-reporter && chmod +x ./cc-test-reporter
./cc-test-reporter before-build
displayName: "Notify services before build"
env:
CC_TEST_REPORTER_ID: $(CC_TEST_REPORTER_ID)
- job: test
displayName: "Test:"
dependsOn: preNotifyCodeServices
strategy:
matrix:
"Python 3.6":
PYTHON_VERSION: "3.6"
"Python 3.7":
PYTHON_VERSION: "3.7"
"Python 3.8":
PYTHON_VERSION: "3.8"
maxParallel: 3
steps:
- task: UsePythonVersion@0
displayName: "Select Python version"
inputs:
versionSpec: "$(PYTHON_VERSION)"
architecture: "x64"
- task: Cache@2
inputs:
key: 'pip_home | "$(PYTHON_VERSION)" | requirements.txt'
restoreKeys: |
pip_home | "$(PYTHON_VERSION)"
pip_home
path: $(PIP_CACHE_DIR)
- script: |
# CodeClimate prerequisities
curl -fsSL https://codeclimate.com/downloads/test-reporter/test-reporter-0.6.3-linux-amd64 -o cc-test-reporter && chmod +x ./cc-test-reporter
# Python project prerequisites: --find-links $(PIP_CACHE_FOLDER)
pip install --upgrade $(SPBM_TEST_REQUIREMENTS)
pip install -r requirements.txt
displayName: "Install prerequisites"
failOnStderr: true
- script: |
python -m coverage run --branch ./manage.py test --testrunner xmlrunner.extra.djangotestrunner.XMLTestRunner --no-input
python -m coverage report
python -m coverage xml
mkdir -p coverage && cp .coverage coverage/.coverage.$(Agent.Id)
displayName: "Test with coverage"
- script: |
# Run CodeClimate test reporter
./cc-test-reporter format-coverage --output coverage/codeclimate.$(Agent.Id).json
displayName: "Format coverage data"
- publish: coverage
artifact: "coverage_$(Agent.Id)"
displayName: "Save coverage reports"
- task: PublishTestResults@2
inputs:
testResultsFiles: "**/TEST-*.xml"
testRunTitle: "Python $(PYTHON_VERSION)"
mergeTestResults: true
condition: succeededOrFailed()
- task: PublishCodeCoverageResults@1
inputs:
summaryFileLocation: coverage.xml
codeCoverageTool: cobertura
- job: postNotifyCodeServices
displayName: "Post-notify QA"
dependsOn: test
condition: succeededOrFailed()
steps:
- download: current
patterns: |
**/*.json
**/.coverage*
- task: UsePythonVersion@0
displayName: "Select Python version"
- script: |
pip install coverage
coverage combine $(Pipeline.Workspace)/coverage_*/.coverage*
coverage xml
# Update env vars to make sense
BRANCH_NAME=$(echo $GIT_BRANCH | cut -d/ -f3-)
echo "Correct branch name is $BRANCH_NAME"
echo "###vso[task.setvariable variable=CI_BRANCH]$BRANCH_NAME"
echo "###vso[task.setvariable variable=GIT_BRANCH]$BRANCH_NAME"
displayName: "Combine coverage.py & fix env vars"
- script: |
curl -fsSL https://codeclimate.com/downloads/test-reporter/test-reporter-0.6.3-linux-amd64 -o cc-test-reporter && chmod +x ./cc-test-reporter
./cc-test-reporter sum-coverage $(Pipeline.Workspace)/coverage_*/codeclimate.*.json
./cc-test-reporter upload-coverage
env:
CC_TEST_REPORTER_ID: $(CC_TEST_REPORTER_ID)
displayName: "Notify Code Climate"
- script: |
LATEST_VERSION="$(curl -Ls https://artifacts.codacy.com/bin/codacy-coverage-reporter/latest)"
curl -Ls -o codacy-coverage-reporter "https://artifacts.codacy.com/bin/codacy-coverage-reporter/${LATEST_VERSION}/codacy-coverage-reporter-linux"
chmod +x codacy-coverage-reporter
./codacy-coverage-reporter report -l Python -r coverage.xml
env:
CODACY_PROJECT_TOKEN: $(CODACY_PROJECT_TOKEN)
displayName: "Notify Codacy"
- script: |
bash <(curl -s https://codecov.io/bash) -f coverage.xml
env:
CODECOV_TOKEN: $(CODECOV_TOKEN)
displayName: "Notify Codecov"
- script: |
pip install coveralls
coveralls
env:
COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN)
displayName: "Notify coveralls"
- stage: buildContainer
displayName: "Build Container"
condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/master'))
jobs:
- deployment: buildImage
environment: Test
displayName: "Build Docker Container"
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: Docker@2
displayName: "Build Docker Container"
inputs:
command: "build"
Dockerfile: "Dockerfile"
containerRegistry: "Docker Hub"
tags: |
$(Build.BuildId)
latest
- stage: publishContainer
displayName: "Publish Container"
dependsOn: build
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
jobs:
- deployment: publishImage
environment: Production
displayName: "Publish on Docker Hub"
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: Docker@2
displayName: "Build & Publish Docker Image"
inputs:
command: "buildAndPush"
Dockerfile: "Dockerfile"
repository: "cybernetisk/spbm"
containerRegistry: "Docker Hub"
tags: |
$(Build.BuildId)
latest