Skip to content

Commit

Permalink
check if the current branch is master for both of bump and release tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi Becheras committed Dec 22, 2016
1 parent e96e450 commit 03040a2
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 03040a2

Please sign in to comment.