-
Notifications
You must be signed in to change notification settings - Fork 2
/
.gitlab-ci.yml
633 lines (620 loc) · 21.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
# Autogenerated by ~/code/xcookie/xcookie/builders/gitlab_ci.py
stages:
# TEMPLATES
- lint
- build
- gpgsign
- test
- deploy
.common_template: &common_template
tags:
# Tags define which runners will accept which jobs
- docker
- linux-x86_64
- build
- kitware-python-stack
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/.cache/pip"
except:
# Don't run the pipeline for new tags
- tags
cache:
paths:
- .cache/pip
.build_sdist_template: &build_sdist_template
<<: *common_template
stage: build
script:
- python -m pip install setuptools>=0.8 wheel build twine
- python -m build --sdist --outdir dist
- python -m twine check ./dist/kwimage*.tar.gz
artifacts:
paths:
- ./dist/kwimage*.tar.gz
.build_wheel_template: &build_wheel_template
<<: *common_template
stage: build
before_script:
- 'python -V # Print out python version for debugging'
- df -h
script:
- python -m pip install setuptools>=0.8 wheel build twine
- python -m build --wheel --outdir dist
- python -m twine check ./dist/kwimage*.whl
artifacts:
paths:
- ./dist/kwimage*.whl
.common_test_template: &common_test_template
<<: *common_template
stage: test
coverage: /TOTAL.+ ([0-9]{1,3}%)/
.test_minimal-loose_template: &test_minimal-loose_template
<<: *common_test_template
before_script:
- |-
# Setup the correct version of python (which should be the same as this instance)
python --version # Print out python version for debugging
export PYVER=$(python -c "import sys; print('{}{}'.format(*sys.version_info[0:2]))")
python -m pip install virtualenv
python -m virtualenv venv$PYVER
source venv$PYVER/bin/activate
pip install pip -U
pip install pip setuptools -U
pip install pygments
python --version # Print out python version for debugging
script:
- export INSTALL_EXTRAS="tests,headless"
- echo "Finding the path to the wheel"
- ls dist || echo "dist does not exist"
- echo "Installing helpers"
- pip install setuptools>=0.8 setuptools_scm wheel build -U
- pip install tomli pkginfo
- |-
export WHEEL_FPATH=$(python -c "if 1:
import pathlib
dist_dpath = pathlib.Path('dist')
candidates = list(dist_dpath.glob('kwimage*.whl'))
candidates += list(dist_dpath.glob('kwimage*.tar.gz'))
fpath = sorted(candidates)[-1]
print(str(fpath).replace(chr(92), chr(47)))
")
- |-
export MOD_VERSION=$(python -c "if 1:
from pkginfo import Wheel, SDist
fpath = '$WHEEL_FPATH'
cls = Wheel if fpath.endswith('.whl') else SDist
print(cls(fpath).version)
")
- pip install -r requirements/gdal.txt
- echo "WHEEL_FPATH=$WHEEL_FPATH"
- echo "INSTALL_EXTRAS=$INSTALL_EXTRAS"
- echo "MOD_VERSION=$MOD_VERSION"
- pip install --prefer-binary "kwimage[$INSTALL_EXTRAS]==$MOD_VERSION" -f dist
- echo "Install finished."
- echo "Creating test sandbox directory"
- export WORKSPACE_DNAME="sandbox"
- echo "WORKSPACE_DNAME=$WORKSPACE_DNAME"
- mkdir -p $WORKSPACE_DNAME
- echo "cd-ing into the workspace"
- cd $WORKSPACE_DNAME
- pwd
- ls -altr
- '# Get the path to the installed package and run the tests'
- export MOD_DPATH=$(python -c "import kwimage, os; print(os.path.dirname(kwimage.__file__))")
- export MOD_NAME=kwimage
- |-
echo "
---
MOD_DPATH = $MOD_DPATH
---
running the pytest command inside the workspace
---
"
- |-
python -m pytest --verbose -p pytester -p no:doctest --xdoctest --cov-config ../pyproject.toml --cov-report term --durations=100 --cov="$MOD_NAME" "$MOD_DPATH" ../tests
- echo "pytest command finished, moving the coverage file to the repo root"
.test_full-loose_template: &test_full-loose_template
<<: *common_test_template
before_script:
- |-
# Setup the correct version of python (which should be the same as this instance)
python --version # Print out python version for debugging
export PYVER=$(python -c "import sys; print('{}{}'.format(*sys.version_info[0:2]))")
python -m pip install virtualenv
python -m virtualenv venv$PYVER
source venv$PYVER/bin/activate
pip install pip -U
pip install pip setuptools -U
pip install pygments
python --version # Print out python version for debugging
script:
- export INSTALL_EXTRAS="tests,optional,headless"
- echo "Finding the path to the wheel"
- ls dist || echo "dist does not exist"
- echo "Installing helpers"
- pip install setuptools>=0.8 setuptools_scm wheel build -U
- pip install tomli pkginfo
- |-
export WHEEL_FPATH=$(python -c "if 1:
import pathlib
dist_dpath = pathlib.Path('dist')
candidates = list(dist_dpath.glob('kwimage*.whl'))
candidates += list(dist_dpath.glob('kwimage*.tar.gz'))
fpath = sorted(candidates)[-1]
print(str(fpath).replace(chr(92), chr(47)))
")
- |-
export MOD_VERSION=$(python -c "if 1:
from pkginfo import Wheel, SDist
fpath = '$WHEEL_FPATH'
cls = Wheel if fpath.endswith('.whl') else SDist
print(cls(fpath).version)
")
- pip install -r requirements/gdal.txt
- echo "WHEEL_FPATH=$WHEEL_FPATH"
- echo "INSTALL_EXTRAS=$INSTALL_EXTRAS"
- echo "MOD_VERSION=$MOD_VERSION"
- pip install --prefer-binary "kwimage[$INSTALL_EXTRAS]==$MOD_VERSION" -f dist
- echo "Install finished."
- echo "Creating test sandbox directory"
- export WORKSPACE_DNAME="sandbox"
- echo "WORKSPACE_DNAME=$WORKSPACE_DNAME"
- mkdir -p $WORKSPACE_DNAME
- echo "cd-ing into the workspace"
- cd $WORKSPACE_DNAME
- pwd
- ls -altr
- '# Get the path to the installed package and run the tests'
- export MOD_DPATH=$(python -c "import kwimage, os; print(os.path.dirname(kwimage.__file__))")
- export MOD_NAME=kwimage
- |-
echo "
---
MOD_DPATH = $MOD_DPATH
---
running the pytest command inside the workspace
---
"
- |-
python -m pytest --verbose -p pytester -p no:doctest --xdoctest --cov-config ../pyproject.toml --cov-report term --durations=100 --cov="$MOD_NAME" "$MOD_DPATH" ../tests
- echo "pytest command finished, moving the coverage file to the repo root"
.test_minimal-strict_template: &test_minimal-strict_template
<<: *common_test_template
before_script:
- |-
# Setup the correct version of python (which should be the same as this instance)
python --version # Print out python version for debugging
export PYVER=$(python -c "import sys; print('{}{}'.format(*sys.version_info[0:2]))")
python -m pip install virtualenv
python -m virtualenv venv$PYVER
source venv$PYVER/bin/activate
pip install pip -U
pip install pip setuptools -U
pip install pygments
python --version # Print out python version for debugging
script:
- export INSTALL_EXTRAS="tests-strict,runtime-strict,headless-strict"
- echo "Finding the path to the wheel"
- ls dist || echo "dist does not exist"
- echo "Installing helpers"
- pip install setuptools>=0.8 setuptools_scm wheel build -U
- pip install tomli pkginfo
- |-
export WHEEL_FPATH=$(python -c "if 1:
import pathlib
dist_dpath = pathlib.Path('dist')
candidates = list(dist_dpath.glob('kwimage*.whl'))
candidates += list(dist_dpath.glob('kwimage*.tar.gz'))
fpath = sorted(candidates)[-1]
print(str(fpath).replace(chr(92), chr(47)))
")
- |-
export MOD_VERSION=$(python -c "if 1:
from pkginfo import Wheel, SDist
fpath = '$WHEEL_FPATH'
cls = Wheel if fpath.endswith('.whl') else SDist
print(cls(fpath).version)
")
- pip install -r requirements/gdal.txt
- echo "WHEEL_FPATH=$WHEEL_FPATH"
- echo "INSTALL_EXTRAS=$INSTALL_EXTRAS"
- echo "MOD_VERSION=$MOD_VERSION"
- pip install --prefer-binary "kwimage[$INSTALL_EXTRAS]==$MOD_VERSION" -f dist
- echo "Install finished."
- echo "Creating test sandbox directory"
- export WORKSPACE_DNAME="sandbox"
- echo "WORKSPACE_DNAME=$WORKSPACE_DNAME"
- mkdir -p $WORKSPACE_DNAME
- echo "cd-ing into the workspace"
- cd $WORKSPACE_DNAME
- pwd
- ls -altr
- '# Get the path to the installed package and run the tests'
- export MOD_DPATH=$(python -c "import kwimage, os; print(os.path.dirname(kwimage.__file__))")
- export MOD_NAME=kwimage
- |-
echo "
---
MOD_DPATH = $MOD_DPATH
---
running the pytest command inside the workspace
---
"
- |-
python -m pytest --verbose -p pytester -p no:doctest --xdoctest --cov-config ../pyproject.toml --cov-report term --durations=100 --cov="$MOD_NAME" "$MOD_DPATH" ../tests
- echo "pytest command finished, moving the coverage file to the repo root"
.test_full-strict_template: &test_full-strict_template
<<: *common_test_template
before_script:
- |-
# Setup the correct version of python (which should be the same as this instance)
python --version # Print out python version for debugging
export PYVER=$(python -c "import sys; print('{}{}'.format(*sys.version_info[0:2]))")
python -m pip install virtualenv
python -m virtualenv venv$PYVER
source venv$PYVER/bin/activate
pip install pip -U
pip install pip setuptools -U
pip install pygments
python --version # Print out python version for debugging
script:
- export INSTALL_EXTRAS="tests-strict,runtime-strict,optional-strict,headless-strict"
- echo "Finding the path to the wheel"
- ls dist || echo "dist does not exist"
- echo "Installing helpers"
- pip install setuptools>=0.8 setuptools_scm wheel build -U
- pip install tomli pkginfo
- |-
export WHEEL_FPATH=$(python -c "if 1:
import pathlib
dist_dpath = pathlib.Path('dist')
candidates = list(dist_dpath.glob('kwimage*.whl'))
candidates += list(dist_dpath.glob('kwimage*.tar.gz'))
fpath = sorted(candidates)[-1]
print(str(fpath).replace(chr(92), chr(47)))
")
- |-
export MOD_VERSION=$(python -c "if 1:
from pkginfo import Wheel, SDist
fpath = '$WHEEL_FPATH'
cls = Wheel if fpath.endswith('.whl') else SDist
print(cls(fpath).version)
")
- pip install -r requirements/gdal.txt
- echo "WHEEL_FPATH=$WHEEL_FPATH"
- echo "INSTALL_EXTRAS=$INSTALL_EXTRAS"
- echo "MOD_VERSION=$MOD_VERSION"
- pip install --prefer-binary "kwimage[$INSTALL_EXTRAS]==$MOD_VERSION" -f dist
- echo "Install finished."
- echo "Creating test sandbox directory"
- export WORKSPACE_DNAME="sandbox"
- echo "WORKSPACE_DNAME=$WORKSPACE_DNAME"
- mkdir -p $WORKSPACE_DNAME
- echo "cd-ing into the workspace"
- cd $WORKSPACE_DNAME
- pwd
- ls -altr
- '# Get the path to the installed package and run the tests'
- export MOD_DPATH=$(python -c "import kwimage, os; print(os.path.dirname(kwimage.__file__))")
- export MOD_NAME=kwimage
- |-
echo "
---
MOD_DPATH = $MOD_DPATH
---
running the pytest command inside the workspace
---
"
- |-
python -m pytest --verbose -p pytester -p no:doctest --xdoctest --cov-config ../pyproject.toml --cov-report term --durations=100 --cov="$MOD_NAME" "$MOD_DPATH" ../tests
- echo "pytest command finished, moving the coverage file to the repo root"
build/sdist:
<<: *build_sdist_template
image: python:3.11
test/sdist/minimal-loose/cp311-linux-x86_64:
<<: *test_minimal-loose_template
image: python:3.11
needs:
- build/sdist
build/cp39-linux-x86_64:
<<: *build_wheel_template
image: python:3.9
test/minimal-loose/cp39-linux-x86_64:
<<: *test_minimal-loose_template
image: python:3.9
needs:
- build/cp39-linux-x86_64
test/full-loose/cp39-linux-x86_64:
<<: *test_full-loose_template
image: python:3.9
needs:
- build/cp39-linux-x86_64
test/minimal-strict/cp39-linux-x86_64:
<<: *test_minimal-strict_template
image: python:3.9
needs:
- build/cp39-linux-x86_64
test/full-strict/cp39-linux-x86_64:
<<: *test_full-strict_template
image: python:3.9
needs:
- build/cp39-linux-x86_64
build/cp310-linux-x86_64:
<<: *build_wheel_template
image: python:3.10
test/minimal-loose/cp310-linux-x86_64:
<<: *test_minimal-loose_template
image: python:3.10
needs:
- build/cp310-linux-x86_64
test/full-loose/cp310-linux-x86_64:
<<: *test_full-loose_template
image: python:3.10
needs:
- build/cp310-linux-x86_64
test/minimal-strict/cp310-linux-x86_64:
<<: *test_minimal-strict_template
image: python:3.10
needs:
- build/cp310-linux-x86_64
test/full-strict/cp310-linux-x86_64:
<<: *test_full-strict_template
image: python:3.10
needs:
- build/cp310-linux-x86_64
build/cp311-linux-x86_64:
<<: *build_wheel_template
image: python:3.11
test/minimal-loose/cp311-linux-x86_64:
<<: *test_minimal-loose_template
image: python:3.11
needs:
- build/cp311-linux-x86_64
test/full-loose/cp311-linux-x86_64:
<<: *test_full-loose_template
image: python:3.11
needs:
- build/cp311-linux-x86_64
test/minimal-strict/cp311-linux-x86_64:
<<: *test_minimal-strict_template
image: python:3.11
needs:
- build/cp311-linux-x86_64
test/full-strict/cp311-linux-x86_64:
<<: *test_full-strict_template
image: python:3.11
needs:
- build/cp311-linux-x86_64
build/cp312-linux-x86_64:
<<: *build_wheel_template
image: python:3.12
test/minimal-loose/cp312-linux-x86_64:
<<: *test_minimal-loose_template
image: python:3.12
needs:
- build/cp312-linux-x86_64
test/full-loose/cp312-linux-x86_64:
<<: *test_full-loose_template
image: python:3.12
needs:
- build/cp312-linux-x86_64
test/minimal-strict/cp312-linux-x86_64:
<<: *test_minimal-strict_template
image: python:3.12
needs:
- build/cp312-linux-x86_64
test/full-strict/cp312-linux-x86_64:
<<: *test_full-strict_template
image: python:3.12
needs:
- build/cp312-linux-x86_64
build/cp313-linux-x86_64:
<<: *build_wheel_template
image: python:3.13
test/minimal-loose/cp313-linux-x86_64:
<<: *test_minimal-loose_template
image: python:3.13
needs:
- build/cp313-linux-x86_64
test/full-loose/cp313-linux-x86_64:
<<: *test_full-loose_template
image: python:3.13
needs:
- build/cp313-linux-x86_64
test/minimal-strict/cp313-linux-x86_64:
<<: *test_minimal-strict_template
image: python:3.13
needs:
- build/cp313-linux-x86_64
test/full-strict/cp313-linux-x86_64:
<<: *test_full-strict_template
image: python:3.13
needs:
- build/cp313-linux-x86_64
lint:
<<: *common_template
image: python:3.11
stage: lint
before_script:
- df -h
script:
- pip install -r requirements/linting.txt
- ./run_linter.sh
allow_failure: true
gpgsign/wheels:
<<: *common_template
image: python:3.11
stage: gpgsign
artifacts:
paths:
- dist/*.asc
- dist/*.tar.gz
- dist/*.whl
- dist/*.ots
only:
refs:
# Gitlab will only expose protected variables on protected branches
# (which I've set to be main and release), so only run this stage
# there.
- master
- main
- release
script:
- ls dist
- export GPG_EXECUTABLE=gpg
- export GPG_KEYID=$(cat dev/public_gpg_key)
- echo "GPG_KEYID = $GPG_KEYID"
# Decrypt and import GPG Keys / trust
# note the variable pointed to by VARNAME_CI_SECRET is a protected variables only available on main and release branch
- source dev/secrets_configuration.sh
- CI_SECRET=${!VARNAME_CI_SECRET}
- $GPG_EXECUTABLE --version
- openssl version
- $GPG_EXECUTABLE --list-keys
# note CI_KITWARE_SECRET is a protected variables only available on main and release branch
- CIS=$CI_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:CIS -d -a -in dev/ci_public_gpg_key.pgp.enc | $GPG_EXECUTABLE --import
- CIS=$CI_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:CIS -d -a -in dev/gpg_owner_trust.enc | $GPG_EXECUTABLE --import-ownertrust
- CIS=$CI_SECRET openssl enc -aes-256-cbc -pbkdf2 -md SHA512 -pass env:CIS -d -a -in dev/ci_secret_gpg_subkeys.pgp.enc | $GPG_EXECUTABLE --import
- GPG_SIGN_CMD="$GPG_EXECUTABLE --batch --yes --detach-sign --armor --local-user $GPG_KEYID"
- |-
WHEEL_PATHS=(dist/*.whl dist/*.tar.gz)
WHEEL_PATHS_STR=$(printf '"%s" ' "${WHEEL_PATHS[@]}")
echo "$WHEEL_PATHS_STR"
for WHEEL_PATH in "${WHEEL_PATHS[@]}"
do
echo "------"
echo "WHEEL_PATH = $WHEEL_PATH"
$GPG_SIGN_CMD --output $WHEEL_PATH.asc $WHEEL_PATH
$GPG_EXECUTABLE --verify $WHEEL_PATH.asc $WHEEL_PATH || echo "hack, the first run of gpg very fails"
$GPG_EXECUTABLE --verify $WHEEL_PATH.asc $WHEEL_PATH
done
- ls dist
- python -m pip install opentimestamps-client
- ots stamp dist/*.tar.gz dist/*.whl dist/*.asc
needs:
- job: build/sdist
artifacts: true
- job: build/cp39-linux-x86_64
artifacts: true
- job: build/cp310-linux-x86_64
artifacts: true
- job: build/cp311-linux-x86_64
artifacts: true
- job: build/cp312-linux-x86_64
artifacts: true
- job: build/cp313-linux-x86_64
artifacts: true
deploy/wheels:
<<: *common_template
image: python:3.11
stage: deploy
only:
refs:
- release
script:
- pip install pyopenssl ndg-httpsclient pyasn1 requests[security] twine -U
- ls dist
- |-
WHEEL_PATHS=(dist/*.whl dist/*.tar.gz)
WHEEL_PATHS_STR=$(printf '"%s" ' "${WHEEL_PATHS[@]}")
source dev/secrets_configuration.sh
TWINE_PASSWORD=${!VARNAME_TWINE_PASSWORD}
TWINE_USERNAME=${!VARNAME_TWINE_USERNAME}
echo "$WHEEL_PATHS_STR"
for WHEEL_PATH in "${WHEEL_PATHS[@]}"
do
twine check $WHEEL_PATH.asc $WHEEL_PATH
twine upload --username $TWINE_USERNAME --password $TWINE_PASSWORD $WHEEL_PATH || echo "upload already exists"
done
- |-
# Have the server git-tag the release and push the tags
export PROJECT_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' | sed -e 's|git@||g' | sed -e 's|:|/|g')
source dev/secrets_configuration.sh
CI_SECRET=${!VARNAME_CI_SECRET}
PUSH_TOKEN=${!VARNAME_PUSH_TOKEN}
echo "URL_HOST = $URL_HOST"
# A git config user name and email is required. Set if needed.
if [[ "$(git config user.email)" == "" ]]; then
git config user.email "[email protected]"
git config user.name "Gitlab-CI"
fi
TAG_NAME="v${PROJECT_VERSION}"
echo "TAG_NAME = $TAG_NAME"
if [ $(git tag -l "$TAG_NAME") ]; then
echo "Tag already exists"
else
# if we messed up we can delete the tag
# git push origin :refs/tags/$TAG_NAME
# and then tag with -f
git tag $TAG_NAME -m "tarball tag $PROJECT_VERSION"
git push --tags "https://git-push-token:${PUSH_TOKEN}@${URL_HOST}"
fi
- |-
# https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
echo "CI_PROJECT_ID=$CI_PROJECT_ID"
echo "CI_PROJECT_NAME=$CI_PROJECT_NAME"
echo "CI_API_V4_URL=$CI_API_V4_URL"
export PROJECT_VERSION=$(python -c "import setup; print(setup.VERSION)")
echo "PROJECT_VERSION=$PROJECT_VERSION"
# If running on CI use CI authentication, otherwise
# assume we developer authentication available.
if [[ -z "$CI_JOB_TOKEN" ]]; then
AUTH_HEADER="PRIVATE-TOKEN: $PRIVATE_GITLAB_TOKEN"
else
AUTH_HEADER="JOB-TOKEN: $CI_JOB_TOKEN"
fi
# Loop over all of the assets in the wheelhouse (i.e. dist)
# and upload them to a package registry. We also store the
# links to the artifacts so we can attach them to a release
# page.
PACKAGE_ARTIFACT_ARRAY=()
for FPATH in "dist"/*; do
FNAME=$(basename $FPATH)
echo "Upload artifact: $FNAME"
PACKAGE_URL="$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/generic/$CI_PROJECT_NAME/$PROJECT_VERSION/$FNAME"
curl \
--header "$AUTH_HEADER" \
--upload-file $FPATH \
"$PACKAGE_URL"
PACKAGE_ARTIFACT_ARRAY+=("$PACKAGE_URL")
done
- |-
export PROJECT_VERSION=$(python -c "import setup; print(setup.VERSION)")
echo "PROJECT_VERSION=$PROJECT_VERSION"
TAG_NAME="v$PROJECT_VERSION"
# Construct the JSON for assets to attach to the release
RELEASE_ASSET_JSON_LINKS=()
for ASSET_URL in "${PACKAGE_ARTIFACT_ARRAY[@]}"; do
ASSET_FNAME=$(basename $ASSET_URL)
RELEASE_ASSET_JSON_LINKS+=("{\"name\": \"$ASSET_FNAME\", \"url\": \"$ASSET_URL\"},")
done
_ASSET_LINK_JSON="${RELEASE_ASSET_JSON_LINKS[@]}"
# remove the trailing comma
ASSET_LINK_JSON=${_ASSET_LINK_JSON::-1}
echo "ASSET_LINK_JSON=$ASSET_LINK_JSON"
# Build json describing the release
RELEASE_DATA_JSON="{
\"name\": \"Version $PROJECT_VERSION\",
\"description\": \"Automated release of $CI_PROJECT_NAME version $PROJECT_VERSION\",
\"tag_name\": \"$TAG_NAME\",
\"assets\": {\"links\": [$ASSET_LINK_JSON]}
}"
echo "$RELEASE_DATA_JSON"
# If running on CI use CI authentication, otherwise
# assume we developer authentication available.
if [[ -z "${CI_JOB_TOKEN}" ]]; then
AUTH_HEADER="PRIVATE-TOKEN: $PRIVATE_GITLAB_TOKEN"
else
AUTH_HEADER="JOB-TOKEN: $CI_JOB_TOKEN"
fi
curl \
--header 'Content-Type: application/json' \
--header "$AUTH_HEADER" \
--data "$RELEASE_DATA_JSON" \
--request POST \
"$CI_API_V4_URL/projects/$CI_PROJECT_ID/releases"
# end