Alex Rivera | Logout

Can you record the git revision with gruntjs

Asked 2012-10-29T22:40:56.413
13

I build my webapp with gruntjs and yeoman.io.

I'd like to be able to record the git revision/commit/sha that a build come from, so that i can look in the deployed version and double check where it came from and what has changed with the new release.

Edit
Report

1 Answer

12

Not a Grunt expert either, but here's a solution based on git describe which I currently use for a large AngularJS app. We store the major version in the project's package.json. In addition to that I generate a version.json file containing the revision and date for every build. This information can later be accessed by the client to help testers and maintainers to see which version/revision of the app they're using.

grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),

  'git-describe': {
    options: {
      prop: 'meta.revision'
    },
    me: {}
  },

  ...
});

grunt.registerTask('tag-revision', 'Tag the current build revision', function () {
  grunt.task.requires('git-describe');

  grunt.file.write('public/version.json', JSON.stringify({
    version: grunt.config('pkg.version'),
    revision: grunt.config('meta.revision'),
    date: grunt.template.today()
  }));
});

grunt.registerTask('version', ['git-describe', 'tag-revision']);

So by including the version task in our build tasks we can tag each build with a version.json file.

answered 2013-07-17T08:49:45.533

Your Answer