From 1785c8116bb787f2d8f2c4cfdaf4a45a3f536746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Becheras?= Date: Wed, 21 Dec 2016 17:32:13 +0100 Subject: [PATCH 1/9] add gulp-git dev deendency --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index f0918b3..9540dcc 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "gulp-bump": "^2.5.1", "gulp-coverage": "^0.3.38", "gulp-coveralls": "^0.1.4", + "gulp-git": "^1.12.0", "gulp-mocha": "^3.0.1", "gulp-shell": "^0.5.2", "gulp-standard-bundle": "^0.2.6", From 5b77efaffe788f98964fc57ce2a70aa12d220109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Becheras?= Date: Wed, 21 Dec 2016 17:32:58 +0100 Subject: [PATCH 2/9] create a release task --- gulpfile.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index eea8015..82a3c97 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -8,6 +8,7 @@ var shell = require('gulp-shell') var cover = require('gulp-coverage') var coveralls = require('gulp-coveralls') var bump = require('gulp-bump') +var git = require('gulp-git') var linter = standard.linter var argv = yargs.argv @@ -42,18 +43,33 @@ gulp.task('coverage', ['jscover'], function () { gulp.task('bump', function () { var opts = {} - opts.type = argv.patch - ? 'patch' : (argv.minor) - ? 'minor' : (argv.major) - ? 'major' : (argv.prerelease) - ? 'prerelease' : 'patch' + opts.type = getBumpType() return gulp.src('./package.json') .pipe(bump(opts)) .pipe(gulp.dest('./')) }) +gulp.task('release', ['bump'], function () { + var pkg = require('./package.json') + var version = pkg.version + var releaseType = getBumpType() + var commitMsg = 'Releasing ' + releaseType + ' version: v' + version + gulp.src('./package.json') + .pipe(git.add()) + .pipe(git.commit(commitMsg)) + .pipe(git.push('gh-sirap-group', '2-create-a-release-task')) +}) + gulp.task('default', ['test']) gulp.task('watch', function () { gulp.watch([ './tests/**/*.js', './lib/**/*.js' ], ['test']) }) + +function getBumpType () { + return argv.patch + ? 'patch' : (argv.minor) + ? 'minor' : (argv.major) + ? 'major' : (argv.prerelease) + ? 'prerelease' : 'patch' +} From aeef38110df92b670ea01790d0a90fbbf46d2ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Becheras?= Date: Wed, 21 Dec 2016 17:48:04 +0100 Subject: [PATCH 3/9] fix the git push step --- gulpfile.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 82a3c97..d495bf3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -49,7 +49,7 @@ gulp.task('bump', function () { .pipe(gulp.dest('./')) }) -gulp.task('release', ['bump'], function () { +gulp.task('release', ['bump'], function (done) { var pkg = require('./package.json') var version = pkg.version var releaseType = getBumpType() @@ -57,7 +57,9 @@ gulp.task('release', ['bump'], function () { gulp.src('./package.json') .pipe(git.add()) .pipe(git.commit(commitMsg)) - .pipe(git.push('gh-sirap-group', '2-create-a-release-task')) + .on('end', function () { + git.push('gh-sirap-group', null, done) + }) }) gulp.task('default', ['test']) From 297cce7a78936b6780e2dbd42a193aa1dcb0ee3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Becheras?= Date: Wed, 21 Dec 2016 18:05:25 +0100 Subject: [PATCH 4/9] add the git tag creation in the release tag --- gulpfile.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index d495bf3..0da5eaf 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -51,14 +51,19 @@ gulp.task('bump', function () { gulp.task('release', ['bump'], function (done) { var pkg = require('./package.json') - var version = pkg.version + var version = 'v' + pkg.version var releaseType = getBumpType() - var commitMsg = 'Releasing ' + releaseType + ' version: v' + version + var commitMsg = 'Releasing ' + releaseType + ' version: ' + version gulp.src('./package.json') .pipe(git.add()) .pipe(git.commit(commitMsg)) .on('end', function () { - git.push('gh-sirap-group', null, done) + git.tag(version, commitMsg, function (err) { + if (err) { + throw err + } + git.push('gh-sirap-group', null, done) + }) }) }) From 9df7d298f220e7de8f1cf44d1e88aa626853385a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Becheras?= Date: Wed, 21 Dec 2016 18:06:52 +0100 Subject: [PATCH 5/9] add the git push tag to the release task --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index 0da5eaf..f9236f3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -62,7 +62,7 @@ gulp.task('release', ['bump'], function (done) { if (err) { throw err } - git.push('gh-sirap-group', null, done) + git.push('gh-sirap-group', null, {args: '--tags'}, done) }) }) }) From 2a15d485675dfcdbd803c5352103abb3d4d9afef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Becheras?= Date: Thu, 22 Dec 2016 11:12:08 +0100 Subject: [PATCH 6/9] add the git-rev dev dependency --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 9540dcc..be097dd 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "chai": "^3.5.0", "chalk": "^1.1.3", "del": "^2.2.2", + "git-rev": "^0.2.1", "gulp": "^3.9.1", "gulp-bump": "^2.5.1", "gulp-coverage": "^0.3.38", From 619646333032f17092c7e64f29bd98c4a9ad699a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Becheras?= Date: Thu, 22 Dec 2016 11:14:54 +0100 Subject: [PATCH 7/9] Force the release task to be run only if we are on the master branch! --- gulpfile.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index f9236f3..03fa966 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,6 +1,7 @@ var gulp = require('gulp') var yargs = require('yargs') var del = require('del') +var chalk = require('chalk') var standard = require('gulp-standard-bundle') var mocha = require('gulp-mocha') @@ -9,6 +10,7 @@ var cover = require('gulp-coverage') var coveralls = require('gulp-coveralls') var bump = require('gulp-bump') var git = require('gulp-git') +var gitRev = require('git-rev') var linter = standard.linter var argv = yargs.argv @@ -50,19 +52,27 @@ gulp.task('bump', function () { }) gulp.task('release', ['bump'], function (done) { - var pkg = require('./package.json') - var version = 'v' + pkg.version - var releaseType = getBumpType() - var commitMsg = 'Releasing ' + releaseType + ' version: ' + version - gulp.src('./package.json') - .pipe(git.add()) - .pipe(git.commit(commitMsg)) - .on('end', function () { - git.tag(version, commitMsg, function (err) { - if (err) { - throw err - } - git.push('gh-sirap-group', null, {args: '--tags'}, done) + gitRev.branch(function (branch) { + if (branch !== 'master') { + var errorMsg = 'You must be on the master branch to make a new release!' + errorMsg += 'If you want to make a release candidate (RC), use the `prerelease` task instead.' + console.error(chalk.red.bgWhite(errorMsg)) + return + } + var pkg = require('./package.json') + var version = 'v' + pkg.version + var releaseType = getBumpType() + var commitMsg = 'Releasing ' + releaseType + ' version: ' + version + gulp.src('./package.json') + .pipe(git.add()) + .pipe(git.commit(commitMsg)) + .on('end', function () { + git.tag(version, commitMsg, function (err) { + if (err) { + throw err + } + git.push('gh-sirap-group', null, {args: '--tags'}, done) + }) }) }) }) From e96e45024da820035f3ef981ec1a54a23513d2fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Becheras?= Date: Thu, 22 Dec 2016 11:27:05 +0100 Subject: [PATCH 8/9] improve the error message --- gulpfile.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 03fa966..fdcd615 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -54,10 +54,11 @@ gulp.task('bump', function () { gulp.task('release', ['bump'], function (done) { gitRev.branch(function (branch) { if (branch !== 'master') { - var errorMsg = 'You must be on the master branch to make a new release!' - errorMsg += 'If you want to make a release candidate (RC), use the `prerelease` task instead.' + var errorMsg = 'You must be on the master branch to make a new release!\n' + errorMsg += 'If you want to make a release candidate (RC), use the `prerelease` task instead.\n' + errorMsg += 'Tasks `release`... Aborting.' console.error(chalk.red.bgWhite(errorMsg)) - return + return done() } var pkg = require('./package.json') var version = 'v' + pkg.version From 03040a28f13f82a8983a76e24a6c2f7480f9d277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Becheras?= Date: Thu, 22 Dec 2016 11:37:01 +0100 Subject: [PATCH 9/9] check if the current branch is master for both of bump and release tasks --- gulpfile.js | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index fdcd615..5118205 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -43,22 +43,26 @@ gulp.task('coverage', ['jscover'], function () { .pipe(coveralls()) }) -gulp.task('bump', function () { - var opts = {} - opts.type = getBumpType() - return gulp.src('./package.json') - .pipe(bump(opts)) - .pipe(gulp.dest('./')) +gulp.task('bump', function (done) { + releaseIfHeadOnMaster(function (err) { + if (err) { + done() + return + } + var opts = {} + opts.type = getBumpType() + return gulp.src('./package.json') + .pipe(bump(opts)) + .pipe(gulp.dest('./')) + .on('end', done) + }) }) gulp.task('release', ['bump'], function (done) { - gitRev.branch(function (branch) { - if (branch !== 'master') { - var errorMsg = 'You must be on the master branch to make a new release!\n' - errorMsg += 'If you want to make a release candidate (RC), use the `prerelease` task instead.\n' - errorMsg += 'Tasks `release`... Aborting.' - console.error(chalk.red.bgWhite(errorMsg)) - return done() + releaseIfHeadOnMaster(function (err) { + if (err) { + done() + return } var pkg = require('./package.json') var version = 'v' + pkg.version @@ -84,6 +88,20 @@ gulp.task('watch', function () { gulp.watch([ './tests/**/*.js', './lib/**/*.js' ], ['test']) }) +function releaseIfHeadOnMaster (done) { + gitRev.branch(function (branch) { + if (branch !== 'master') { + var errorMsg = 'You must be on the master branch to make a new release!\n' + errorMsg += 'If you want to make a release candidate (RC), use the `prerelease` task instead.\n' + errorMsg += 'Tasks `release`... Aborting.' + console.error(chalk.red.bgWhite(errorMsg)) + done(new Error()) + return + } + done() + }) +} + function getBumpType () { return argv.patch ? 'patch' : (argv.minor)