Skip to content

Commit

Permalink
fix(cli): should error if all results fail
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Jan 30, 2016
1 parent 9c574ee commit 12f1990
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ $ conventional-github-releaser --help # for more details

You can supply your auth token by a flag `-t` or `--token`. You can also set up an environment variable `CONVENTIONAL_GITHUB_RELEASER_TOKEN` to avoid typing your token every time.

Note: If all results error, it will print the error messages to stderr and exit with code `1`.


## Regenerate all the releases

Expand Down
19 changes: 10 additions & 9 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@ conventionalGithubReleaser({
process.exit(1);
}

if (data.length === 1) {
var result = data[0];
var allRejected = true;

if (result.state === 'rejected') {
if (flags.verbose) {
console.error(data);
} else {
console.error(result.reason.toString());
}
process.exit(1);
for (var i = data.length - 1; i >= 0 ; i--) {
if (data[i].state === 'fulfilled') {
allRejected = false;
break;
}
}

if (allRejected) {
console.error(data);
process.exit(1);
} else if (flags.verbose) {
console.log(data);
}
Expand Down
39 changes: 36 additions & 3 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('cli', function() {
shell.cd('../');
});

it('should work', function(done) {
it('should work with one release', function(done) {
var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-v'], {
stdio: [process.stdin, null, null]
});
Expand All @@ -45,7 +45,7 @@ describe('cli', function() {
});
});

it('should print out error message and exit with `1` if there is one result and it errors', function(done) {
it('should print out error message and exit with `1` if all results error', function(done) {
var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token], {
stdio: [process.stdin, null, null]
});
Expand All @@ -61,7 +61,7 @@ describe('cli', function() {
});
});

it('should print out error message and exit with `1` if there is one result and it errors with verbose', function(done) {
it('should print out error message and exit with `1` if all results error when verbose', function(done) {
var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-v'], {
stdio: [process.stdin, null, null]
});
Expand All @@ -76,4 +76,37 @@ describe('cli', function() {
done();
});
});

it('should exit with `0` if not all results error', function(done) {
fs.writeFileSync('test2', '');
shell.exec('git add --all && git commit -m"Second commit"');
shell.exec('git tag v0.0.2');

var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-r', '0'], {
stdio: [process.stdin, null, null]
});

cp.on('close', function(code) {
expect(code).to.equal(0);

done();
});
});

it('should exit with `1` if all results error', function(done) {
var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-r', '0'], {
stdio: [process.stdin, null, null]
});

cp.stderr.on('data', function(data) {
expect(data.toString()).to.include('already_exists');
});

cp.on('close', function(code) {
expect(code).to.equal(1);

done();
});
});

});

0 comments on commit 12f1990

Please sign in to comment.