-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
357 lines (333 loc) · 12 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
variables:
GIT_SUBMODULE_STRATEGY: recursive
LIGO_REGISTRY_IMAGE_BASE_NAME: "${CI_PROJECT_PATH}/${CI_PROJECT_NAME}"
WEBIDE_IMAGE_TAG: "registry.gitlab.com/${CI_PROJECT_PATH}/ligo_webide:${CI_COMMIT_SHORT_SHA}"
LIGO_IMAGE_TAG: "ligo:${CI_COMMIT_SHORT_SHA}-${CI_PIPELINE_ID}"
stages:
- pretooling # changelog
- docker-build # build, test, produces binaries/.deb/doc within docker
- docker-extract # extract what have been built and expose them as artifact
- tooling # build miscellaneous tooling-related things (website, changelog..)
- push # deploy docker images, pages, releases (tag)
- ide-deploy # deploy web IDE
- ide-feature-container-removal # remove feature branch containers of the webide
# jobs for building and testing LSP
include: '/tools/lsp/.gitlab-ci.yml'
.nix:
before_script:
- find "$CI_PROJECT_DIR" -path "$CI_PROJECT_DIR/.git" -prune -o "(" -type d -a -not -perm -u=w ")" -exec chmod --verbose u+w {} ";"
- export COMMIT_DATE="$(git show --no-patch --format=%ci)"
changelog:
stage: pretooling
extends : .nix
only:
- merge_requests
- dev
- /^.*-run-dev$/
- /[0-9]+\.[0-9]+\.[0-9]+/
script:
- nix-build nix -A ligo-changelog
- cp -L result/* .
artifacts:
paths:
- changelog.md
- changelog.txt
- release-notes.md
- release-notes.txt
to_dos:
stage: pretooling
only:
- merge_requests
- /^.*-run-dev$/
script:
- ./scripts/list-to-dos.sh > to-dos.html
artifacts:
paths:
- to-dos.html
# TODO: https://docs.gitlab.com/ee/ci/yaml/#onlychangesexceptchanges ?
docker_build:
stage: docker-build
dependencies:
- changelog
only:
- merge_requests
- dev
- /^.*-run-dev$/
- /[0-9]+\.[0-9]+\.[0-9]+/
script:
- docker build .
--build-arg=ci_commit_tag=$CI_COMMIT_TAG
--build-arg=ci_commit_sha=$CI_COMMIT_SHA
--build-arg=ci_commit_timestamp=$CI_COMMIT_TIMESTAMP
--build-arg=changelog_path=changelog.txt
-t ${LIGO_IMAGE_TAG}
- docker save -o ligo.tar.gz ${LIGO_IMAGE_TAG}
after_script:
- docker image rm "${LIGO_IMAGE_TAG}" >/dev/null 2>&1 || true
artifacts:
expose_as: "Ligo docker image - light -"
paths:
- ligo.tar.gz
docker_extract:
stage: docker-extract
only:
- merge_requests
- dev
- /^.*-run-dev$/
- /[0-9]+\.[0-9]+\.[0-9]+/
extends: .nix
dependencies :
- docker_build
script:
- docker load -i ligo.tar.gz
- docker cp $(docker create ${LIGO_IMAGE_TAG}):/root/ligo .
- chmod +rwx ligo
# Check that the binary is truly static and has 0 dependencies
- ldd ligo | grep 'statically' # TODO: there is maybe a better way to do that ?
- docker cp $(docker create ${LIGO_IMAGE_TAG}):/root/coverage .
- cat coverage/coverage-summary
- docker cp -La $(docker create ${LIGO_IMAGE_TAG}):/root/doc .
- nix-build nix -A ligo-deb
- cp -L result/ligo.deb .
after_script:
- docker image rm "${LIGO_IMAGE_TAG}" >/dev/null 2>&1 || true
artifacts:
paths:
- ligo
- ligo.deb
- coverage
- doc
xrefcheck:
stage: tooling
only:
- merge_requests
script:
# Should be replaced with
# nix run github:serokell/xrefcheck
# Once flakes roll out to stable
# - nix run -f https://github.com/serokell/xrefcheck/archive/v0.1.1.2.tar.gz -c 'xrefcheck local-only'
- curl -L https://github.com/serokell/xrefcheck/releases/download/v0.1.1/release.tar.gz | tar -zxf - xrefcheck/bin/xrefcheck
- xrefcheck/bin/xrefcheck
allow_failure: true #TODO could be better if we do not allow failure for realeases
# Strange race conditions, disable for now
.webide-e2e:
stage: tooling
extends: .nix
only:
# Disabled for now unless the branch name contains webide, because a test in this job fails randomly
- /.*webide.*/
#- merge_requests
#- dev
#- /^.*-run-dev$/
script:
- nix-build nix -A ligo-editor.e2e
docker:
stage: tooling
dependencies:
- docker_build
only:
- merge_requests
- dev
- /^.*-run-dev$/
- /[0-9]+\.[0-9]+\.[0-9]+/
script:
- ':'
artifacts:
paths:
- ligo.tar.gz
webide-docker:
extends: .nix
stage: tooling
dependencies:
- docker_extract
only:
- merge_requests
- dev
- /^.*-run-dev$/
script:
- nix-build nix -A ligo-editor-docker
- cp -L result webide.tar.gz
artifacts:
paths:
- webide.tar.gz
.docker-image:
stage: push
image: docker:19.03.5
services:
- docker:19.03.5-dind
docker-push:
stage: push
extends: .docker-image
dependencies:
- docker_build
needs:
- docker_build
only:
- dev
- /^.*-run-dev$/
- /[0-9]+\.[0-9]+\.[0-9]+/
script:
- echo ${LIGO_REGISTRY_PASSWORD} | docker login -u ${LIGO_REGISTRY_USER} --password-stdin
- docker load -i=./ligo.tar.gz
- if test "$CI_COMMIT_REF_NAME" = "dev"; then export LIGO_TAG=next; else if echo "$CI_COMMIT_TAG" | grep -E "[0-9]+\.[0-9]+\.[0-9]+"; then export LIGO_TAG="$CI_COMMIT_TAG"; else export LIGO_TAG=next-attempt; fi; fi
- export LIGO_REGISTRY_FULL_NAME="${LIGO_REGISTRY_IMAGE_BUILD:-ligolang/ligo}:$LIGO_TAG"
- docker tag "${LIGO_IMAGE_TAG}" "${LIGO_REGISTRY_FULL_NAME}"
- docker push "${LIGO_REGISTRY_FULL_NAME}"
after_script:
- docker image rm "${LIGO_IMAGE_TAG}" >/dev/null 2>&1 || true
# docker-large-push: ?
# extends: docker-push
# dependencies:
# - docker-large
# needs:
# - docker-large
# script:
# - echo "${LIGO_REGISTRY_PASSWORD}" | docker login -u "${LIGO_REGISTRY_USER}" --password-stdin
# - docker load -i=./ligo.tar.gz
# - if test "$CI_COMMIT_REF_NAME" = "dev"; then export LIGO_TAG=next-large; else if echo "$CI_COMMIT_TAG" | grep -E "[0-9]+\.[0-9]+\.[0-9]+"; then export LIGO_TAG="$CI_COMMIT_TAG-large"; else export LIGO_TAG=next-attempt-large; fi; fi
# - export LIGO_REGISTRY_FULL_NAME="${LIGO_REGISTRY_IMAGE_BUILD:-ligolang/ligo}:$LIGO_TAG"
# - docker tag ligo "${LIGO_REGISTRY_FULL_NAME}"
# - docker push "${LIGO_REGISTRY_FULL_NAME}"
webide-push:
extends: .docker-image
stage: push
dependencies:
- webide-docker
needs:
- webide-docker
rules:
# Only deploy docker when from the dev branch or a merge request AND on the canonical ligolang/ligo repository
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_PROJECT_PATH == "ligolang/ligo"'
changes:
- tools/webide/**/*
when: always
- if: '$CI_COMMIT_REF_NAME == "dev" && $CI_PROJECT_PATH == "ligolang/ligo"'
when: always
script:
- echo "${CI_BUILD_TOKEN}" | docker login -u gitlab-ci-token --password-stdin registry.gitlab.com
- docker load -i=./webide.tar.gz
- docker tag ligo-editor "${WEBIDE_IMAGE_TAG}"
- docker push "${WEBIDE_IMAGE_TAG}"
after_script:
- docker image rm "${WEBIDE_IMAGE_TAG}" >/dev/null 2>&1 || true
release:
stage: push
image: registry.gitlab.com/gitlab-org/release-cli
rules:
- if: '$CI_COMMIT_TAG =~ /[0-9]+\.[0-9]+\.[0-9]+/'
when: always
dependencies:
- docker_extract
- changelog
## FIXME find a better solution to upload the binary
artifacts:
expire_in: 1000 yrs
paths:
- ligo
- ligo.deb
script:
- release-cli create --name "Release $CI_COMMIT_TAG" --description "$(cat release-notes.md)" --assets-links-name "Static Linux binary" --assets-links-url "$CI_PROJECT_URL/-/jobs/$CI_JOB_ID/artifacts/raw/ligo" --assets-links-name "deb package" --assets-links-url "$CI_PROJECT_URL/-/jobs/$CI_JOB_ID/artifacts/raw/ligo.deb"
.website:
stage: push
extends: .nix
dependencies:
- docker_extract
- to_dos
script:
- nix-build nix -A ligo-website
- cp -Lr --no-preserve=mode,ownership,timestamps result/ public
- touch to-dos.html; cp to-dos.html public/to-dos.html
artifacts:
paths:
- public
pages:
extends: .website
rules:
- if: '$CI_COMMIT_REF_NAME == "dev" && $CI_PROJECT_PATH == "ligolang/ligo"'
when: always
- if: '$CI_COMMIT_TAG =~ /[0-9]+\.[0-9]+\.[0-9]+/'
when: always
pages-attempt:
extends: .website
only:
- merge_requests
- /^.*-run-dev$/
# This job will deploy the web-ide docker container to the test server.
deploy-handoff-feature:
# Handoff deployment duties to private repo.
stage: ide-deploy
variables:
IDE_DOCKER_IMAGE: "registry.gitlab.com/${CI_PROJECT_PATH}/ligo_webide"
LIGO_COMMIT_REF_NAME: "${CI_COMMIT_SHORT_SHA}"
LIGO_CI_MERGE_REQUEST_IID: "${CI_MERGE_REQUEST_IID}"
trigger:
project: ligolang/ligo-webide-deploy
rules:
# Only deploy handoff when from an MR AND on the canonical ligolang/ligo repository.
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_PROJECT_PATH == "ligolang/ligo"'
changes:
- tools/webide/**/*
when: always
deploy-handoff:
# Handoff deployment duties to private repo
stage: ide-deploy
variables:
IDE_DOCKER_IMAGE: "registry.gitlab.com/${CI_PROJECT_PATH}/ligo_webide"
LIGO_COMMIT_REF_NAME: "${CI_COMMIT_SHORT_SHA}"
trigger:
project: ligolang/ligo-webide-deploy
rules:
# Only deploy handoff when from the dev branch AND on the canonical ligolang/ligo repository
- if: '$CI_COMMIT_REF_NAME == "dev" && $CI_PROJECT_PATH == "ligolang/ligo"'
when: always
# This job builds the ligo-webide front-end from the tools/webide/ directory and deploys it as a Branch Deploy to Netlify using the netlify-cli tool.
# After the deployment is done a comment is posted to the MR with the draft site URL as well as the Netlify logs
build-preview-ligo-webide-front-end:
stage: ide-deploy
image: node:12.20.0-buster
tags:
- docker
script:
- apt-get update
- apt-get install -y --no-install-recommends jq
- cd ./tools/webide/
- sed -i "s/temphost/$CI_MERGE_REQUEST_IID-$CI_COMMIT_SHORT_SHA/g" ./packages/client/feature-netlify.toml
- cat ./packages/client/feature-netlify.toml
- mv ./packages/client/feature-netlify.toml ./packages/client/netlify.toml
- yarn install
- CI= yarn workspaces run build
- cd ./packages/client
- npm install netlify-cli
- npx netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --json --alias="$CI_MERGE_REQUEST_IID-$CI_COMMIT_SHORT_SHA" > netlify.json
- export NETLIFY_DEPLOY_URL=$(jq -r .deploy_url netlify.json)
- export NETLIFY_DEPLOY_LOGS=$(jq -r .logs netlify.json)
- echo "The URL for this deployment is $NETLIFY_DEPLOY_URL"
- echo "Logs for this deployment can be found at $NETLIFY_DEPLOY_LOGS"
- '[ ! -z "$CI_MERGE_REQUEST_IID" ] && curl POST https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/notes -d "{\"body\": \"A new deploy preview is available on Netlify at $NETLIFY_DEPLOY_URL, you can view the logs at $NETLIFY_DEPLOY_LOGS\"}" --header "Content-Type: application/json" --header "Private-Token: $GITLAB_PERSONAL_API_PRIVATE_TOKEN"'
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
changes:
- tools/webide/**/*
when: always
# This job will remove the web-ide docker containers that contain the MR_IID in their name from the test server.
downstream-webide-removal-handoff:
# Handoff deployment duties to private repo
stage: ide-feature-container-removal
variables:
IDE_DOCKER_IMAGE: "registry.gitlab.com/${CI_PROJECT_PATH}/ligo_webide"
LIGO_COMMIT_REF_NAME: "${CI_COMMIT_SHORT_SHA}"
LIGO_CI_MERGE_REQUEST_IID: "${CI_MERGE_REQUEST_IID}"
CLEAN_DOWNSTREAM: "true"
trigger:
project: ligolang/ligo-webide-deploy
rules:
# When there is a merge request there will be a manual job to remove feature branch containers
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_PROJECT_PATH == "ligolang/ligo"'
changes:
- tools/webide/**/*
when: manual
# After a MR merges and is committed to the default branch, the removal job will be triggered
- if: '$CI_COMMIT_REF_NAME == "dev" && $CI_PROJECT_PATH == "ligolang/ligo" && $CI_MERGE_REQUEST_IID != null'
changes:
- tools/webide/**/*
when: always