-
Notifications
You must be signed in to change notification settings - Fork 8
/
.gitlab-ci.yml
247 lines (194 loc) · 5.17 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
stages:
- update_version
- build
- test
- package
- release
- deploy
variables:
NODE_IMAGE: node:16-alpine
PNPM_STORE_DIR: .pnpm-store
PACKAGE_NAME: frontend
PACKAGE_VERSION: $CI_COMMIT_REF_NAME
PACKAGE_FILE: ${PACKAGE_NAME}.tar.gz
PACKAGE_REGISTRY_URL: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${PACKAGE_NAME}/${PACKAGE_VERSION}/${PACKAGE_FILE}
include:
- project: wabbitproject/platform/apps-deployment/mngt-apps/inbox-frontend
file: upstream/jobs.yaml
rules:
- if: $G_TRIGGER_DEPLOY == "true"
.cache_config: &cache_config
key:
files:
# compute our cache key from the lock file (`pnpm-lock.yaml`)
- pnpm-lock.yaml
paths:
# cache the `pnpm`'s content-addressable store between our CI/CD pipeline
# runs, to optimize execution time
- $PNPM_STORE_DIR
.install_pnpm: &install_pnpm
before_script:
- npm install --location=global --no-fund pnpm
- pnpm config set store-dir $PNPM_STORE_DIR
Update project version on git tag:
stage: update_version
image: $NODE_IMAGE
only:
- tags
<<: *install_pnpm
script:
- pnpm version --no-git-tag-version ${PACKAGE_VERSION}
artifacts:
name: version
paths:
- package.json
Build:
stage: build
image: $NODE_IMAGE
only:
- master
- merge_requests
- tags
cache:
<<: *cache_config
<<: *install_pnpm
script:
- apk add --no-cache --upgrade bash
- chmod +x ./setup_env.sh
- ./setup_env.sh
- pnpm install --prefer-offline
# HACK: Using `CI=false` as a temporary workaround to ignore compilation
# warnings, as they're breaking our GitLab CI/CD pipeline
#
# For details, please see:
# https://gitlab.com/wabbitproject/web-app/-/issues/156
- CI=false pnpm build
# track our built frontend files in GitLab's MR widget/ui
artifacts:
name: frontend
expose_as: Built frontend files
paths:
- build/
Lint:
stage: test
image: $NODE_IMAGE
cache:
<<: *cache_config
# download the cache when this job starts, but don't upload it when this job
# finishes - as the 'Build' job has already (re)generated the cache for us,
# as needed
policy: pull
only:
- master
- merge_requests
- tags
dependencies:
- Update project version on git tag
<<: *install_pnpm
script:
- pnpm install --prefer-offline
- pnpm lint:prettier
Test:
stage: test
image: $NODE_IMAGE
cache:
<<: *cache_config
# download the cache when this job starts, but don't upload it when this job
# finishes - as the 'Build' job has already (re)generated the cache for us,
# as needed
policy: pull
only:
- master
- merge_requests
- tags
dependencies:
- Update project version on git tag
<<: *install_pnpm
script:
- pnpm install --prefer-offline
- pnpm test --
--passWithNoTests
--coverage --coverageReporters=text --coverageReporters=cobertura --coverageReporters=html
# track our test coverage in GitLab's MR widget/ui
coverage: '/All files.*\|\s+(\d+(?:\.\d+)?)/'
# track our test coverage in GitLab's CI pipeline test reports
artifacts:
expose_as: Coverage HTML report
paths:
- coverage/
reports:
coverage_report:
coverage_format: cobertura
path: coverage/cobertura-coverage.xml
#Security audit:
# stage: test
# image: $NODE_IMAGE
#
# only:
# - master
# - merge_requests
# - tags
#
# dependencies:
# - Update project version on git tag
#
# <<: *install_pnpm
# script:
# - pnpm audit --audit-level=critical
Publish package on git tag:
stage: package
only:
- tags
dependencies:
- Build
script:
- tar -czvf ${PACKAGE_FILE} -C build .
- >
curl
--fail
--header "JOB-TOKEN: ${CI_JOB_TOKEN}"
--upload-file ${PACKAGE_FILE}
${PACKAGE_REGISTRY_URL}
Publish docker image:
stage: package
image: docker:20.10
only:
- tags
dependencies:
- Build
services:
- docker:20.10-dind
variables:
# G_* variables must be defined in project CI/CD settings
DOCKER_IMAGE_TAG: "${G_DOCKER_IMAGE_NAME}:${CI_COMMIT_TAG}"
DOCKER_REGISTRY_URL: "${G_DOCKER_REGISTRY_URL}"
DOCKER_REGISTRY_USER: "${G_DOCKER_REGISTRY_USER}"
DOCKER_REGISTRY_PASS: "${G_DOCKER_REGISTRY_PASS}"
DOCKER_TLS_CERTDIR: "/certs"
before_script:
- echo "${DOCKER_REGISTRY_PASS}" | docker login -u "${DOCKER_REGISTRY_USER}" --password-stdin "${DOCKER_REGISTRY_URL}"
script:
- docker build -f docker/Dockerfile.prebuild -t "${DOCKER_IMAGE_TAG}" .
- docker push "${DOCKER_IMAGE_TAG}"
after_script:
- docker logout
Create release on git tag:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli
only:
- tags
dependencies: []
# HACK: All release jobs, except trigger jobs, must include the `script` keyword.
#
# For details, please see:
# https://docs.gitlab.com/ee/ci/yaml/#release
script:
- echo "Running the release job..."
release:
tag_name: $PACKAGE_VERSION
description: Release automatically created by ${CI_PIPELINE_URL}
assets:
links:
- name: $PACKAGE_FILE
url: $PACKAGE_REGISTRY_URL
link_type: package