Skip to content

Instantly share code, notes, and snippets.

@shorttompkins
Created April 8, 2014 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shorttompkins/10117306 to your computer and use it in GitHub Desktop.
Save shorttompkins/10117306 to your computer and use it in GitHub Desktop.
Grunt task for pushing a git tag
// jshint node:true
'use strict';
var semver = require('semver'),
exec = require('exec');
module.exports = function(grunt) {
'use strict';
require('load-grunt-tasks')(grunt);
var gitVersion;
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
shell: {
options: {
stdout: true,
stderr: true
},
tag: {
command: [
'git tag <%= grunt.option("tag") %>',
'git push origin --tags'
].join(' && ')
}
}
});
// Auto increment GIT TAG and PUSH to ORIGIN
grunt.registerTask('tag:patch', ['tag']);
grunt.registerTask('tag:minor', function() {
grunt.option('tagType', 'minor');
grunt.task.run(['tag']);
});
grunt.registerTask('tag:major', function() {
grunt.option('tagType', 'major');
grunt.task.run(['tag']);
});
grunt.registerTask('tag', function() {
if (grunt.option('tagType') !== 'major' &&
grunt.option('tagType') !== 'minor') {
grunt.option('tagType', 'patch');
}
var done = this.async();
exec('git describe --tags --abbrev=0',
function(err, stdout, stderr) {
if (stderr) {
grunt.log.error(stderr);
} else {
gitVersion = semver.inc(
stdout.trim(),
grunt.option('tagType')
);
grunt.log.ok('Tagging: ' + gitVersion +
' (' + grunt.option('tagType') + ')');
grunt.option('tag', gitVersion);
grunt.task.run(['shell:tag']);
}
done();
}
);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment