Created
April 8, 2014 12:32
-
-
Save shorttompkins/10117306 to your computer and use it in GitHub Desktop.
Grunt task for pushing a git tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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