Skip to content

Commit

Permalink
Faster CI build for PR (#14171)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok authored and sampaiodiego committed Apr 17, 2019
1 parent 183652b commit f6f507d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 49 deletions.
104 changes: 63 additions & 41 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ test-configure-replicaset: &test-configure-replicaset
mongo --eval 'rs.initiate({_id:"rs0", members: [{"_id":1, "host":"localhost:27017"}]})'
mongo --eval 'rs.status()'
test-restore-npm-cache: &test-restore-npm-cache
keys:
- node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "package.json" }}

test-save-npm-cache: &test-save-npm-cache
key: node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "package.json" }}
paths:
- ./node_modules

test-docker-image: &test-docker-image
circleci/node:8.11-stretch-browsers

Expand All @@ -54,8 +63,10 @@ test-with-oplog: &test-with-oplog
- checkout
- run: *test-install-dependencies
- run: *test-configure-replicaset
- restore_cache: *test-restore-npm-cache
- run: *test-npm-install
- run: *test-run
- save_cache: *test-save-npm-cache
- store_artifacts: *test-store_artifacts

test-without-oplog: &test-without-oplog
Expand All @@ -64,8 +75,10 @@ test-without-oplog: &test-without-oplog
- attach_workspace: *attach_workspace
- checkout
- run: *test-install-dependencies
- restore_cache: *test-restore-npm-cache
- run: *test-npm-install
- run: *test-run
- save_cache: *test-save-npm-cache
- store_artifacts: *test-store_artifacts


Expand All @@ -79,13 +92,13 @@ jobs:
steps:
- checkout

# - restore_cache:
# keys:
# - node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "package.json" }}
- restore_cache:
keys:
- node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "package.json" }}

# - restore_cache:
# keys:
# - meteor-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/release" }}
- restore_cache:
keys:
- meteor-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/release" }}

- run:
name: Install Meteor
Expand Down Expand Up @@ -134,25 +147,34 @@ jobs:
command: |
meteor npm run testunit
# - restore_cache:
# keys:
# - meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/versions" }}
- restore_cache:
keys:
- meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/versions" }}

# - restore_cache:
# keys:
# - livechat-meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/app/.meteor/versions" }}
- restore_cache:
keys:
- livechat-meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/.app/.meteor/versions" }}

# - restore_cache:
# keys:
# - livechat-node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/app/package.json" }}
- restore_cache:
keys:
- livechat-node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/.app/package.json" }}

- run:
name: Build Rocket.Chat
environment:
TOOL_NODE_FLAGS: --max_old_space_size=3072
command: |
if [[ $CIRCLE_TAG ]]; then meteor reset; fi
meteor build --server-only --directory /tmp/build-test
if [[ $CIRCLE_TAG ]] || [[ $CIRCLE_BRANCH == 'develop' ]]; then
meteor reset;
fi
export CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"
if [[ -z $CIRCLE_PR_NUMBER ]]; then
meteor build --server-only --directory /tmp/build-test
else
export METEOR_PROFILE=1000
meteor build --server-only --directory --debug /tmp/build-test
fi;
- run:
name: Prepare build
Expand All @@ -163,30 +185,30 @@ jobs:
cd /tmp/build-test/bundle/programs/server
npm install
# - save_cache:
# key: node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "package.json" }}
# paths:
# - ./node_modules

# - save_cache:
# key: meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/versions" }}
# paths:
# - ./.meteor/local

# - save_cache:
# key: livechat-node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/app/package.json" }}
# paths:
# - ./packages/rocketchat-livechat/app/node_modules

# - save_cache:
# key: livechat-meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/app/.meteor/versions" }}
# paths:
# - ./packages/rocketchat-livechat/app/.meteor/local

# - save_cache:
# key: meteor-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/release" }}
# paths:
# - ~/.meteor
- save_cache:
key: node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "package.json" }}
paths:
- ./node_modules

- save_cache:
key: meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/versions" }}
paths:
- ./.meteor/local

- save_cache:
key: livechat-node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/.app/package.json" }}
paths:
- ./packages/rocketchat-livechat/app/node_modules

- save_cache:
key: livechat-meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/.app/.meteor/versions" }}
paths:
- ./packages/rocketchat-livechat/app/.meteor/local

- save_cache:
key: meteor-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/release" }}
paths:
- ~/.meteor

- persist_to_workspace:
root: /tmp/
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-livechat/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Package.registerBuildPlugin({
'plugin/build-livechat.js',
],
npmDependencies: {
shelljs: '0.8.1',
'uglify-js': '2.8.29',
},
});
Expand Down
19 changes: 14 additions & 5 deletions packages/rocketchat-livechat/plugin/build-livechat.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import path from 'path';
import shell from 'shelljs';
import { execSync } from 'child_process';
import fs from 'fs';
import UglifyJS from 'uglify-js';

const result = UglifyJS.minify(path.resolve('packages', 'rocketchat-livechat', 'assets', 'rocket-livechat.js'));
const livechatSource = path.resolve('packages', 'rocketchat-livechat', 'assets', 'rocket-livechat.js');
const livechatTarget = path.resolve('packages', 'rocketchat-livechat', 'assets', 'rocketchat-livechat.min.js');

fs.writeFileSync(path.resolve('packages', 'rocketchat-livechat', 'assets', 'rocketchat-livechat.min.js'), result.code);
if (process.env.CIRCLE_PR_NUMBER) {
fs.writeFileSync(livechatTarget, fs.readFileSync(livechatSource));
} else {
fs.writeFileSync(livechatTarget, UglifyJS.minify(livechatSource).code);
}

const packagePath = path.join(path.resolve('.'), 'packages', 'rocketchat-livechat');
const pluginPath = path.join(packagePath, 'plugin');

const options = {
env: process.env,
};

if (process.platform === 'win32') {
shell.exec(`${ pluginPath }/build.bat`);
execSync(`${ pluginPath }/build.bat`, options);
} else {
shell.exec(`sh ${ pluginPath }/build.sh`);
execSync(`sh ${ pluginPath }/build.sh`, options);
}
3 changes: 2 additions & 1 deletion packages/rocketchat-livechat/plugin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export LATEST_LIVECHAT_VERSION="1.0.0"

cd packages/rocketchat-livechat/.app
meteor npm install --production

meteor build --headless --directory $BUILD_DIR

rm -rf $LIVECHAT_DIR
Expand All @@ -32,7 +33,7 @@ rm build.tar.gz

# change to lowercase so all injected junk from rocket.chat is not sent: https://github.com/meteorhacks/meteor-inject-initial/blob/master/lib/inject-core.js#L10
# this is not harmful since doctype is case-insesitive: https://www.w3.org/TR/html5/syntax.html#the-doctype
ex -s -c '%s/<!DOCTYPE/<!doctype/g|x' index.html
node -e 'fs.writeFileSync("index.html", fs.readFileSync("index.html").toString().replace("<!DOCTYPE", "<!doctype"));'

cd $LIVECHAT_ASSETS_DIR
cp ../../public/livechat/$LATEST_LIVECHAT_VERSION/index.html .
2 changes: 1 addition & 1 deletion tests/chimp-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
// chai: false,
screenshotsOnError: true,
screenshotsPath: '.screenshots',
captureAllStepScreenshots: true,
captureAllStepScreenshots: false,
saveScreenshotsToDisk: true,
// // Note: With a large viewport size and captureAllStepScreenshots enabled,
// // you may run out of memory. Use browser.setViewportSize to make the
Expand Down

0 comments on commit f6f507d

Please sign in to comment.