-
Notifications
You must be signed in to change notification settings - Fork 22
405 lines (351 loc) · 16.4 KB
/
ci-test.yaml
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
name: Build and Run Tests
on:
push:
branches:
- CV2-5261-run-similarity-tests
# pull_request:
# branches:
# - Epic-4798/migraton-of-check-web-ci
env:
GITHUB_BRANCH: ${{ github.head_ref || github.ref_name }}
GITHUB_JOB_NAME: ${{ github.job }}
GITHUB_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
AWS_ENDPOINT: ${{ secrets.AWS_ENDPOINT }}
AWS_REGION: eu-west-1
jobs:
similarity-tests:
runs-on: ubuntu-latest
if: >
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/master' ||
contains(github.event.head_commit.message, '[full ci]') ||
contains(github.event.head_commit.message, '[similarity tests]')
steps:
- name: free disk space
run: |
sudo apt clean
docker rmi $(docker image ls -aq)
df -h
- uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: eu-west-1
IMGUR_CLIENT_ID: ${{ secrets.IMGUR_CLIENT_ID }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Decrypt credentials for Alegre
env:
DECRYPTION_PASSWORD: ${{ secrets.DECRYPTION_PASSWORD }}
run: |
openssl enc -aes-256-cbc -d -in test/google_credentials.json.enc -out test/google_credentials.json -k $DECRYPTION_PASSWORD
- name: Setup UTF-8 Capable locale
run: |
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
export LANGUAGE=C.UTF-8
- name: Ngrok
run: |
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list && sudo apt update && sudo apt install ngrok
export GITHUB_TAG=0.0.0
- name: Setup Pender
run: |
export PENDER_BRANCH=$((git ls-remote --exit-code --heads https://github.com/meedan/pender.git $GITHUB_BRANCH >/dev/null && echo $GIT_BRANCH) || echo 'develop')
echo "Using branch $PENDER_BRANCH for Pender"
git clone --branch=$PENDER_BRANCH https://github.com/meedan/pender.git
cd pender
cp config/config.yml.example config/config.yml
cp config/database.yml.example config/database.yml
cp config/sidekiq.yml.example config/sidekiq.yml
cd -
- name: Setup Check API
run: |
export CHECK_API_BRANCH=$((git ls-remote --exit-code --heads https://github.com/meedan/check-api.git $GITHUB_BRANCH >/dev/null && echo $GITHUB_BRANCH) || echo 'develop')
echo "Using branch $CHECK_API_BRANCH for Check API"
git clone --branch=$CHECK_API_BRANCH https://github.com/meedan/check-api.git
cd check-api
cp config/config.yml.example config/config.yml
cp config/database.yml.example config/database.yml
cp config/sidekiq.yml.example config/sidekiq.yml
cd -
- name: Setup Alegre
run: |
export ALEGRE_BRANCH=$((git ls-remote --exit-code --heads https://github.com/meedan/alegre.git $GITHUB_BRANCH >/dev/null && echo $GITHUB_BRANCH) || echo 'develop')
echo "Using branch $ALEGRE_BRANCH for Alegre"
git clone --branch=$ALEGRE_BRANCH https://github.com/meedan/alegre.git
cd alegre
cp .env_file.test .env_file
cp ../test/google_credentials.json google_credentials.json
cd -
- name: Setup Presto
run: |
export PRESTO_BRANCH=$((git ls-remote --exit-code --heads https://github.com/meedan/presto.git $GITHUB_BRANCH >/dev/null && echo $GITHUB_BRANCH) || echo 'master')
echo "Using branch $PRESTO_BRANCH for Presto"
git clone --branch=$PRESTO_BRANCH https://github.com/meedan/presto.git
cd presto
cp .env_file.test .env_file
cp ../test/google_credentials.json google_credentials.json
cd -
- name: Setup Configuration Files
run: |
cp config.js.example config.js
cp config.js.example test/config.js
cp config-build.js.example config-build.js
cp config-server.js.example config-server.js
cp test/config.yml.example test/config.yml
- name: Before Script
env:
MAX_WEB_CURL: 3000
WEB_CURL_COUNT: 0
NGROK_AUTH: ${{ secrets.NGROK_AUTH }}
run: |
GITHUB_JOB_NAME=$GITHUB_JOB_NAME GITHUB_BRANCH=$GITHUB_BRANCH ./build.sh
MAX_WEB_CURL=$MAX_WEB_CURL;
WEB_CURL_COUNT=$WEB_CURL_COUNT; until curl --silent -I -f --fail http://localhost:3333 || (("$WEB_CURL_COUNT" == "$MAX_WEB_CURL")); do printf .; sleep 1; WEB_CURL_COUNT=$((++WEB_CURL_COUNT)); done; if [ "$WEB_CURL_COUNT" == "$MAX_WEB_CURL" ]; then echo "Terminating job after $WEB_CURL_COUNT curl attempts to check-web"; exit 1; fi
docker ps
- name: Run linter
run: |
docker compose exec web npm run linter
docker compose exec web npm run test:integration:lint
- name: Run Similarity test
env:
IMGUR_CLIENT_ID: ${{ secrets.IMGUR_CLIENT_ID }}
run: |
docker ps
docker compose exec web bash service nginx start
docker compose -f docker-compose.yml -f docker-test.yml exec chromedriver service nginx start
docker compose exec -T \
-e IMGUR_CLIENT_ID=$IMGUR_CLIENT_ID \
-e GITHUB_JOB_NAME=$GITHUB_JOB_NAME \
-e GITHUB_BRANCH=$GITHUB_BRANCH \
-e AWS_ENDPOINT=${{ secrets.AWS_ENDPOINT }} \
-e AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} \
-e AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} \
-e ROLE_TO_ASSUME=${{ secrets.AWS_ROLE_TO_ASSUME }} \
-e AWS_REGION=eu-west-1 \
-e TEST_RETRY_COUNT=3 \
web npm run tests
- name: After similarity tests
run: |
docker compose exec web bash -c "python -m json.tool test/file.json"
size=$(du -k build/web/js/index.bundle.js | cut -f1) && size2=$(du -k build/web/js/vendor.bundle.js | cut -f1) && totalsize=$((size+size2)) && echo "Your bundle size is $totalsize kb"
kill -9 $(pgrep ngrok)
integration-and-unit-tests:
runs-on: ubuntu-latest
if: >
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/master' ||
contains(github.event.head_commit.message, '[full ci]') ||
contains(github.event.head_commit.message, '[smoke tests]')
steps:
- uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: eu-west-1
IMGUR_CLIENT_ID: ${{ secrets.IMGUR_CLIENT_ID }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Decrypt credentials for Alegre
env:
DECRYPTION_PASSWORD: ${{ secrets.DECRYPTION_PASSWORD }}
run: |
openssl enc -aes-256-cbc -d -in test/google_credentials.json.enc -out test/google_credentials.json -k $DECRYPTION_PASSWORD
- name: Setup UTF-8 Capable locale
run: |
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
export LANGUAGE=C.UTF-8
- name: Setup Pender
run: |
export PENDER_BRANCH=$((git ls-remote --exit-code --heads https://github.com/meedan/pender.git $GITHUB_BRANCH >/dev/null && echo $GIT_BRANCH) || echo 'develop')
echo "Using branch $PENDER_BRANCH for Pender"
git clone --branch=$PENDER_BRANCH https://github.com/meedan/pender.git
cd pender
cp config/config.yml.example config/config.yml
cp config/database.yml.example config/database.yml
cp config/sidekiq.yml.example config/sidekiq.yml
cd -
- name: Setup Check API
run: |
export CHECK_API_BRANCH=$((git ls-remote --exit-code --heads https://github.com/meedan/check-api.git $GITHUB_BRANCH >/dev/null && echo $GITHUB_BRANCH) || echo 'develop')
echo "Using branch $CHECK_API_BRANCH for Check API"
git clone --branch=$CHECK_API_BRANCH https://github.com/meedan/check-api.git
cd check-api
cp config/config.yml.example config/config.yml
cp config/database.yml.example config/database.yml
cp config/sidekiq.yml.example config/sidekiq.yml
cd -
- name: Setup Alegre
run: |
export ALEGRE_BRANCH=$((git ls-remote --exit-code --heads https://github.com/meedan/alegre.git $GITHUB_BRANCH >/dev/null && echo $GITHUB_BRANCH) || echo 'develop')
echo "Using branch $ALEGRE_BRANCH for Alegre"
git clone --branch=$ALEGRE_BRANCH https://github.com/meedan/alegre.git
cd alegre
cp .env_file.test .env_file
cp ../test/google_credentials.json google_credentials.json
cd -
- name: Setup Presto
run: |
export PRESTO_BRANCH=$((git ls-remote --exit-code --heads https://github.com/meedan/presto.git $GITHUB_BRANCH >/dev/null && echo $GITHUB_BRANCH) || echo 'master')
echo "Using branch $PRESTO_BRANCH for Presto"
git clone --branch=$PRESTO_BRANCH https://github.com/meedan/presto.git
cd presto
cp .env_file.test .env_file
cp ../test/google_credentials.json google_credentials.json
cd -
- name: Setup Configuration Files
run: |
cp config.js.example config.js
cp config.js.example test/config.js
cp config-build.js.example config-build.js
cp config-server.js.example config-server.js
cp test/config.yml.example test/config.yml
- name: Before Script
env:
MAX_WEB_CURL: 3000
WEB_CURL_COUNT: 0
run: |
GITHUB_JOB_NAME=$GITHUB_JOB_NAME GITHUB_BRANCH=$GITHUB_BRANCH ./build.sh
MAX_WEB_CURL=$MAX_WEB_CURL;
WEB_CURL_COUNT=$WEB_CURL_COUNT; until curl --silent -I -f --fail http://localhost:3333 || (("$WEB_CURL_COUNT" == "$MAX_WEB_CURL")); do printf .; sleep 1; WEB_CURL_COUNT=$((++WEB_CURL_COUNT)); done; if [ "$WEB_CURL_COUNT" == "$MAX_WEB_CURL" ]; then echo "Terminating job after $WEB_CURL_COUNT curl attempts to check-web"; exit 1; fi
docker ps
- name: Run linter
run: |
docker compose exec web npm run linter
docker compose exec web npm run test:integration:lint
- name: Run Integration test
env:
IMGUR_CLIENT_ID: ${{ secrets.IMGUR_CLIENT_ID }}
run: |
docker ps
docker compose exec web bash service nginx start
docker compose -f docker-compose.yml -f docker-test.yml exec chromedriver service nginx start
docker compose exec -T \
-e IMGUR_CLIENT_ID=$IMGUR_CLIENT_ID \
-e GITHUB_JOB_NAME=$GITHUB_JOB_NAME \
-e GITHUB_BRANCH=$GITHUB_BRANCH \
-e AWS_ENDPOINT=${{ secrets.AWS_ENDPOINT }} \
-e AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} \
-e AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} \
-e ROLE_TO_ASSUME=${{ secrets.AWS_ROLE_TO_ASSUME }} \
-e AWS_REGION=eu-west-1 \
-e TEST_RETRY_COUNT=3 \
web npm run tests
- name: After integration tests
run: |
docker compose exec web bash -c "python -m json.tool test/file.json"
size=$(du -k build/web/js/index.bundle.js | cut -f1) && size2=$(du -k build/web/js/vendor.bundle.js | cut -f1) && totalsize=$((size+size2)) && echo "Your bundle size is $totalsize kb"
unit-tests:
runs-on: ubuntu-latest
if: >
github.ref != 'refs/heads/develop' &&
github.ref != 'refs/heads/master' &&
!contains(github.event.head_commit.message, '[full ci]') &&
!contains(github.event.head_commit.message, '[smoke tests]') &&
!contains(github.event.head_commit.message, '[similarity tests]')
steps:
- uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: eu-west-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Decrypt credentials for Alegre
env:
DECRYPTION_PASSWORD: ${{ secrets.DECRYPTION_PASSWORD }}
run: |
openssl enc -aes-256-cbc -d -in test/google_credentials.json.enc -out test/google_credentials.json -k $DECRYPTION_PASSWORD
- name: Setup UTF-8 Capable locale
run: |
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
export LANGUAGE=C.UTF-8
- name: Setup Pender
env:
GIT_BRANCH: ${{ github.head_ref || github.ref_name }}
run: |
export PENDER_BRANCH=$((git ls-remote --exit-code --heads https://github.com/meedan/pender.git $GITHUB_BRANCH >/dev/null && echo $GIT_BRANCH) || echo 'develop')
echo "Using branch $PENDER_BRANCH for Pender"
git clone --branch=$PENDER_BRANCH https://github.com/meedan/pender.git
cd pender
cp config/config.yml.example config/config.yml
cp config/database.yml.example config/database.yml
cp config/sidekiq.yml.example config/sidekiq.yml
cd -
- name: Setup Check API
run: |
export CHECK_API_BRANCH=$((git ls-remote --exit-code --heads https://github.com/meedan/check-api.git $GITHUB_BRANCH >/dev/null && echo $GITHUB_BRANCH) || echo 'develop')
echo "Using branch $CHECK_API_BRANCH for Check API"
git clone --branch=$CHECK_API_BRANCH https://github.com/meedan/check-api.git
cd check-api
cp config/config.yml.example config/config.yml
cp config/database.yml.example config/database.yml
cp config/sidekiq.yml.example config/sidekiq.yml
cd -
- name: Setup Alegre
run: |
export ALEGRE_BRANCH=$((git ls-remote --exit-code --heads https://github.com/meedan/alegre.git $GITHUB_BRANCH >/dev/null && echo $GITHUB_BRANCH) || echo 'develop')
echo "Using branch $ALEGRE_BRANCH for Alegre"
git clone --branch=$ALEGRE_BRANCH https://github.com/meedan/alegre.git
cd alegre
cp .env_file.test .env_file
cp ../test/google_credentials.json google_credentials.json
cd -
- name: Setup Presto
run: |
export PRESTO_BRANCH=$((git ls-remote --exit-code --heads https://github.com/meedan/presto.git $GITHUB_BRANCH >/dev/null && echo $GITHUB_BRANCH) || echo 'master')
echo "Using branch $PRESTO_BRANCH for Presto"
git clone --branch=$PRESTO_BRANCH https://github.com/meedan/presto.git
cd presto
cp .env_file.test .env_file
cp ../test/google_credentials.json google_credentials.json
cd -
- name: Setup Configuration Files
run: |
cp config.js.example config.js
cp config.js.example test/config.js
cp config-build.js.example config-build.js
cp config-server.js.example config-server.js
cp test/config.yml.example test/config.yml
- name: Before Script
env:
MAX_WEB_CURL: 3000
WEB_CURL_COUNT: 0
run: |
gitHUB_JOB_NAME=$GITHUB_JOB_NAME GITHUB_BRANCH=$GITHUB_BRANCH ./build.sh
MAX_WEB_CURL=$MAX_WEB_CURL;
WEB_CURL_COUNT=$WEB_CURL_COUNT; until curl --silent -I -f --fail http://localhost:3333 || (("$WEB_CURL_COUNT" == "$MAX_WEB_CURL")); do printf .; sleep 1; WEB_CURL_COUNT=$((++WEB_CURL_COUNT)); done; if [ "$WEB_CURL_COUNT" == "$MAX_WEB_CURL" ]; then echo "Terminating job after $WEB_CURL_COUNT curl attempts to check-web"; exit 1; fi
docker ps
- name: Run linter
run: |
docker compose exec web npm run linter
docker compose exec web npm run test:integration:lint
- name: Run Unit Tests
run: |
docker compose exec -T -e GITHUB_JOB_NAME=$GITHUB_JOB_NAME web npm run tests