-
Notifications
You must be signed in to change notification settings - Fork 1
/
azure-pipelines.yml
246 lines (211 loc) Β· 9.14 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
234
235
236
237
238
239
240
241
242
243
244
245
246
trigger:
- master
- develop
- release
variables:
latestBackendGitRevision: HEAD~1
latestFrontendGitRevision: HEAD~1
latestClientGitRevision: HEAD~1
isMasterBranch: eq(variables['Build.SourceBranch'], 'refs/heads/master')
isDevelopBranch: eq(variables['Build.SourceBranch'], 'refs/heads/developer')
isReleaseBranch: eq(variables['Build.SourceBranch'], 'refs/heads/release')
isPullRequest: $[ eq(variables['Build.Reason'], 'PullRequest') ]
dockerHubId: kochanowski
dockerHubImageName: maisie
jobs:
- job: Facts
displayName: Gather facts
pool:
vmImage: 'Ubuntu-16.04'
variables:
maisieVersionType: patch
sourceBranch: $[ variables['Build.SourceBranchName'] ]
rebuildBackend: 0
rebuildFrontend: 0
rebuildClient: 0
steps:
- bash: |
git checkout $(sourceBranch)
git diff-index $(latestBackendGitRevision) --quiet -- backend/
echo "##vso[task.setvariable variable=rebuildBackend]$?"
displayName: Check for changes in Backend component
- bash: echo "##vso[task.setvariable variable=rebuildBackend]1"
condition: eq(variables['forceRebuildBackend'], 'True')
displayName: Overwrite the rebuildBackend flag
- bash: |
git checkout $(sourceBranch)
git diff-index $(latestFrontendGitRevision) --quiet -- frontend/
echo "##vso[task.setvariable variable=rebuildFrontend]$?"
displayName: Check for changes in Frontend component
- bash: echo "##vso[task.setvariable variable=rebuildFrontend]1"
condition: eq(variables['forceRebuildFrontend'], 'True')
displayName: Overwrite the rebuildFrontend flag
- bash: |
git checkout $(sourceBranch)
git diff-index $(latestClientGitRevision) --quiet -- client/
echo "##vso[task.setvariable variable=rebuildClient]$?"
displayName: Check for changes in Client component
- bash: echo "##vso[task.setvariable variable=rebuildClient]1"
condition: eq(variables['forceRebuildClient'], 'True')
displayName: Overwrite the rebuildClient flag
- bash: echo "##vso[task.setvariable variable=maisieVersionType]minor"
condition: eq(variables['isMasterBranch'], 'True')
displayName: Set version type (Master)
- bash: echo "##vso[task.setvariable variable=maisieVersionType]major"
condition: eq(variables['isReleaseBranch'], 'True')
displayName: Set version type (Release)
- bash: |
echo "##vso[task.setvariable variable=maisieVersionType;isOutput=true]$(maisieVersionType)"
echo "##vso[task.setvariable variable=rebuildBackend;isOutput=true]$(rebuildBackend)"
echo "##vso[task.setvariable variable=rebuildFrontend;isOutput=true]$(rebuildFrontend)"
echo "##vso[task.setvariable variable=rebuildClient;isOutput=true]$(rebuildClient)"
name: factsVars
displayName: Publish variables
- job: VerifyFacts
displayName: Verify gathered facts
dependsOn: Facts
pool:
vmImage: 'Ubuntu-16.04'
variables:
maisieVersionType: $[ dependencies.Facts.outputs['factsVars.maisieVersionType'] ]
rebuildBackend: $[ dependencies.Facts.outputs['factsVars.rebuildBackend'] ]
rebuildFrontend: $[ dependencies.Facts.outputs['factsVars.rebuildFrontend'] ]
rebuildClient: $[ dependencies.Facts.outputs['factsVars.rebuildClient'] ]
isPullRequest: $[ eq(variables['Build.Reason'], 'PullRequest') ]
steps:
- script: |
echo maisieVersionType $(maisieVersionType)
echo latestClientGitRevision $(latestClientGitRevision)
echo latestBackendGitRevision $(latestBackendGitRevision)
echo latestFrontendGitRevision $(latestFrontendGitRevision)
echo rebuildClient $(rebuildClient)
echo rebuildBackend $(rebuildBackend)
echo rebuildFrontend $(rebuildFrontend)
echo isPullRequest $(isPullRequest)
echo Build.Reason $(Build.Reason)
echo Build.SourceBranch $(Build.SourceBranch)
displayName: Display the summary of variables
- job: BuildClient
displayName: Build Client - PyPI Package
dependsOn: Facts
condition: eq(dependencies.Facts.outputs['factsVars.rebuildClient'], '1')
pool:
vmImage: 'Ubuntu-16.04'
variables:
maisieVersionType: $[ dependencies.Facts.outputs['factsVars.maisieVersionType'] ]
workingDirectory: client
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.7'
- bash: |
python -m pip install --upgrade pip wheel
python -m pip install --pre black
black .
# pre-commit install
# find client -type f -name '*.py' | xargs pre-commit run --files
displayName: Check code formatting
workingDirectory: $(workingDirectory)
- bash: |
export UNVME_MAISIE=$(curl -s https://unversion.me/@kochanowski/maisie/pypi/client/$(maisieVersionType)/)
echo "##vso[task.setvariable variable=maisieVersion]$UNVME_MAISIE"
displayName: Get version number for the next release
- script: |
pip install -r requirements.txt
displayName: Install dependencies
workingDirectory: $(workingDirectory)
- script: cp ../README.rst README.rst
displayName: Provide README for the Client package
workingDirectory: $(workingDirectory)
- script: |
pip install pytest pytest-azurepipelines
# pytest
displayName: Test package
workingDirectory: $(workingDirectory)
- bash: |
python -m pip install bumpversion
export CURRENT_VERSION=$(python setup.py --version)
bumpversion --current-version $CURRENT_VERSION --new-version $(maisieVersion) --allow-dirty --no-commit --no-tag --list $(maisieVersionType) setup.py
displayName: Apply version patch for client configuration
workingDirectory: $(workingDirectory)
- script: |
pip install twine
python setup.py sdist bdist_wheel
twine check dist/*
displayName: 'Build package'
workingDirectory: $(workingDirectory)
- task: TwineAuthenticate@0
inputs:
externalFeeds: 'PyPI-UnversionMe'
- script: 'twine upload -r PyPI-UnversionMe --config-file $(PYPIRC_PATH) dist/*'
displayName: Publish to PyPI
condition: eq(variables['isPullRequest'], 'False')
workingDirectory: $(workingDirectory)
- bash: curl -s https://unversion.me/listener/$(unvmeClientListener)/$(maisieVersion)/
displayName: Call Unversion.me for the new release
condition: eq(variables['isPullRequest'], 'False')
- job: BuildBackend
displayName: Build Backend - DockerHub
dependsOn: Facts
condition: eq(dependencies.Facts.outputs['factsVars.rebuildBackend'], '1')
pool:
vmImage: 'Ubuntu-16.04'
variables:
maisieVersionType: $[ dependencies.Facts.outputs['factsVars.maisieVersionType'] ]
workingDirectory: backend
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.7'
- bash: |
python -m pip install --upgrade pip wheel
python -m pip install --pre black
black .
# pre-commit install
# find backend -type f -name '*.py' | xargs pre-commit run --files
displayName: Check code formatting
workingDirectory: $(workingDirectory)
- bash: |
export UNVME_MAISIE=$(curl -s https://unversion.me/@kochanowski/maisie/dockerhub/backend/$(maisieVersionType)/)
echo "##vso[task.setvariable variable=maisieVersion]$UNVME_MAISIE"
displayName: Get version number for the next release
- script: |
echo "Building backend image version $(maisieVersion)"
docker login -u $(dockerHubId) -p $password
docker build -t $(dockerHubId)/$(dockerHubImageName):backend -t $(dockerHubId)/$(dockerHubImageName):backend-$(maisieVersion) -f Dockerfile.production .
env:
password: $(dockerHubPassword)
displayName: Build new image
workingDirectory: $(workingDirectory)
- script: |
docker push $(dockerHubId)/$(dockerHubImageName):backend
docker push $(dockerHubId)/$(dockerHubImageName):backend-$(maisieVersion) && curl -s https://unversion.me/listener/$(unvmeBackendListener)/$(maisieVersion)/
displayName: Push built image
condition: eq(variables['isPullRequest'], 'False')
- job: BuildFrontend
displayName: Build Frontend - DockerHub
dependsOn: Facts
condition: eq(dependencies.Facts.outputs['factsVars.rebuildFrontend'], '1')
pool:
vmImage: 'Ubuntu-16.04'
variables:
maisieVersionType: $[ dependencies.Facts.outputs['factsVars.maisieVersionType'] ]
workingDirectory: frontend
steps:
- bash: |
export UNVME_MAISIE=$(curl -s https://unversion.me/@kochanowski/maisie/dockerhub/frontend/$(maisieVersionType)/)
echo "##vso[task.setvariable variable=maisieVersion]$UNVME_MAISIE"
displayName: Get version number for the next release
- script: |
echo "Building frontend image version $(maisieVersion)"
docker login -u $(dockerHubId) -p $password
docker build -t $(dockerHubId)/$(dockerHubImageName):frontend -t $(dockerHubId)/$(dockerHubImageName):frontend-$(maisieVersion) -f Dockerfile.production .
env:
password: $(dockerHubPassword)
displayName: Build new image
workingDirectory: $(workingDirectory)
- script: |
docker push $(dockerHubId)/$(dockerHubImageName):frontend
docker push $(dockerHubId)/$(dockerHubImageName):frontend-$(maisieVersion) && curl -s https://unversion.me/listener/$(unvmeFrontendListener)/$(maisieVersion)/
displayName: Push built image
condition: eq(variables['isPullRequest'], 'False')