Skip to content

Commit

Permalink
Fix (release.js): Protect against EPIPE bombs from npmjs (closes #645).
Browse files Browse the repository at this point in the history
 * Adds epipebomb package, which swallows EPIPE errors.
 * Adds a default timeout to `toExecPromise`, and the ability to override it.
 * Increases timeout for npm publish.
  • Loading branch information
marcoscaceres committed Mar 15, 2016
1 parent 3390ced commit 1d0a601
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -15,6 +15,7 @@
"async": "^1.5.2",
"chai": "^3.5.0",
"colors": "^1.1.2",
"epipebomb": "^0.1.1",
"express": "^4.13.4",
"fs-extra": "^0.26.5",
"fs-promise": "^0.5.0",
Expand Down
18 changes: 13 additions & 5 deletions tools/release.js
Expand Up @@ -12,6 +12,9 @@ const colors = require("colors");
const MAIN_BRANCH = "develop";
let DEBUG = false;

//See: https://github.com/w3c/respec/issues/645
require("epipebomb")();

colors.setTheme({
data: "grey",
debug: "cyan",
Expand All @@ -24,12 +27,13 @@ colors.setTheme({
verbose: "cyan",
warn: "yellow",
});

function rel(f) {
return path.join(__dirname, f);
}

function git(cmd) {
if(DEBUG){
if (DEBUG) {
console.log(colors.debug(`Pretending to run: ${"git " + colors.prompt(cmd)}`));
return Promise.resolve();
}
Expand Down Expand Up @@ -132,12 +136,15 @@ const Promps = {
}
};

function toExecPromise(cmd) {
function toExecPromise(cmd, timeout) {
if (!timeout) {
timeout = 20000;
}
return new Promise((resolve, reject) => {
const id = setTimeout(() => {
reject(new Error(`Command took too long: ${cmd}`));
proc.kill("SIGTERM");
}, 20000);
}, timeout);
const proc = exec(cmd, (err, stdout) => {
clearTimeout(id);
if (err) {
Expand All @@ -154,7 +161,7 @@ function getBranchState() {
const remote = yield git(`rev-parse @{u}`);
const base = yield git(`merge-base @ @{u}`);
let result = "";
switch(local){
switch (local) {
case remote:
result = "up-to-date";
break;
Expand Down Expand Up @@ -205,7 +212,8 @@ async.task(function * () {
yield git("push origin gh-pages");
yield git("push --tags");
console.log(colors.info(" 📡 Publishing to npm..."));
yield toExecPromise("npm publish");
// We give npm publish 1 minute to time out, as it can be slow.
yield toExecPromise("npm publish", 60000);
} catch (err) {
console.error(colors.red(err));
process.exit(1);
Expand Down

0 comments on commit 1d0a601

Please sign in to comment.