Skip to content

Commit

Permalink
Merge pull request gulpjs#909 from carpasse/master
Browse files Browse the repository at this point in the history
Add recipe for bump version number and create a new Git tag
  • Loading branch information
contra committed Apr 24, 2015
2 parents 47803d7 + 2f28735 commit 3fa134e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/recipes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
* [Browserify + Uglify with sourcemaps](browserify-uglify-sourcemap.md)
* [Browserify + Globs](browserify-with-globs.md)
* [Output both a minified and non-minified version](minified-and-non-minified.md)
* [Bump project version, and create new tag in Git](bump-version-and-create-git-tag.md)
* [Templating with Swig and YAML front-matter](templating-with-swig-and-yaml-front-matter.md)
65 changes: 65 additions & 0 deletions docs/recipes/bump-version-and-create-git-tag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Bump version number and create new Git tag

If your project follows a semantic versioning, it may be a good idea to automatize the steps needed to do a release.
Below you have a simple recipe that bumps the project version, commits the changes to git and creates a
new task.

``` javascript

var gulp = require('gulp');
var runSequence = require('run-sequence');
var bump = require('gulp-bump');
var gutil = require('gulp-util');
var git = require('gulp-git');
var fs = require('fs');

gulp.task('bump-version', function () {
//Note: I have hardcoded the version change type to 'patch' but it may be a good idea to use
// minimist (https://www.npmjs.com/package/minimist) to determine with a command argument whether you are doing
// a 'major', 'minor' or a 'patch' change.
return gulp.src(['./bower.json', './package.json'])
.pipe(bump({type: "patch"}).on('error', gutil.log))
.pipe(gulp.dest('./'));
});

gulp.task('commit-changes', function () {
return gulp.src('.')
.pipe(git.commit('[Prerelease] Bumped version number', {args: '-a'}));
});

gulp.task('push-changes', function (cb) {
git.push('origin', 'master', cb);
});

gulp.task('create-new-tag', function (cb) {
var version = getPackageJsonVersion();
git.tag(version, 'Created Tag for version: ' + version, function (error) {
if (error) {
return cb(error);
}
git.push('origin', 'master', {args: '--tags'}, cb);
});

function getPackageJsonVersion () {
//We parse the json file instead of using require because require caches multiple calls so the version number won't be updated
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
};
});

gulp.task('release', function (callback) {
runSequence(
'bump-version',
'commit-changes',
'push-changes',
'create-new-tag',
function (error) {
if (error) {
console.log(error.message);
} else {
console.log('RELEASE FINISHED SUCCESSFULLY');
}
callback(error);
});
});

```

0 comments on commit 3fa134e

Please sign in to comment.