Skip to content

Commit d1e8503

Browse files
rodrigokgeekgonecrazy
authored andcommitted
Add CircleCI (#8685)
1 parent 67ce583 commit d1e8503

File tree

13 files changed

+406
-3
lines changed

13 files changed

+406
-3
lines changed

.circleci/config.yml

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
defaults: &defaults
2+
working_directory: ~/repo
3+
4+
version: 2
5+
jobs:
6+
build:
7+
<<: *defaults
8+
docker:
9+
- image: circleci/node:4.8
10+
11+
steps:
12+
- checkout
13+
14+
- restore_cache:
15+
keys:
16+
- node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "package.json" }}
17+
18+
- restore_cache:
19+
keys:
20+
- meteor-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/release" }}
21+
22+
- run:
23+
name: Install Meteor
24+
command: |
25+
# Restore bin from cache
26+
set +e
27+
METEOR_SYMLINK_TARGET=$(readlink ~/.meteor/meteor)
28+
METEOR_TOOL_DIRECTORY=$(dirname "$METEOR_SYMLINK_TARGET")
29+
set -e
30+
LAUNCHER=$HOME/.meteor/$METEOR_TOOL_DIRECTORY/scripts/admin/launch-meteor
31+
if [ -e $LAUNCHER ]
32+
then
33+
echo "Cached Meteor bin found, restoring it"
34+
sudo cp "$LAUNCHER" "/usr/local/bin/meteor"
35+
else
36+
echo "No cached Meteor bin found."
37+
fi
38+
39+
# only install meteor if bin isn't found
40+
command -v meteor >/dev/null 2>&1 || curl https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh
41+
42+
- run:
43+
name: Versions
44+
command: |
45+
npm --versions
46+
node -v
47+
meteor --version
48+
meteor npm --versions
49+
meteor node -v
50+
git version
51+
52+
- run:
53+
name: Meteor npm install
54+
command: |
55+
# rm -rf node_modules
56+
# rm -f package-lock.json
57+
meteor npm install
58+
59+
- run:
60+
name: Lint
61+
command: |
62+
meteor npm run lint
63+
meteor npm run stylelint
64+
65+
- run:
66+
name: Unit Test
67+
command: |
68+
meteor npm run testunit
69+
70+
- restore_cache:
71+
keys:
72+
- meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/versions" }}
73+
74+
- restore_cache:
75+
keys:
76+
- livechat-meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/app/.meteor/versions" }}
77+
78+
- restore_cache:
79+
keys:
80+
- livechat-node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/app/package.json" }}
81+
82+
- run:
83+
name: Build Rocket.Chat
84+
command: |
85+
if [[ $CIRCLE_TAG ]]; then meteor reset; fi
86+
set +e
87+
meteor add rocketchat:lib
88+
set -e
89+
meteor build --server-only --directory /tmp/build-test
90+
91+
- run:
92+
name: Prepare build
93+
command: |
94+
mkdir /tmp/build/
95+
cd /tmp/build-test
96+
tar czf /tmp/build/Rocket.Chat.tar.gz bundle
97+
cd /tmp/build-test/bundle/programs/server
98+
npm install
99+
100+
- save_cache:
101+
key: node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "package.json" }}
102+
paths:
103+
- ./node_modules
104+
105+
- save_cache:
106+
key: meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/versions" }}
107+
paths:
108+
- ./.meteor/local
109+
110+
- save_cache:
111+
key: livechat-node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/app/package.json" }}
112+
paths:
113+
- ./packages/rocketchat-livechat/app/node_modules
114+
115+
- save_cache:
116+
key: livechat-meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/app/.meteor/versions" }}
117+
paths:
118+
- ./packages/rocketchat-livechat/app/.meteor/local
119+
120+
- save_cache:
121+
key: meteor-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/release" }}
122+
paths:
123+
- ~/.meteor
124+
125+
- persist_to_workspace:
126+
root: /tmp/
127+
paths:
128+
- build-test
129+
- build
130+
131+
- store_artifacts:
132+
path: /tmp/build
133+
134+
test-with-oplog:
135+
<<: *defaults
136+
docker:
137+
- image: circleci/node:4.8-browsers
138+
- image: mongo:3.4
139+
command: [mongod, --nojournal, --noprealloc, --smallfiles, --replSet=rs0]
140+
141+
environment:
142+
TEST_MODE: "true"
143+
MONGO_URL: mongodb://localhost:27017/testwithoplog
144+
MONGO_OPLOG_URL: mongodb://localhost:27017/local
145+
146+
steps:
147+
- attach_workspace:
148+
at: /tmp
149+
150+
- checkout
151+
152+
- run:
153+
name: Install dependencies
154+
command: |
155+
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
156+
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
157+
sudo apt-get update
158+
sudo apt-get install -y mongodb-org-shell
159+
160+
- run:
161+
name: Configure Replica Set
162+
command: |
163+
mongo --eval 'rs.initiate({_id:"rs0", members: [{"_id":1, "host":"localhost:27017"}]})'
164+
mongo --eval 'rs.status()'
165+
166+
- run:
167+
name: Update NPM
168+
command: |
169+
sudo npm install -g npm
170+
171+
- run:
172+
name: NPM install
173+
command: |
174+
npm install
175+
176+
- run:
177+
name: Run Tests
178+
command: |
179+
for i in $(seq 1 5); do npm test && s=0 && break || s=$? && sleep 1; done; (exit $s)
180+
181+
- store_artifacts:
182+
path: ~/repo/.screenshots
183+
184+
test-without-oplog:
185+
<<: *defaults
186+
docker:
187+
- image: circleci/node:4.8-browsers
188+
- image: circleci/mongo:3.4
189+
190+
environment:
191+
TEST_MODE: "true"
192+
MONGO_URL: mongodb://localhost:27017/testwithoplog
193+
194+
steps:
195+
- attach_workspace:
196+
at: /tmp
197+
198+
- checkout
199+
200+
- run:
201+
name: Update NPM
202+
command: |
203+
sudo npm install -g npm
204+
205+
- run:
206+
name: NPM install
207+
command: |
208+
npm install
209+
210+
- run:
211+
name: Run Tests
212+
command: |
213+
for i in $(seq 1 5); do npm test && s=0 && break || s=$? && sleep 1; done; (exit $s)
214+
215+
# - run:
216+
# name: Build Failed
217+
# when: on_fail
218+
# command: |
219+
# cp -R .screenshots /tmp/screenshots
220+
221+
# - store_artifacts:
222+
# path: ~/repo/.screenshots
223+
224+
deploy:
225+
<<: *defaults
226+
docker:
227+
- image: circleci/node:4.8
228+
229+
steps:
230+
- attach_workspace:
231+
at: /tmp
232+
233+
- checkout
234+
235+
- run:
236+
name: Install AWS cli
237+
command: |
238+
if [[ $CIRCLE_PULL_REQUESTS ]]; then exit 0; fi;
239+
240+
sudo apt-get -y -qq update
241+
sudo apt-get -y -qq install python3.4-dev
242+
curl -O https://bootstrap.pypa.io/get-pip.py
243+
python3.4 get-pip.py --user
244+
export PATH=~/.local/bin:$PATH
245+
pip install awscli --upgrade --user
246+
247+
- run:
248+
name: Publish assets
249+
command: |
250+
if [[ $CIRCLE_PULL_REQUESTS ]]; then exit 0; fi;
251+
252+
export PATH=~/.local/bin:$PATH
253+
export CIRCLE_TAG=${CIRCLE_TAG:=}
254+
255+
source .circleci/setartname.sh
256+
source .circleci/setdeploydir.sh
257+
bash .circleci/setupsig.sh
258+
bash .circleci/namefiles.sh
259+
# echo ".circleci/sandstorm.sh"
260+
261+
aws s3 cp $ROCKET_DEPLOY_DIR/ s3://download.rocket.chat/build/ --recursive
262+
263+
bash .circleci/update-releases.sh
264+
bash .circleci/docker.sh
265+
bash .circleci/snap.sh
266+
267+
workflows:
268+
version: 2
269+
build-and-test:
270+
jobs:
271+
- build
272+
- test-with-oplog:
273+
requires:
274+
- build
275+
- test-without-oplog:
276+
requires:
277+
- build
278+
- deploy:
279+
requires:
280+
- test-with-oplog
281+
- test-without-oplog
282+
filters:
283+
branches:
284+
only:
285+
- develop
286+
- circle-ci
287+
tags:
288+
only:
289+
- "/^\\d+\\.\\d+\\.\\d+(-rc\\.\\d+)?$/"

