-
Notifications
You must be signed in to change notification settings - Fork 3
/
.gitlab-ci.yml
225 lines (204 loc) · 4.83 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
variables:
NODE_IMAGE: node:14-alpine
NODE_E2E_IMAGE: circleci/node:14-buster-browsers
DEPLOY_IMAGE: docksal/ssh-agent:1.3
# To cache both npm modules and Cypress binary we use environment variables
# to point at the folders we can list as paths in "cache" job settings
YARN_CACHE_FOLDER: "$CI_PROJECT_DIR/cache/yarn"
CYPRESS_CACHE_FOLDER: "$CI_PROJECT_DIR/cache/cypress"
GIT_DEPTH: 10
stages:
- prepare
- test
- build
- deploy
# GitLab don't support bash syntax in the "variables" definitions,
# so we use a custom step to define all necessary environment variables
.defineVars: &defineVars |-
export VERSION="${CI_COMMIT_TAG:-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}}"
.installSentry: &installSentry |-
apk add curl
curl -sL https://sentry.io/get-cli/ | bash
.setupSSH: &setupSSH |-
mkdir ~/.ssh
echo -e "Host *\n StrictHostKeyChecking no\n" > ~/.ssh/config
eval $(ssh-agent -s)
echo "$SSH_DEPLOY_KEY" | tr -d '\r' | ssh-add -
###################
# Steps to extend #
###################
.yarnCache:
cache:
key: yarn-cache
paths:
- node_modules
- packages/*/node_modules
- tests-e2e/node_modules # Keep this node_modules because it's one of workspaces
policy: pull
#################
# Prepare stage #
#################
Yarn:
stage: prepare
image: $NODE_IMAGE
extends:
- .yarnCache
cache:
policy: pull-push
variables:
CYPRESS_INSTALL_BINARY: 0 # Don't install binary to increase caching performance between jobs
before_script:
- apk add git
script:
- yarn install --frozen-lockfile
#################
# Testing stage #
#################
Lint:
stage: test
image: $NODE_IMAGE
needs:
- Yarn
extends:
- .yarnCache
script:
- yarn lint:check
TypeScript:
stage: test
image: $NODE_IMAGE
needs:
- Yarn
extends:
- .yarnCache
script:
- yarn ts:check
Jest:
stage: test
image: $NODE_IMAGE
needs:
- Yarn
extends:
- .yarnCache
script:
- yarn test
Crowdin:
stage: test
image: $NODE_IMAGE
needs:
- Yarn
extends:
- .yarnCache
script:
- yarn i18n:extract
- yarn i18n:push
- yarn i18n:pull
artifacts:
name: "i18n for $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA"
paths:
- packages/app/i18n/*.json
- packages/app/i18n/index.js
expire_in: 1 week
###############
# Build stage #
###############
Build:
stage: build
image: $NODE_IMAGE
needs:
- Lint
- TypeScript
- Jest
- Crowdin
extends:
- .yarnCache
before_script:
- *defineVars
script:
- yarn build
# Remove unneeded files
- rm -rf build/*.css.map
# Move all source maps to its own directory
- mkdir -p source-maps
- cd build
- find . -name '*.js.map' | cpio -pdm ../source-maps/
- rm -rf *.js.map
- find . -name '*.js' | cpio -pdm ../source-maps/
- cd ..
# Cleanup source maps for unimportant bundles
- rm -f source-maps/runtime.js
- rm -f source-maps/intl-polyfills.js
- rm -rf source-maps/locale-*
artifacts:
name: "Production build for $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA"
paths:
- build
- source-maps
expire_in: 1 week
Storybook:
stage: build
image: $NODE_IMAGE
needs:
- Yarn
- Crowdin
extends:
- .yarnCache
script:
- yarn sb:build --quiet
artifacts:
name: "Storybook for $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA"
paths:
- storybook-static
expire_in: 1 day
################
# Deploy stage #
################
.deployJob:
stage: deploy
image: $DEPLOY_IMAGE
needs:
- Build
before_script:
- *defineVars
- *installSentry
- *setupSSH
- apk add rsync
script:
# Send release to the Sentry
- sentry-cli releases new $VERSION
- sentry-cli releases set-commits --commit "elyby/accounts-frontend@${CI_COMMIT_SHA}" $VERSION
- sentry-cli releases files $VERSION upload-sourcemaps source-maps
- rsync -v -a -r --delete-after -e "ssh -J [email protected]:4534 -p 722" build/ "root@${VM_HOST_NAME}:${VM_DEPLOY_PATH}"
# Finalize Sentry's release
- sentry-cli releases deploys $VERSION new -e $CI_ENVIRONMENT_NAME
- sentry-cli releases finalize $VERSION
Dev:
extends:
- .deployJob
environment:
name: Development
variables:
VM_HOST_NAME: playground.ely.local
VM_DEPLOY_PATH: /srv/dev.account.ely.by/frontend
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: on_success
- if: '$CI_COMMIT_MESSAGE =~ /\[deploy dev\]/'
when: on_success
# Default:
- when: never
Prod:
extends:
- .deployJob
stage: deploy
environment:
name: Production
variables:
VM_HOST_NAME: accounts.ely.local
VM_DEPLOY_PATH: /srv/frontend
rules:
- if: '$CI_COMMIT_BRANCH != "master"'
when: never
- if: '$CI_COMMIT_MESSAGE =~ /\[deploy\]/'
when: on_success
# Default:
- when: manual