Skip to content

Commit

Permalink
feat(grunt): adds a release task check to ensure the branch is master
Browse files Browse the repository at this point in the history
If you run the release grunt task while not in the master branch,
the repo will get trashed. After personally experiencing this,
I created this check to prevent this from happening in the future.
  • Loading branch information
gvsboy committed Jan 14, 2014
1 parent 1c7bef7 commit d568538
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion gruntfile.js
Expand Up @@ -28,6 +28,15 @@ module.exports = function (grunt) {
}
}

/**
* Removes whitespace from a given string.
* @param {String} string The string you wish to trim.
* @return {String} The trimmed string.
*/
function trim(string) {
return string.replace(/[\s]/g, '');
}

// the workhorse of the grunt file
grunt.initConfig({
// inject specific header
Expand Down Expand Up @@ -76,12 +85,23 @@ module.exports = function (grunt) {
command: 'git describe HEAD',
options: {
callback: function (err, stdout, stderr, next) {
var version = stdout.replace(/[\s]/g, '');
var version = trim(stdout);
setVersion(version);
next();
}
}
},
isBranchMaster: {
command: 'git rev-parse --abbrev-ref HEAD',
options: {
callback: function (err, stdout, stderr, next) {
if (trim(stdout) !== 'master') {
throw new Error('You have not checked out the master branch.');
}
next();
}
}
},
git_add: {
command: 'git add -A',
options: {
Expand Down Expand Up @@ -435,6 +455,7 @@ module.exports = function (grunt) {
]);

grunt.registerTask('release', [
'shell:isBranchMaster',
'build',
'releasetest',
'copy:recent_to_release',
Expand Down

0 comments on commit d568538

Please sign in to comment.