.circleci/docker.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -euvo pipefail
3+
IFS=$'\n\t'
4+
5+
CURL_URL="https://registry.hub.docker.com/u/rocketchat/rocket.chat/trigger/$DOCKER_TRIGGER_TOKEN/"
6+
7+
if [[ $CIRCLE_TAG ]]; then
8+
CURL_DATA='{"source_type":"Tag","source_name":"'"$CIRCLE_TAG"'"}';
9+
else
10+
CURL_DATA='{"source_type":"Branch","source_name":"'"$CIRCLE_BRANCH"'"}';
11+
fi
12+
13+
curl -H "Content-Type: application/json" --data "$CURL_DATA" -X POST "$CURL_URL"

.circleci/namefiles.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -euvo pipefail
3+
IFS=$'\n\t'
4+
5+
FILENAME="$ROCKET_DEPLOY_DIR/rocket.chat-$ARTIFACT_NAME.tgz";
6+
7+
ln -s /tmp/build/Rocket.Chat.tar.gz "$FILENAME"
8+
gpg --armor --detach-sign "$FILENAME"

.circleci/setartname.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
if [[ $CIRCLE_TAG ]]; then
2+
export ARTIFACT_NAME="$(npm run version --silent)"
3+
else
4+
export ARTIFACT_NAME="$(npm run version --silent).circleci-$CIRCLE_BUILD_NUM"
5+
fi
6+
7+
if [[ $CIRCLE_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+ ]]; then
8+
SNAP_CHANNEL=candidate
9+
RC_RELEASE=candidate
10+
RC_VERSION=$CIRCLE_TAG
11+
elif [[ $CIRCLE_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
12+
SNAP_CHANNEL=stable
13+
RC_RELEASE=stable
14+
RC_VERSION=$CIRCLE_TAG
15+
else
16+
SNAP_CHANNEL=edge
17+
RC_RELEASE=develop
18+
RC_VERSION=0.59.0-develop
19+
fi
20+
21+
export SNAP_CHANNEL
22+
export RC_RELEASE
23+
export RC_VERSION

.circleci/setdeploydir.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export ROCKET_DEPLOY_DIR="/tmp/deploy"
2+
mkdir -p $ROCKET_DEPLOY_DIR

.circleci/setupsig.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -euvo pipefail
3+
IFS=$'\n\t'
4+
5+
cp .circleci/sign.key.gpg /tmp
6+
gpg --yes --batch --passphrase=$GPG_PASSWORD /tmp/sign.key.gpg
7+
gpg --allow-secret-key-import --import /tmp/sign.key
8+
rm /tmp/sign.key

.circleci/sign.key.gpg

5 KB
Binary file not shown.

.circleci/snap.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
set -euvo pipefail
3+
IFS=$'\n\t'
4+
5+
# Add launchpad to known hosts
6+
ssh-keyscan -t rsa -H git.launchpad.net > ~/.ssh/known_hosts
7+
8+
echo "Preparing to trigger a snap release for $SNAP_CHANNEL channel"
9+
10+
cd $PWD/.snapcraft
11+
12+
# We need some meta data so it'll actually commit. This could be useful to have for debugging later.
13+
echo -e "Tag: $CIRCLE_TAG\r\nBranch: $CIRCLE_BRANCH\r\nBuild: $CIRCLE_BUILD_NUM\r\nCommit: $CIRCLE_SHA1" > buildinfo
14+
15+
# Clone launchpad repo for the channel down.
16+
git clone -b $SNAP_CHANNEL git+ssh://[email protected]/rocket.chat launchpad
17+
18+
# Rarely will change, but just incase we copy it all
19+
cp -r resources buildinfo launchpad/
20+
sed s/#{RC_VERSION}/$RC_VERSION/ snapcraft.yaml > launchpad/snapcraft.yaml
21+
22+
cd launchpad
23+
git add resources snapcraft.yaml buildinfo
24+
25+
# Set commit author details
26+
git config user.email "[email protected]"
27+
git config user.name "CircleCI"
28+
29+
# Another place where basic meta data will live for at a glance info
30+
git commit -m "CircleCI Build: $CIRCLE_BUILD_NUM CircleCI Commit: $CIRCLE_SHA1"
31+
32+
# Push up up to the branch of choice.
33+
git push origin $SNAP_CHANNEL
34+
35+
# Clean up
36+
cd ..
37+
rm -rf launchpad

0 commit comments

Comments
 (0)