Skip to content

Commit

Permalink
Build changelog from git commit history whenever bumping a version
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Jun 27, 2015
1 parent 51c95e8 commit c9af8ec
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
35 changes: 35 additions & 0 deletions build/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var gulp = require('gulp'),
util = require('gulp-util'),
cat = require('gulp-cat'),
git = require('gulp-git'),
replace = require('gulp-replace'),
path = require('path');

var repo = require('../package.json').repository.url;

gulp.task('changelog', function(done) {
git.exec({ args: 'log --oneline --decorate' }, function(err, stdout) {
if(err) return done(err);
return done(null, gulp.src('CHANGELOG.md')
.pipe(replace(/.|\n/g, ''))
.pipe(replace(/$/, stdout))
.pipe(replace(/#(\d+)/, '[#$1](' + repo + '/issues/$1)'))
.pipe(replace(/([a-f0-9]{7}) \(HEAD[^)]*\) (.+)/g, function(_, sha, comment) {
return '\n## [Working Changes](' + repo + ')' +
'\n- [' + sha + '](' + repo + '/commit/' + sha + ') ' + comment;
}))
.pipe(replace(/([a-f0-9]{7}) \(tag: ([^\s),]*)[^)]*\) (.+)/g, function(_, sha, tag, comment) {
var niceTag = tag;
if(tag.indexOf('v') !== 0) niceTag = 'v' + tag;
return '\n## [' + niceTag + '](' + repo + '/tree/' + tag + ')' +
'\n- [' + sha + '](' + repo + '/commit/' + sha + ') ' + comment;
}))
.pipe(replace(/([a-f0-9]{7}) (.+)/g, '- [$1](' + repo + '/commit/$1) $2'))
.pipe(gulp.dest('.')));
});
});

gulp.task('changelog-commit', function () {
return gulp.src('.')
.pipe(git.commit('Updated CHANGELOG'));
});
16 changes: 9 additions & 7 deletions build/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,22 @@ gulp.task('version-push', function (cb) {

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

gulp.task('version-push-tags', function (cb) {
git.push('origin', 'master', { args: '--tags' }, cb);
});

gulp.task('version', function (callback) {
runSequence(
'version-bump',
'version-commit',
'version-push',
'version-tag',
'changelog',
'changelog-commit',
'version-push',
'version-push-tags',
function (error) {
if (error) {
console.log(error.message);
Expand Down

0 comments on commit c9af8ec

Please sign in to comment.