-
Notifications
You must be signed in to change notification settings - Fork 22
/
.gitlab-ci.yml
217 lines (189 loc) · 5.41 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
# Note: This GitLab CI configuration is used for internal testing, users can ignore it.
include:
- project: '${CI_PROJECT_NAMESPACE}/ci-libs-for-client-libraries'
file:
- '/${CI_PROJECT_NAME}/.gitlab-ci.yml'
- project: 'deepl/ops/ci-cd-infrastructure/gitlab-ci-lib'
file:
- '/templates/.secret-detection.yml'
# Global --------------------------
# Use Active LTS (18)
image: node:18-alpine
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_TAG
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
cache:
key:
files:
- package.json
- package-lock.lock
paths:
- node_modules/
stages:
- check
- build
- test
- publish
before_script:
- npm install
# stage: check ----------------------
.eslint_base:
stage: check
script:
- npm run lint
eslint_scheduled:
extends: .eslint_base
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
retry: 2
eslint_manual:
extends: .eslint_base
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
.audit_base:
stage: check
script:
- npm audit --production
# Suppressing NPM audit failures on dev dependencies due to CVE-2022-25883
# in semver <7.5.2, used by test dependencies.
# See: https://github.com/npm/node-semver/pull/564
# Currently npm audit fix cannot resolve this issue.
- npm audit || echo "Suppressing npm audit failures for dev dependencies"
audit_scheduled:
extends: .audit_base
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
retry: 2
audit_manual:
extends: .audit_base
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
.format_base:
stage: check
script:
- npm run format
format_scheduled:
extends: .format_base
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
retry: 2
format_manual:
extends: .format_base
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
secret_detection:
extends: .secret-detection
stage: check
image: !reference [.secret-detection, image]
before_script:
- echo "overriding default before_script..."
rules:
- if: $CI_MERGE_REQUEST_ID
# stage: build ----------------------
build:
stage: build
script:
- npm run clean
- npm run build
artifacts:
paths:
- dist
# stage: test ----------------------
.test_base:
stage: test
extends: .test
retry: 1
variables:
KUBERNETES_MEMORY_LIMIT: 8Gi
parallel:
matrix:
- DOCKER_IMAGE: 'node:18-alpine'
- DOCKER_IMAGE: 'node:12-alpine'
USE_MOCK_SERVER: 'use mock server'
- DOCKER_IMAGE: 'node:14-alpine'
USE_MOCK_SERVER: 'use mock server'
- DOCKER_IMAGE: 'node:16-alpine'
USE_MOCK_SERVER: 'use mock server'
- DOCKER_IMAGE: 'node:17-alpine'
USE_MOCK_SERVER: 'use mock server'
- DOCKER_IMAGE: 'node:18-alpine'
USE_MOCK_SERVER: 'use mock server'
image: ${DOCKER_IMAGE}
script:
- >
if [[ ! -z "${USE_MOCK_SERVER}" ]]; then
echo "Using mock server"
export DEEPL_SERVER_URL=http://deepl-mock:3000
export DEEPL_MOCK_SERVER_PORT=3000
export DEEPL_PROXY_URL=http://deepl-mock:3001
export DEEPL_MOCK_PROXY_SERVER_PORT=3001
fi
- npm run test:coverage
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage/clover.xml
junit:
- junit.xml
when: always
test_scheduled:
extends: .test_base
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
retry: 2
test_manual:
extends: .test_base
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
.examples_base:
stage: test
extends: .test
parallel:
matrix:
- DOCKER_IMAGE: 'node:12-alpine'
- DOCKER_IMAGE: 'node:14-alpine'
- DOCKER_IMAGE: 'node:16-alpine'
- DOCKER_IMAGE: 'node:17-alpine'
- DOCKER_IMAGE: 'node:18-alpine'
image: ${DOCKER_IMAGE}
before_script: # Note: replaces global before_script
- npm install --production
script:
- export DEEPL_AUTH_KEY=mock-auth-key
- export DEEPL_SERVER_URL=http://deepl-mock:3000
- export DEEPL_MOCK_SERVER_PORT=3000
- export DEEPL_PROXY_URL=http://deepl-mock:3001
- export DEEPL_MOCK_PROXY_SERVER_PORT=3001
- cd $CI_PROJECT_DIR/examples/commonjs
- npm install
- node index.js
- cd $CI_PROJECT_DIR/examples/esmodule
- npm install
- node index.js
- cd $CI_PROJECT_DIR/examples/typescript
- npm install
- npm run build
- node index.js
examples_scheduled:
extends: .examples_base
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
retry: 2
examples_manual:
extends: .examples_base
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
# stage: publish ----------------------
publish to NPM:
stage: publish
extends: .publish
dependencies:
- build
rules:
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
script:
- npm config set //registry.npmjs.org/:_authToken ${NPM_PUBLISH_TOKEN}
- npm publish