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

feat: only allow releases from master branch #8

Merged
merged 1 commit into from
Jan 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require('shelljs/global');

var path = require('path');

var RELEASE_BRANCH = 'master';

// npm version (bump version, commit, make tag)
// echo npm publish
// - if successful, push commit & tag
Expand All @@ -13,12 +15,31 @@ function usage() {
echo(' Usage: node ' + process.argv[1] + ' <major|minor|patch>');
}

function gitBranch() {
var output = exec('git rev-parse --abbrev-ref HEAD', { silent: true });
if (output.code) {
throw new Error('Unable to fetch git branch');
}
return output.stdout.trimRight();
}

config.silent = true;
function run(version) {
config.silent = false;
config.fatal = true;
try {
// TODO(nfischer): only allow releases from master branch (issue #4)
var currentBranch = gitBranch();
if (currentBranch !== RELEASE_BRANCH) {
echo('Please switch to the release branch: ' + RELEASE_BRANCH);
echo('Currently on: ' + currentBranch);
exit(1);
}
} catch (e) {
echo('Are you in a git repo?');
exit(1);
}

try {
echo('Publishing new ' + version + ' version');
echo('');
exec('npm version ' + version);
Expand Down Expand Up @@ -71,9 +92,8 @@ function run(version) {

config.silent = false;
try {
// TODO(nfischer): this currently requires upstream tracking (issue #2)
exec('git push');
exec('git push --tags');
exec('git push origin ' + RELEASE_BRANCH);
exec('git push --tags origin ' + RELEASE_BRANCH);
} catch (e) {
echo('');
echo('Version has been released, but commit/tag could not be pushed.');
Expand Down