-
Notifications
You must be signed in to change notification settings - Fork 10.9k
614 lines (502 loc) · 18.3 KB
/
build_and_test.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
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
name: Build and Test
on:
release:
types: [published]
pull_request:
branches: '**'
push:
branches:
- develop
env:
CI: true
MONGO_URL: mongodb://localhost:27017
TOOL_NODE_FLAGS: --max_old_space_size=4096
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Github Info
run: |
echo "GITHUB_ACTION: $GITHUB_ACTION"
echo "GITHUB_ACTOR: $GITHUB_ACTOR"
echo "GITHUB_REF: $GITHUB_REF"
echo "GITHUB_HEAD_REF: $GITHUB_HEAD_REF"
echo "GITHUB_BASE_REF: $GITHUB_BASE_REF"
echo "github.event_name: ${{ github.event_name }}"
cat $GITHUB_EVENT_PATH
- name: Use Node.js 12.22.1
uses: actions/setup-node@v2
with:
node-version: "12.22.1"
- uses: actions/checkout@v2
- name: Free disk space
run: |
sudo swapoff -a
sudo rm -f /swapfile
sudo apt clean
docker rmi $(docker image ls -aq)
df -h
- name: check package-lock
run: |
npx package-lock-check
- name: Cache cypress
id: cache-cypress
uses: actions/cache@v2
with:
path: /home/runner/.cache/Cypress
key: ${{ runner.OS }}-cache-cypress-${{ hashFiles('**/package-lock.json', '.github/workflows/build_and_test.yml') }}
# - name: Cache node modules
# if: steps.cache-cypress.outputs.cache-hit == 'true'
# id: cache-nodemodules
# uses: actions/cache@v2
# with:
# path: |
# ./node_modules
# ./ee/server/services/node_modules
# key: ${{ runner.OS }}-node_modules-${{ hashFiles('**/package-lock.json', '.github/workflows/build_and_test.yml') }}
- name: Cache meteor local
uses: actions/cache@v2
with:
path: ./.meteor/local
key: ${{ runner.OS }}-meteor_cache-${{ hashFiles('.meteor/versions', '.github/workflows/build_and_test.yml') }}
- name: Cache meteor
uses: actions/cache@v2
with:
path: ~/.meteor
key: ${{ runner.OS }}-meteor-${{ hashFiles('.meteor/release', '.github/workflows/build_and_test.yml') }}
- name: Install Meteor
run: |
# Restore bin from cache
set +e
METEOR_SYMLINK_TARGET=$(readlink ~/.meteor/meteor)
METEOR_TOOL_DIRECTORY=$(dirname "$METEOR_SYMLINK_TARGET")
set -e
LAUNCHER=$HOME/.meteor/$METEOR_TOOL_DIRECTORY/scripts/admin/launch-meteor
if [ -e $LAUNCHER ]
then
echo "Cached Meteor bin found, restoring it"
sudo cp "$LAUNCHER" "/usr/local/bin/meteor"
else
echo "No cached Meteor bin found."
fi
# only install meteor if bin isn't found
command -v meteor >/dev/null 2>&1 || curl https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh
- name: Versions
run: |
npm --versions
node -v
meteor --version
meteor npm --versions
meteor node -v
git version
- name: npm install
# if: steps.cache-nodemodules.outputs.cache-hit != 'true' || steps.cache-cypress.outputs.cache-hit != 'true'
run: |
meteor npm install
cd ./ee/server/services
npm install
cd -
- run: meteor npm run lint
- run: meteor npm run translation-check
- name: Launch MongoDB
uses: wbari/start-mongoDB@v0.2
with:
mongoDBVersion: "4.0"
- run: meteor npm run testunit
- run: meteor npm run typecheck
- name: Build Storybook to sanity check components
run: npm run build-storybook ; rm -rf ./storybook-static
# To reduce memory need during actual build, build the packages solely first
# - name: Build a Meteor cache
# run: |
# # to do this we can clear the main files and it build the rest
# echo "" > server/main.js
# echo "" > client/main.js
# sed -i.backup 's/rocketchat:livechat/#rocketchat:livechat/' .meteor/packages
# meteor build --server-only --debug --directory /tmp/build-temp
# git checkout -- server/main.js client/main.js .meteor/packages
- name: Reset Meteor
if: startsWith(github.ref, 'refs/tags/') == 'true' || github.ref == 'refs/heads/develop'
run: |
meteor reset
- name: Try building micro services
run: |
cd ./ee/server/services
npm run build
rm -rf dist/
- name: Build Rocket.Chat From Pull Request
if: startsWith(github.ref, 'refs/pull/') == true
env:
METEOR_PROFILE: 1000
run: |
meteor build --server-only --directory --debug /tmp/build-test
- name: Build Rocket.Chat
if: startsWith(github.ref, 'refs/pull/') != true
run: |
meteor build --server-only --directory /tmp/build-test
- name: Prepare build
run: |
mkdir /tmp/build/
cd /tmp/build-test
tar czf /tmp/build/Rocket.Chat.tar.gz bundle
cd /tmp/build-test/bundle/programs/server
npm install
cd /tmp
tar czf Rocket.Chat.test.tar.gz ./build-test
- name: Store build for tests
uses: actions/upload-artifact@v2
with:
name: build-test
path: /tmp/Rocket.Chat.test.tar.gz
- name: Store build
uses: actions/upload-artifact@v2
with:
name: build
path: /tmp/build
test:
runs-on: ubuntu-16.04
needs: build
strategy:
matrix:
node-version: ["12.22.1"]
mongodb-version: ["3.4", "3.6", "4.0", "4.2"]
steps:
- name: Launch MongoDB
uses: wbari/start-mongoDB@v0.2
with:
mongoDBVersion: ${{ matrix.mongodb-version }} --replSet=rs0
- name: Restore build for tests
uses: actions/download-artifact@v2
with:
name: build-test
path: /tmp
- name: Decompress build
run: |
cd /tmp
tar xzf Rocket.Chat.test.tar.gz
cd -
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Setup Chrome
run: |
npm i chromedriver
- name: Configure Replica Set
run: |
docker exec mongo mongo --eval 'rs.initiate({_id:"rs0", members: [{"_id":1, "host":"localhost:27017"}]})'
docker exec mongo mongo --eval 'rs.status()'
- uses: actions/checkout@v2
- name: Cache cypress
id: cache-cypress
uses: actions/cache@v2
with:
path: /home/runner/.cache/Cypress
key: ${{ runner.OS }}-cache-cypress-${{ hashFiles('**/package-lock.json', '.github/workflows/build_and_test.yml') }}
# - name: Cache node modules
# if: steps.cache-cypress.outputs.cache-hit == 'true'
# id: cache-nodemodules
# uses: actions/cache@v2
# with:
# path: |
# ./node_modules
# ./ee/server/services/node_modules
# key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json', '.github/workflows/build_and_test.yml') }}
- name: NPM install
# if: steps.cache-nodemodules.outputs.cache-hit != 'true' || steps.cache-cypress.outputs.cache-hit != 'true'
run: |
npm install
- name: Test
env:
TEST_MODE: "true"
MONGO_URL: mongodb://localhost:27017/rocketchat
MONGO_OPLOG_URL: mongodb://localhost:27017/local
run: |
echo -e 'pcm.!default {\n type hw\n card 0\n}\n\nctl.!default {\n type hw\n card 0\n}' > ~/.asoundrc
Xvfb -screen 0 1024x768x24 :99 &
for i in $(seq 1 5); do (docker exec mongo mongo rocketchat --eval 'db.dropDatabase()') && npm run testci && s=0 && break || s=$? && sleep 1; done; (exit $s)
# notification:
# runs-on: ubuntu-latest
# needs: test
# steps:
# - name: Rocket.Chat Notification
# uses: RocketChat/Rocket.Chat.GitHub.Action.Notification@1.1.1
# with:
# type: ${{ job.status }}
# job_name: '**Build and Test**'
# url: ${{ secrets.ROCKETCHAT_WEBHOOK }}
# commit: true
# token: ${{ secrets.GITHUB_TOKEN }}
build-image-pr:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
strategy:
matrix:
release: ["official", "preview"]
steps:
- uses: actions/checkout@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.CR_USER }}
password: ${{ secrets.CR_PAT }}
- name: Free disk space
run: |
sudo swapoff -a
sudo rm -f /swapfile
sudo apt clean
docker rmi $(docker image ls -aq)
df -h
# - name: Cache node modules
# id: cache-nodemodules
# uses: actions/cache@v2
# with:
# path: |
# ./node_modules
# ./ee/server/services/node_modules
# key: ${{ runner.OS }}-node_modules-${{ hashFiles('**/package-lock.json', '.github/workflows/build_and_test.yml') }}
- name: Cache meteor local
uses: actions/cache@v2
with:
path: ./.meteor/local
key: ${{ runner.OS }}-meteor_cache-${{ hashFiles('.meteor/versions', '.github/workflows/build_and_test.yml') }}
- name: Cache meteor
uses: actions/cache@v2
with:
path: ~/.meteor
key: ${{ runner.OS }}-meteor-${{ hashFiles('.meteor/release', '.github/workflows/build_and_test.yml') }}
- name: Use Node.js 12.22.1
uses: actions/setup-node@v2
with:
node-version: "12.22.1"
- name: Install Meteor
run: |
# Restore bin from cache
set +e
METEOR_SYMLINK_TARGET=$(readlink ~/.meteor/meteor)
METEOR_TOOL_DIRECTORY=$(dirname "$METEOR_SYMLINK_TARGET")
set -e
LAUNCHER=$HOME/.meteor/$METEOR_TOOL_DIRECTORY/scripts/admin/launch-meteor
if [ -e $LAUNCHER ]
then
echo "Cached Meteor bin found, restoring it"
sudo cp "$LAUNCHER" "/usr/local/bin/meteor"
else
echo "No cached Meteor bin found."
fi
# only install meteor if bin isn't found
command -v meteor >/dev/null 2>&1 || curl https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh
- name: Versions
run: |
npm --versions
node -v
meteor --version
meteor npm --versions
meteor node -v
git version
- name: npm install
# if: steps.cache-nodemodules.outputs.cache-hit != 'true'
run: |
meteor npm install
# To reduce memory need during actual build, build the packages solely first
# - name: Build a Meteor cache
# run: |
# # to do this we can clear the main files and it build the rest
# echo "" > server/main.js
# echo "" > client/main.js
# sed -i.backup 's/rocketchat:livechat/#rocketchat:livechat/' .meteor/packages
# meteor build --server-only --debug --directory /tmp/build-temp
# git checkout -- server/main.js client/main.js .meteor/packages
- name: Build Rocket.Chat
run: |
meteor build --server-only --directory /tmp/build-pr
- name: Build Docker image for PRs
run: |
cd /tmp/build-pr
LOWERCASE_REPOSITORY=$(echo "${{ github.repository_owner }}" | tr "[:upper:]" "[:lower:]")
IMAGE_NAME="rocket.chat"
if [[ '${{ matrix.release }}' = 'preview' ]]; then
IMAGE_NAME="${IMAGE_NAME}.preview"
fi;
IMAGE_NAME="ghcr.io/${LOWERCASE_REPOSITORY}/${IMAGE_NAME}:pr-${{ github.event.number }}"
echo "Build official Docker image ${IMAGE_NAME}"
DOCKER_PATH="${GITHUB_WORKSPACE}/.docker"
if [[ '${{ matrix.release }}' = 'preview' ]]; then
DOCKER_PATH="${DOCKER_PATH}-mongo"
fi;
echo "Build ${{ matrix.release }} Docker image"
cp ${DOCKER_PATH}/Dockerfile .
if [ -e ${DOCKER_PATH}/entrypoint.sh ]; then
cp ${DOCKER_PATH}/entrypoint.sh .
fi;
docker build -t $IMAGE_NAME .
docker push $IMAGE_NAME
deploy:
runs-on: ubuntu-latest
if: github.event_name == 'release' || github.ref == 'refs/heads/develop'
needs: test
steps:
- uses: actions/checkout@v2
- name: Restore build
uses: actions/download-artifact@v2
with:
name: build
path: /tmp/build
- name: Publish assets
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: 'us-east-1'
GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
REDHAT_REGISTRY_PID: ${{ secrets.REDHAT_REGISTRY_PID }}
REDHAT_REGISTRY_KEY: ${{ secrets.REDHAT_REGISTRY_KEY }}
UPDATE_TOKEN: ${{ secrets.UPDATE_TOKEN }}
run: |
if [[ '${{ github.event_name }}' = 'release' ]]; then
GIT_TAG="${GITHUB_REF#*tags/}"
GIT_BRANCH=""
ARTIFACT_NAME="$(npm run version --silent)"
RC_VERSION=$GIT_TAG
if [[ $GIT_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+ ]]; then
SNAP_CHANNEL=candidate
RC_RELEASE=candidate
elif [[ $GIT_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
SNAP_CHANNEL=stable
RC_RELEASE=stable
fi
else
GIT_TAG=""
GIT_BRANCH="${GITHUB_REF#*heads/}"
ARTIFACT_NAME="$(npm run version --silent).$GITHUB_SHA"
RC_VERSION="$(npm run version --silent)"
SNAP_CHANNEL=edge
RC_RELEASE=develop
fi;
ROCKET_DEPLOY_DIR="/tmp/deploy"
FILENAME="$ROCKET_DEPLOY_DIR/rocket.chat-$ARTIFACT_NAME.tgz";
aws s3 cp s3://rocketchat/sign.key.gpg .github/sign.key.gpg
mkdir -p $ROCKET_DEPLOY_DIR
cp .github/sign.key.gpg /tmp
gpg --yes --batch --passphrase=$GPG_PASSWORD /tmp/sign.key.gpg
gpg --allow-secret-key-import --import /tmp/sign.key
rm /tmp/sign.key
ln -s /tmp/build/Rocket.Chat.tar.gz "$FILENAME"
gpg --armor --detach-sign "$FILENAME"
aws s3 cp $ROCKET_DEPLOY_DIR/ s3://download.rocket.chat/build/ --recursive
curl -H "Content-Type: application/json" -H "X-Update-Token: $UPDATE_TOKEN" -d \
"{\"commit\": \"$GITHUB_SHA\", \"tag\": \"$RC_VERSION\", \"branch\": \"$GIT_BRANCH\", \"artifactName\": \"$ARTIFACT_NAME\", \"releaseType\": \"$RC_RELEASE\" }" \
https://releases.rocket.chat/update
# Makes build fail if the release isn't there
curl --fail https://releases.rocket.chat/$RC_VERSION/info
if [[ $GIT_TAG ]]; then
curl -X POST \
https://connect.redhat.com/api/v2/projects/$REDHAT_REGISTRY_PID/build \
-H "Authorization: Bearer $REDHAT_REGISTRY_KEY" \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '{"tag":"'$GIT_TAG'"}'
fi
image-build:
runs-on: ubuntu-latest
needs: deploy
strategy:
matrix:
release: ["official", "preview"]
env:
IMAGE: "rocketchat/rocket.chat"
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Restore build
uses: actions/download-artifact@v2
with:
name: build
path: /tmp/build
- name: Unpack build
run: |
cd /tmp/build
tar xzf Rocket.Chat.tar.gz
rm Rocket.Chat.tar.gz
DOCKER_PATH="${GITHUB_WORKSPACE}/.docker"
if [[ '${{ matrix.release }}' = 'preview' ]]; then
DOCKER_PATH="${DOCKER_PATH}-mongo"
fi;
echo "Build ${{ matrix.release }} Docker image"
cp ${DOCKER_PATH}/Dockerfile .
if [ -e ${DOCKER_PATH}/entrypoint.sh ]; then
cp ${DOCKER_PATH}/entrypoint.sh .
fi;
- name: Build Docker image for tag
if: github.event_name == 'release'
run: |
cd /tmp/build
GIT_TAG="${GITHUB_REF#*tags/}"
if [[ '${{ matrix.release }}' = 'preview' ]]; then
IMAGE="${IMAGE}.preview"
fi;
docker build -t ${IMAGE}:$GIT_TAG .
docker push ${IMAGE}:$GIT_TAG
if echo "$GIT_TAG" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' ; then
RELEASE="latest"
elif echo "$GIT_TAG" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+$' ; then
RELEASE="release-candidate"
fi
docker tag ${IMAGE}:$GIT_TAG ${IMAGE}:${RELEASE}
docker push ${IMAGE}:${RELEASE}
- name: Build Docker image for develop
if: github.ref == 'refs/heads/develop'
run: |
cd /tmp/build
if [[ '${{ matrix.release }}' = 'preview' ]]; then
IMAGE="${IMAGE}.preview"
fi;
docker build -t ${IMAGE}:develop .
docker push ${IMAGE}:develop
services-image-build:
runs-on: ubuntu-latest
needs: deploy
strategy:
matrix:
service: ["account", "authorization", "ddp-streamer", "presence", "stream-hub"]
steps:
- uses: actions/checkout@v2
- name: Use Node.js 12.22.1
uses: actions/setup-node@v2
with:
node-version: "12.22.1"
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Build Docker images
run: |
# defines image tag
if [[ $GITHUB_REF == refs/tags/* ]]; then
IMAGE_TAG="${GITHUB_REF#refs/tags/}"
else
IMAGE_TAG="${GITHUB_REF#refs/heads/}"
fi
# first install repo dependencies
npm i
# then micro services dependencies
cd ./ee/server/services
npm i
npm run build
echo "Building Docker image for service: ${{ matrix.service }}:${IMAGE_TAG}"
docker build --build-arg SERVICE=${{ matrix.service }} -t rocketchat/${{ matrix.service }}-service:${IMAGE_TAG} .
docker push rocketchat/${{ matrix.service }}-service:${IMAGE_TAG}
if [[ $GITHUB_REF == refs/tags/* ]]; then
if echo "$IMAGE_TAG" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' ; then
RELEASE="latest"
elif echo "$IMAGE_TAG" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+$' ; then
RELEASE="release-candidate"
fi
docker tag rocketchat/${{ matrix.service }}-service:${IMAGE_TAG} rocketchat/${{ matrix.service }}-service:${RELEASE}
docker push rocketchat/${{ matrix.service }}-service:${RELEASE}
fi