Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(danger): report PR's build size #2674

Merged
merged 2 commits into from Jun 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -14,22 +14,22 @@ cache:
env:
matrix:
- NODE_VER=4 FULL_VALIDATE=false
- NODE_VER=6 FULL_VALIDATE=true alias grunt=./node_modules/grunt-cli/bin/grunt danger=./node_modules/danger/distribution/danger
- NODE_VER=6 FULL_VALIDATE=true alias grunt=./node_modules/grunt-cli/bin/grunt
- NODE_VER=7 FULL_VALIDATE=false
matrix:
fast_finish: true

before_install:
- nvm install $NODE_VER
- npm install -g npm@4 && node -v && npm -v
- npm install -g npm@4 && npm install -g npx && node -v && npm -v
- if [ "$FULL_VALIDATE" == "true" ]; then npm install grunt@0.4.1 grunt-cli grunt-contrib-connect grunt-run; fi
- if [ "$FULL_VALIDATE" == "true" ] && [ -n "DANGER_GITHUB_API_TOKEN" ]; then npm install danger@0.18.0 && danger; fi

install:
- npm install
- if [ "$FULL_VALIDATE" == "true" ]; then npm run lint && npm run check_circular_dependencies; fi

script:
- if [ "$FULL_VALIDATE" == "true" ] && [ -n "DANGER_GITHUB_API_TOKEN" ]; then echo {} > ./.babelrc && npx danger; fi
- npm run build_spec && npm run test_mocha && node ./node_modules/markdown-doctest/bin/cmd.js

after_success:
Expand Down
59 changes: 58 additions & 1 deletion dangerfile.js
@@ -1,6 +1,8 @@
var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var getSize = require('get-folder-size');
var gzipSize = require('gzip-size');
var validateMessage = require('validate-commit-msg');

//simple regex matcher to detect usage of helper function and its type signature
Expand Down Expand Up @@ -65,4 +67,59 @@ var messageConventionValid = danger.git.commits.reduce(function (acc, value) {
if (!messageConventionValid) {
warn('commit message does not follows conventional change log (' + ++errorCount + ')');
markdown('> (' + errorCount + ') : RxJS uses conventional change log to generate changelog automatically. It seems some of commit messages are not following those, please check [contributing guideline](https://github.com/ReactiveX/rxjs/blob/master/CONTRIBUTING.md#commit-message-format) and update commit messages.');
}
}

function getKB(size) {
return (size / 1024).toFixed(2);
}

var globalFile = 'Rx.js';
var minFile = 'Rx.min.js';

function sizeDiffBadge(name, value) {
return 'https://img.shields.io/badge/' + name + '-' + value + 'KB-red.svg?style=flat-square';
}

//post size of build
schedule(new Promise(function (res) {
getSize('./dist/cjs', function (e, result) {
var localGlobalFile = path.resolve('./dist/global', globalFile);
var localMinFile = path.resolve('./dist/global', minFile);

//get sizes of PR build
var global = fs.statSync(localGlobalFile);
var global_gzip = gzipSize.sync(fs.readFileSync(localGlobalFile, 'utf8'));
var min = fs.statSync(localMinFile);
var min_gzip = gzipSize.sync(fs.readFileSync(localMinFile, 'utf8'));

//resolve path to release build
var releasePath = path.dirname(require.resolve(require.resolve('rxjs')));
var bundlePath = path.resolve(releasePath, 'bundles');
var bundleGlobalFile = path.resolve(bundlePath, globalFile);
var bundleMinFile = path.resolve(bundlePath, minFile);

var packagePath = path.resolve(releasePath, 'package.json');
var releaseVersion = require(packagePath).version;

//get sizes of release build
var bundleGlobal = fs.statSync(bundleGlobalFile);
var bundle_global_gzip = gzipSize.sync(fs.readFileSync(bundleGlobalFile, 'utf8'));
var bundleMin = fs.statSync(bundleMinFile);
var bundle_min_gzip = gzipSize.sync(fs.readFileSync(bundleMinFile, 'utf8'));

var sizeMessage = '<img src="https://img.shields.io/badge/Size%20Diff%20%28' + releaseVersion + '%29--lightgrey.svg?style=flat-square"/> ';
sizeMessage += '<img src="' + sizeDiffBadge('Global', getKB(global.size) - getKB(bundleGlobal.size)) + '"/>';
sizeMessage += '<img src="' + sizeDiffBadge('Global(gzipped)', getKB(global_gzip) - getKB(bundle_global_gzip)) + '"/>';
sizeMessage += '<img src="' + sizeDiffBadge('Min', getKB(min.size) - getKB(bundleMin.size)) + '"/>';
sizeMessage += '<img src="' + sizeDiffBadge('Min (gzipped)', getKB(min_gzip) - getKB(bundle_min_gzip)) + '"/>';
message(sizeMessage);

markdown('> CJS: **' + getKB(result) +
'**KB, global: **' + getKB(global.size) +
'**KB (gzipped: **' + getKB(global_gzip) +
'**KB), min: **' + getKB(min.size) +
'**KB (gzipped: **' + getKB(min_gzip) + '**KB)');

res();
});
}));
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -155,11 +155,13 @@
"commitizen": "^2.8.6",
"coveralls": "^2.11.13",
"cz-conventional-changelog": "^1.2.0",
"danger": "^0.21.0",
"doctoc": "^1.0.0",
"escape-string-regexp": "^1.0.5 ",
"esdoc": "^0.4.7",
"eslint": "^3.8.0",
"fs-extra": "^2.1.2",
"get-folder-size": "^1.0.0",
"glob": "^7.0.3",
"gm": "^1.22.0",
"google-closure-compiler-js": "^20170218.0.0",
Expand All @@ -185,6 +187,7 @@
"rollup-plugin-inject": "^2.0.0",
"rollup-plugin-node-resolve": "^2.0.0",
"rx": "latest",
"rxjs": "latest",
"shx": "^0.2.2",
"sinon": "^2.1.0",
"sinon-chai": "^2.9.0",
Expand Down
23 changes: 0 additions & 23 deletions tools/check-gzip-size.js

This file was deleted.