-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
314 lines (284 loc) · 10.7 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
# CI Routine for the album framework.
#----------------------------
# templates
#----------------------------
# Windows base template
#
# Downloads conda executable in <current_working_directory>\downloads if executable not present.
# Installs conda in >current_working_directory>\miniconda if conda not already installed.
# Runs conda initialization and configuration.
#
# NOTE: Apparently there is no output for commands split over several lines...
.windows_base_template_micromamba:
before_script:
- 'echo "We are in path: $pwd "'
- 'if(-Not (Test-Path .\downloads)) {echo "Cache download not found! Creating..."; New-Item -ItemType Directory -Force -Path .\downloads} else { echo ".\downloads cache found! with content:"; Get-ChildItem -Path .\downloads}'
- 'if(-Not (Test-Path .\.album)) {echo "Cache .album not found! Creating..."; New-Item -ItemType Directory -Force -Path .\.album} else { echo ".\.album cache found! with content:"; Get-ChildItem -Path .\.album}'
- 'if(-Not (Test-Path .\micromamba)) {echo "Cache micromamba not found! Creating..."; New-Item -ItemType Directory -Force -Path .\micromamba} else { echo ".\micromamba cache found! with content:"; Get-ChildItem -Path .\micromamba}'
- '$7ZIP_EXE=(Join-Path $env:ProgramFiles -ChildPath 7-Zip\7z.exe)'
- '$7ZIP_INSTALLER=(Join-Path downloads -ChildPath 7z.exe)'
- '$Env:USERPROFILE=$pwd'
- '$oldProgressPreference = $progressPreference; $progressPreference = "SilentlyContinue";'
- '[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12' # set Security download protocol to avoid https errors
- 'if(-Not (Test-Path $7ZIP_EXE)) {if(-Not (Test-Path $7ZIP_INSTALLER)){Invoke-Webrequest -URI https://www.7-zip.org/a/7z2201-x64.exe -OutFile $7ZIP_INSTALLER}}'
- 'if(-Not (Test-Path $7ZIP_EXE)) {Start-Process -FilePath $7ZIP_INSTALLER -Args "/S" -Verb RunAs -Wait}'
- 'Invoke-Webrequest -URI https://micro.mamba.pm/api/micromamba/win-64/1.5.6 -OutFile micromamba.tar.bz2'
- '& $7ZIP_EXE x micromamba.tar.bz2 -aoa'
- '& $7ZIP_EXE x micromamba.tar -ttar -aoa -r Library\bin\micromamba.exe $("-o" + (Join-Path -Path (Get-Location) -ChildPath micromamba_installation))'
- '$progressPreference = $oldProgressPreference'
- '.\micromamba_installation\Library\bin\micromamba.exe create -y -n album album -c conda-forge python=3.10'
- '.\micromamba_installation\Library\bin\micromamba.exe run -n album pip uninstall -y album'
- '.\micromamba_installation\Library\bin\micromamba.exe run -n album pip install --no-cache-dir https://gitlab.com/album-app/album/-/archive/$env:CI_COMMIT_REF_NAME/album-$env:CI_COMMIT_REF_NAME.zip'
tags:
- windows
variables:
PIP_CACHE_DIR: $CI_PROJECT_DIR\.cache\pip
ErrorActionPreference: Continue # not working properly
cache:
key: one-key-to-rule-them-all-windows
paths:
- downloads
- .cache\pip
# Linux base template for running tests with micromamba as package manager
#
# Uses a docker image where micromamba will be installed.
# Creates a album environment.
#
.linux_base_template_micromamba:
image: ubuntu:latest
tags:
- docker
- linux
before_script:
- apt update
- apt install -y curl
- apt install -y bzip2
- mkdir -p $CI_PROJECT_DIR/bin/
- curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/1.5.6 | tar -xvj -C $CI_PROJECT_DIR/bin/ --strip-components=1 bin/micromamba
- $CI_PROJECT_DIR/bin/micromamba create -y -n album album -c conda-forge python=3.10
- $CI_PROJECT_DIR/bin/micromamba run -n album pip uninstall -y album
- $CI_PROJECT_DIR/bin/micromamba run -n album pip install --no-cache-dir https://gitlab.com/album-app/album/-/archive/$CI_COMMIT_REF_NAME/album-$CI_COMMIT_REF_NAME.zip
- $CI_PROJECT_DIR/bin/micromamba run -n album python -V
- $CI_PROJECT_DIR/bin/micromamba run -n album pip list
variables:
PIP_CACHE_DIR: $CI_PROJECT_DIR/.cache/pip
cache:
key: one-key-to-rule-them-all-linux
paths:
- $CI_PROJECT_DIR/.cache/pip
# Macos base template for running tests with micromamba as package manager
#
# Installs micromamba in a fresh tmp directory and activates it.
# DO NOT ALLOW JOBS TO BE RUN IN PARALLEL!
#
.macos_base_template_micromamba:
tags:
- macos
- shell
before_script:
- echo "$(uname)"
- sw_vers
- tmpdir=$(mktemp -d /tmp/album-test.XXXXXX)
- echo $tmpdir
- echo $tmpdir > /tmp/tmpdir
- mkdir -p $tmpdir/bin/
- curl -Ls https://micro.mamba.pm/api/micromamba/osx-64/1.5.6 | tar -xvj -C $tmpdir/bin/ --strip-components=1 bin/micromamba
- MICROMAMBA_EXECUTABLE=$tmpdir/bin/micromamba
- $MICROMAMBA_EXECUTABLE create -y -n album album -c conda-forge python=3.10
- $MICROMAMBA_EXECUTABLE run -n album pip uninstall -y album
- $MICROMAMBA_EXECUTABLE run -n album pip install --no-cache-dir https://gitlab.com/album-app/album/-/archive/$CI_COMMIT_REF_NAME/album-$CI_COMMIT_REF_NAME.zip
- $MICROMAMBA_EXECUTABLE run -n album python -V
- $MICROMAMBA_EXECUTABLE run -n album pip list
after_script:
- tmpdir=$(</tmp/tmpdir)
- echo $tmpdir
- rm -rf $tmpdir
variables:
MICROMAMBA_EXECUTABLE: ""
#----------------------------
# stages
#----------------------------
stages:
- build
- test
- release-test
- release
- deploy
- post-deploy
#----------------------------
# jobs
#----------------------------
rebuild_album_installer:
stage: post-deploy
trigger:
project: album-app/plugins/album-package
rules:
- if: $CI_COMMIT_TAG
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
changes:
- setup.cfg
prepare release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
tags:
- DeployRunner
- DeployDocker
script:
- echo "preparing release"
- VERSION=$(cat setup.cfg | grep "version=*" | awk '{split($0, s, " "); print s[3]}')
- TAG=v$VERSION
- echo "prepare to release version $VERSION with tag $TAG"
- echo "VERSION=$VERSION" >> variables.env
- echo "TAG=v$VERSION" >> variables.env
artifacts:
reports:
dotenv: variables.env
rules:
- if: $CI_COMMIT_TAG
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
changes:
- setup.cfg
gitlab release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
tags:
- DeployRunner
- DeployDocker
needs:
- job: prepare release
artifacts: true
script:
- echo "running release_job for version $VERSION and tag $TAG"
rules:
- if: $CI_COMMIT_TAG
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
changes:
- setup.cfg
release:
name: 'Release $TAG'
description: 'Created using the release-cli'
tag_name: '$TAG'
ref: '$CI_COMMIT_SHA'
gitlab pypi deploy:
image: python:latest
stage: deploy
tags:
- DeployRunner
- DeployDocker
needs:
- job: gitlab release
- job: prepare release
artifacts: true
script:
- echo "deploying gitlab pypi version $VERSION"
- pip install twine
- python setup.py sdist bdist_wheel
- TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
rules:
- if: $CI_COMMIT_TAG
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
changes:
- setup.cfg
pypi deploy:
image: python:latest
stage: deploy
tags:
- DeployRunner
- DeployDocker
needs:
- job: gitlab release
- job: prepare release
artifacts: true
before_script:
- echo "deploying pypi version $VERSION"
- echo "using pypi deploy user $PYPI_DEPLOY_USER"
script:
- pip install twine
- python setup.py sdist bdist_wheel
- TWINE_PASSWORD=$PYPI_DEPLOY_TOKEN TWINE_USERNAME=$PYPI_DEPLOY_USER python -m twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
rules:
- if: $CI_COMMIT_TAG
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
changes:
- setup.cfg
docker deploy:
stage: deploy
tags:
- DeployRunner
- DeployShell
needs:
- job: gitlab release
- job: prepare release
artifacts: true
- job: pypi deploy
before_script:
- docker info
script:
- echo "deploying docker version $VERSION"
- docker login -u "$DOCKER_DEPLOY_USER" -p "$DOCKER_DEPLOY_TOKEN" docker.io
# building deploy tag
- tag=$(echo $DOCKER_DEPLOY_USER/album:$VERSION)
- echo "Building image with tag $tag"
- docker build -t $tag .
- docker push $tag
rules:
- if: $CI_COMMIT_TAG
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
changes:
- setup.cfg
# Linux Tests
cmdline linux:
extends: .linux_base_template_micromamba
stage: build
script:
- eval "$($CI_PROJECT_DIR/bin/micromamba shell hook -s posix)"
- micromamba activate album
# album commands
- album -h
- album run -h
- album install -h
- album deploy -h
- album uninstall -h
- album repl -h
- album add-catalog -h
- album remove-catalog -h
# album catalog admin
- album-catalog-admin -h
unit tests linux micromamba:
extends: .linux_base_template_micromamba
stage: test
script:
- $CI_PROJECT_DIR/bin/micromamba run -n album python -m unittest test/unit/run_all_unit_micromamba.py
integration tests linux micromamba:
extends: .linux_base_template_micromamba
stage: test
script:
- $CI_PROJECT_DIR/bin/micromamba run -n album python -m unittest test/integration/run_all_integration_micromamba.py
# MacOs Tests
unit tests macos micromamba:
extends: .macos_base_template_micromamba
stage: test
script:
- $MICROMAMBA_EXECUTABLE run -n album python -m unittest test/unit/run_all_unit_micromamba.py
integration tests macos micromamba:
extends: .macos_base_template_micromamba
stage: test
script:
- $MICROMAMBA_EXECUTABLE run -n album python -m unittest test/integration/run_all_integration_micromamba.py
# Windows Tests
unit tests windows micromamba:
extends: .windows_base_template_micromamba
stage: test
script:
- .\micromamba_installation\Library\bin\micromamba.exe run -n album python -m unittest .\test\unit\run_all_unit_micromamba.py
integration tests windows micromamba:
extends: .windows_base_template_micromamba
stage: test
script:
- .\micromamba_installation\Library\bin\micromamba.exe run -n album python -m unittest .\test\integration\run_all_integration_micromamba.py