-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path.gitlab-ci.yml
360 lines (287 loc) · 11.2 KB
/
.gitlab-ci.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# Note: expand yaml
# yaml merge-expand .gitlab-ci.yml _expandyml && cat _expandyml
#
# GITLAB LINTER
# https://gitlab.kitware.com/computer-vision/netharn/-/ci/lint
# This CI file has 4 types of jobs:
# (1) in the build stage we we build the wheels on a manylinux docker image
# (2) then in the test stage we install the wheels, run unit tests, and measure coverage
# (3) after testing we sign the wheels with the CI's GPG key
# (4) finally if we are on the release branch we will push the signed wheels to pypi
stages:
- build
- test
- gpgsign
- deploy
### TEMPLATES ###
# Define common templates using YAML anchors
.common_template: &common_template
tags:
# Tags define which runners will accept which jobs
- docker
- linux
- build
variables:
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
PIP_CACHE_DIR: "$CI_PROJECT_DIR/mb_work/cache_pip"
.build_template: &build_template
# Tags define which runners will accept which jobs
<<:
- *common_template
stage:
build
before_script:
- python -V # Print out python version for debugging
script:
- python setup.py bdist_wheel --universal
cache:
paths:
- .cache/pip
artifacts:
paths:
- dist/*.whl
.test_full_template: &test_full_template
# Tags define which runners will accept which jobs
<<:
- *common_template
stage:
test
before_script:
- python -V # Print out python version for debugging
- export PYVER=$(python -c "import sys; print('{}{}'.format(*sys.version_info[0:2]))")
- pip install --progress-bar off virtualenv
- virtualenv venv$PYVER
- source venv$PYVER/bin/activate
- pip install --progress-bar off pip -U
- pip install --progress-bar off pip setuptools -U
- python -V # Print out python version for debugging
- pip install --progress-bar off -r requirements.txt
- pip install .
# FIXME: we should start from a docker iamge that already has LibGL setup
- apt update && apt install libgl1-mesa-glx -y && rm -rf /var/lib/apt/lists/*
script:
- ./run_tests.py
cache:
paths:
- .cache/pip
- venv/
# Coverage is a regex that will parse the coverage from the test stdout
coverage: '/TOTAL.+ ([0-9]{1,3}%)/'
.__gpg_heredoc__: &__gpg_heredoc__
- |
# THIS IS NOT EXECUTE ON THE CI, THIS IS FOR DEVELOPER REFERENCE
# ON HOW THE ENCRYPTED GPG KEYS ARE SETUP.
# Load or generate secrets
source $(secret_loader.sh)
echo $CI_KITWARE_SECRET
echo $TWINE_USERNAME
# ADD RELEVANT VARIABLES TO GITLAB SECRET VARIABLES
# https://gitlab.kitware.com/computer-vision/netharn/-/settings/ci_cd
# Note that it is important to make sure that these variables are
# only decrpyted on protected branches by selecting the protected
# and masked option. Also make sure you have master and release
# branches protected.
# https://gitlab.kitware.com/computer-vision/netharn/-/settings/repository#js-protected-branches-settings
# HOW TO ENCRYPT YOUR SECRET GPG KEY
IDENTIFIER="travis-ci-Erotemic"
GPG_KEYID=$(gpg --list-keys --keyid-format LONG "$IDENTIFIER" | head -n 2 | tail -n 1 | awk '{print $1}' | tail -c 9)
echo "GPG_KEYID = $GPG_KEYID"
# Export plaintext gpg public keys, private keys, and trust info
mkdir -p dev
gpg --armor --export-secret-keys $GPG_KEYID > dev/ci_secret_gpg_key.pgp
gpg --armor --export $GPG_KEYID > dev/ci_public_gpg_key.pgp
gpg --export-ownertrust > dev/gpg_owner_trust
# Encrypt gpg keys and trust with CI secret
GLKWS=$CI_KITWARE_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:GLKWS -e -a -in dev/ci_public_gpg_key.pgp > dev/ci_public_gpg_key.pgp.enc
GLKWS=$CI_KITWARE_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:GLKWS -e -a -in dev/ci_secret_gpg_key.pgp > dev/ci_secret_gpg_key.pgp.enc
GLKWS=$CI_KITWARE_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:GLKWS -e -a -in dev/gpg_owner_trust > dev/gpg_owner_trust.enc
echo $GPG_KEYID > dev/public_gpg_key
# Test decrpyt
cat dev/public_gpg_key
GLKWS=$CI_KITWARE_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:GLKWS -d -a -in dev/ci_public_gpg_key.pgp.enc
GLKWS=$CI_KITWARE_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:GLKWS -d -a -in dev/gpg_owner_trust.enc
GLKWS=$CI_KITWARE_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:GLKWS -d -a -in dev/ci_secret_gpg_key.pgp.enc
source $(secret_unloader.sh)
# Look at what we did, clean up, and add it to git
ls dev/*.enc
rm dev/gpg_owner_trust dev/*.pgp
git status
git add dev/*.enc
git add dev/public_gpg_key
.gpgsign_template: &gpgsign_template
<<:
- *common_template
stage:
gpgsign
script:
- export GPG_EXECUTABLE=gpg
- export GPG_KEYID=$(cat dev/public_gpg_key)
- echo "GPG_KEYID = $GPG_KEYID"
- $GPG_EXECUTABLE --version
- openssl version
- $GPG_EXECUTABLE --list-keys
- $GPG_EXECUTABLE --list-keys
# Decrypt and import GPG Keys / trust
# note CI_KITWARE_SECRET is a protected variables only available on master and release branch
- GLKWS=$CI_KITWARE_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:GLKWS -d -a -in dev/ci_public_gpg_key.pgp.enc | $GPG_EXECUTABLE --import
- GLKWS=$CI_KITWARE_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:GLKWS -d -a -in dev/gpg_owner_trust.enc | $GPG_EXECUTABLE --import-ownertrust
- GLKWS=$CI_KITWARE_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:GLKWS -d -a -in dev/ci_secret_gpg_key.pgp.enc | $GPG_EXECUTABLE --import
- $GPG_EXECUTABLE --list-keys || echo "first one fails for some reason"
- $GPG_EXECUTABLE --list-keys
# The publish script only builds wheels and does gpg signing if TAG_AND_UPLOAD is False
- MB_PYTHON_TAG=$MB_PYTHON_TAG USE_GPG=True GPG_KEYID=$GPG_KEYID TWINE_PASSWORD=$TWINE_PASSWORD TWINE_USERNAME=$TWINE_USERNAME GPG_EXECUTABLE=$GPG_EXECUTABLE DEPLOY_BRANCH=release TAG_AND_UPLOAD=False ./publish.sh
artifacts:
paths:
- dist/*.asc
- dist/*.tar.gz
- dist/*.whl
only:
refs:
# Gitlab will only expose protected variables on protected branches
# (which I've set to be master and release), so only run this stage
# there.
- master
- release
.deploy_template: &deploy_template
<<:
- *common_template
stage:
deploy
script:
- export GPG_EXECUTABLE=gpg
- export GPG_KEYID=$(cat dev/public_gpg_key)
- echo "GPG_KEYID = $GPG_KEYID"
- $GPG_EXECUTABLE --version
- openssl version
- $GPG_EXECUTABLE --list-keys
- $GPG_EXECUTABLE --list-keys
# Decrypt and import GPG Keys / trust
# note CI_KITWARE_SECRET is a protected variables only available on master and release branch
- GLKWS=$CI_KITWARE_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:GLKWS -d -a -in dev/ci_public_gpg_key.pgp.enc | $GPG_EXECUTABLE --import
- GLKWS=$CI_KITWARE_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:GLKWS -d -a -in dev/gpg_owner_trust.enc | $GPG_EXECUTABLE --import-ownertrust
- GLKWS=$CI_KITWARE_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:GLKWS -d -a -in dev/ci_secret_gpg_key.pgp.enc | $GPG_EXECUTABLE --import
- $GPG_EXECUTABLE --list-keys || echo "first one fails for some reason"
- $GPG_EXECUTABLE --list-keys
# Install twine
- pip install six pyopenssl ndg-httpsclient pyasn1 -U
- pip install requests[security] twine
# Execute the publish script for real this time
- MB_PYTHON_TAG=$MB_PYTHON_TAG USE_GPG=True GPG_KEYID=$GPG_KEYID TWINE_PASSWORD=$TWINE_PASSWORD TWINE_USERNAME=$TWINE_USERNAME GPG_EXECUTABLE=$GPG_EXECUTABLE CURRENT_BRANCH=release DEPLOY_BRANCH=release TAG_AND_UPLOAD=yes ./publish.sh
# Have the server git-tag the release and push the tags
- VERSION=$(python -c "import setup; print(setup.VERSION)")
# do sed twice to handle the case of https clone with and without a read token
- URL_HOST=$(git remote get-url origin | sed -e 's|https\?://.*@||g' | sed -e 's|https\?://||g')
- echo "URL_HOST = $URL_HOST"
- git config user.email "[email protected]"
- git config user.name "Gitlab-CI"
- git tag $VERSION -m "tarball tag $VERSION"
- git push --tags "https://${GIT_PUSH_TOKEN}@${URL_HOST}"
only:
refs:
- release
.build_install_test: &build_install_test
- pip install -r requirements.txt -U
### JOBS ###
# Define the actual jobs
# ---------------
# Python 3.8 Jobs
build/cp38-cp38-linux:
<<:
- *build_template
image:
python:3.8
test_full/cp38-cp38-linux:
<<:
- *test_full_template
image:
python:3.8
# for universal builds we only need to gpg sign once
gpgsign/cp38-cp38-linux:
<<:
- *gpgsign_template
image:
python:3.8
deploy/cp38-cp38-linux:
<<:
- *deploy_template
image:
python:3.8
# ---------------
# Python 3.7 Jobs
build/cp37-cp37m-linux:
<<:
- *build_template
image:
python:3.7
test_full/cp37-cp37m-linux:
<<:
- *test_full_template
image:
python:3.7
# ---------------
# Python 3.6 Jobs
build/cp36-cp36m-linux:
<<:
- *build_template
image:
python:3.6
test_full/cp36-cp36m-linux:
<<:
- *test_full_template
image:
python:3.6
#gpgsign/cp36-cp36m-linux:
# <<:
# - *gpgsign_template
# image:
# python:3.6
#deploy/cp36-cp36m-linux:
# <<:
# - *deploy_template
# image:
# python:3.6
# ---------------
# Python 3.5 Jobs
build/cp35-cp35m-linux:
<<:
- *build_template
image:
python:3.5
test_full/cp35-cp35m-linux:
<<:
- *test_full_template
image:
python:3.5
#gpgsign/cp35-cp35m-linux:
# <<:
# - *gpgsign_template
# image:
# python:3.5
#deploy/cp35-cp35m-linux:
# <<:
# - *deploy_template
# image:
# python:3.5
# ---------------
# Python 2.7 Jobs
#build/cp27-cp27mu-linux:
# <<:
# - *build_template
# image:
# python:2.7
#test_full/cp27-cp27mu-linux:
# <<:
# - *test_full_template
# image:
# python:2.7
#gpgsign/cp27-cp27mu-linux:
# <<:
# - *gpgsign_template
# image:
# python:2.7
#deploy/cp27-cp27mu-linux:
# <<:
# - *deploy_template
# image:
# python:2.7