grunt-tagrelease

This plugin is being deprecated in favor of grunt-release, and will be eventually unpublished. Please migrate.

grunt-tagrelease

This plugin is being deprecated in favor of grunt-release, and will be eventually unpublished. Please migrate.

Commit the changes and tag the last commit with a version from provided JSON file. If there is nothing to commit, the task will tag the current last commit.

This task has been created to work with other tasks like grunt-bumpup to help create a nicely configurable release task. You can see an example in Usage Examples section.

This is a Grunt 0.4 plugin. If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins.

Use npm to install and save the plugin into devDependencies.

npm install grunt-tagrelease --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-tagrelease');

In your project's Gruntfile, add a section named tagrelease to the data object passed into grunt.initConfig(). This is a simple task, and does not conform to multi task options & files input types! All available configuration styles are described below.

This is the most verbose form of the configuration with default options and a version from a JSON file:

grunt.initConfig({
    tagrelease: {
        file: 'package.json',
        commit:  true,
        message: 'Release %version%',
        prefix:  'v',
        annotate: false,
    },
});

Version from a version property, and no prefix:

grunt.initConfig({
    tagrelease: {
        version: '1.0.1',
        prefix:  '',
    },
});

Version retrieved from a function passed to the version property, and enabled annotated tags:

grunt.initConfig({
    tagrelease: {
        versionfunction () {
            return '1.0.1';
        },
        annotate:  true,
    },
});

Default options and a new version from a JSON file:

grunt.initConfig({
    tagrelease: 'package.json'
});

Default options and a new version expanded from a template:

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    tagrelease: '<%= pkg.version %>'
});

Default options and a new version passed directly:

grunt.initConfig({
    tagrelease: '1.0.1'
});

Default options and a new version from a function:

grunt.initConfig({
    tagreleasefunction () {
        return '1.0.1';
    }
});

Type: Mixed Default: null

New version that will be used as a new tag name. Has a priority over the file option below. Can be a string or a function that returns a string. You have to define either this, or a file option below, otherwise the task won't know what should be the new tag.

Type: String Default: null

Path to the JSON file with version that should be used as a new tag. You have to define either this, or a version option above, otherwise the task won't know what should be the new tag.

Type: Boolean Default: true

Whether to commit any un-staged changes before tagging. Does the git commit -a command.

Type: String Default: Release %version%

Message to be used in commits, and annotated tags. Available is one token:

  • %version% - Will be replaced with a new version, without a prefix.

Type: String Default: nothing

Tag prefix. Set to v to have tags line v1.1.0.

Type: Boolean Default: false

Whether the new tag should be annotated. If enabled, the tag will receive a message from message option.

In this example, we create a release task that handles everything needed to build a new release of a project:

// Tasks configuration 
grunt.initConfig({
    jshint: ...,
    uglify: ...,
    bumpup: 'package.json',
    tagrelease: 'package.json'
});
 
// Load the plugins 
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-bumpup');
grunt.loadNpmTasks('grunt-tagrelease');
 
// Release alias task 
grunt.registerTask('release', function (type) {
    type = type ? type : 'patch';
    grunt.task.run('jshint');         // Lint stuff 
    grunt.task.run('uglify');         // Minify stuff 
    grunt.task.run('bumpup:' + type); // Bump up the package version 
    grunt.task.run('tagrelease');     // Commit & tag the changes from above 
});

And now you can call this command to create a new minor release of a project:

grunt release:minor