From a20d1e6c9c43f55bbc8239df39433b9887b46bb6 Mon Sep 17 00:00:00 2001 From: lejoe Date: Thu, 3 Dec 2015 14:54:57 +0100 Subject: [PATCH 01/13] First concept of the release task Most of the steps are 'pseudo code' for now --- gulp/tasks/release.js | 62 +++++++++++++++++++++++++++++++++++++++++++ gulpfile.js | 7 +++++ package.json | 6 ++++- 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 gulp/tasks/release.js diff --git a/gulp/tasks/release.js b/gulp/tasks/release.js new file mode 100644 index 0000000..233886d --- /dev/null +++ b/gulp/tasks/release.js @@ -0,0 +1,62 @@ +'use strict'; + +var gulp = require('gulp'); +var $ = require('gulp-load-plugins')(); +var logger = require('gulplog'); +var releaseBranch = 'master'; +var releaseCommitMessage = 'New release version'; + +// Makes sure we do this on the master branch +var verifyBranch = function() { + $.git.revParse({args:'--abbrev-ref HEAD', quiet: true}, function(err, currentBranch) { + if (currentBranch != releaseBranch) { + logger.error('ERR: You need to be on the %s branch to be able to deploy', releaseBranch); + process.exit(0); + } + }) +} +verifyBranch.displayName = 'Verify branch'; + +// Defaults to minor for now (better than no version bump) +// TODO: +// - get the bumptype from params +// - make that a requirement (no default) +var getBumpType = function() { + // var argv = require('yargs') + // .demand('bumpType', 'Usage: --bumpType={patch, minor, major}').argv; + return 'minor' +} + +// Bumps the version on package.json and commits it locally and pushes to master +var bumpVersion = function() { + return gulp.src('./package.json') + .pipe($.bump({type: getBumpType()})) + .pipe(gulp.dest('./')) + // .pipe($.git.add()) + // .pipe($.git.commit(releaseCommitMessage)) +} +bumpVersion.displayName = 'Bump version'; + +// Merges to the releases branch, tags the version on git and pushes it to github +var publishRelease = function(done) { + done(); +} +publishRelease.displayName = 'Publish release'; + +// Commits the build folder to another branch and pushes it to github +var publishBuild = function(done) { + done(); +} +publishBuild.displayName = 'Publish build release'; + + +var releaseTask = function () { + verifyBranch(); + return new Promise(gulp.series(bumpVersion, publishRelease, publishBuild)); +} + +releaseTask.description = 'Makes a new release of the website'; + +module.exports = function(gulp, $, config) { + return releaseTask; +}; diff --git a/gulpfile.js b/gulpfile.js index c7876e8..aff6f01 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -66,6 +66,13 @@ gulp.task( gulp.task('deploy', t.getTask('deploy')); +///////////// +// Release // +///////////// + +gulp.task('release', t.getTask('release')); + + ///////////// // Others // ///////////// diff --git a/package.json b/package.json index 35c0681..71d4fea 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "build": "./node_modules/.bin/gulp build", "test": "./node_modules/.bin/gulp test", "serve": "./node_modules/.bin/gulp serve", - "deploy": "./node_modules/.bin/gulp deploy" + "deploy": "./node_modules/.bin/gulp deploy", + "release": "./node_modules/.bin/gulp release" }, "dependencies": { "sensible": "0.5.4" @@ -23,12 +24,14 @@ "gulp-a11y": "^0.1.1", "gulp-accessibility": "^1.2.1", "gulp-autoprefixer": "^2.2.0", + "gulp-bump": "^1.0.0", "gulp-changed": "^1.2.1", "gulp-cli": "github:gulpjs/gulp-cli#4.0", "gulp-concat": "^2.5.2", "gulp-css-globbing": "^0.1.7", "gulp-data": "^1.2.0", "gulp-eslint": "^1.0.0", + "gulp-git": "^1.6.0", "gulp-jade": "^1.0.0", "gulp-jade-globbing": "0.1.6", "gulp-load-plugins": "^0.10.0", @@ -38,6 +41,7 @@ "gulp-sourcemaps": "^1.5.2", "gulp-sync": "^0.1.4", "gulp-util": "^3.0.4", + "gulplog": "^1.0.0", "jade": "^1.11.0", "jade-glob-include": "^1.0.1", "jade-inline-file": "^0.1.0", From ba2d44e47f451d996ecb6924931c6a93ae30ffe7 Mon Sep 17 00:00:00 2001 From: lejoe Date: Thu, 10 Dec 2015 12:18:42 +0100 Subject: [PATCH 02/13] Refactors the release task Asks for the bumpt type creates a new version tags it pushes to github --- gulp/tasks/release.js | 87 ++++++++++++++++++++++--------------------- package.json | 4 +- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/gulp/tasks/release.js b/gulp/tasks/release.js index 233886d..64c3313 100644 --- a/gulp/tasks/release.js +++ b/gulp/tasks/release.js @@ -3,59 +3,62 @@ var gulp = require('gulp'); var $ = require('gulp-load-plugins')(); var logger = require('gulplog'); -var releaseBranch = 'master'; -var releaseCommitMessage = 'New release version'; +var inquirer = require('inquirer'); +var exec = require('child_process').spawn; + +var allowedBranch = 'master'; +var bumpTypeQuestion = { + type: 'list', + name: 'bump', + message: 'What type of bump would you like to do?', + default: 'minor', + choices: ['patch', 'minor', 'major'] +}; // Makes sure we do this on the master branch -var verifyBranch = function() { +var asserBranchAllowed = function(done) { $.git.revParse({args:'--abbrev-ref HEAD', quiet: true}, function(err, currentBranch) { - if (currentBranch != releaseBranch) { - logger.error('ERR: You need to be on the %s branch to be able to deploy', releaseBranch); - process.exit(0); - } - }) -} -verifyBranch.displayName = 'Verify branch'; - -// Defaults to minor for now (better than no version bump) -// TODO: -// - get the bumptype from params -// - make that a requirement (no default) -var getBumpType = function() { - // var argv = require('yargs') - // .demand('bumpType', 'Usage: --bumpType={patch, minor, major}').argv; - return 'minor' -} + // if (currentBranch != allowedBranch) { + // logger.error('ERR: You need to be on the %s branch to be able to deploy', allowedBranch); + // process.exit(1); + // } + done(); + }); -// Bumps the version on package.json and commits it locally and pushes to master -var bumpVersion = function() { - return gulp.src('./package.json') - .pipe($.bump({type: getBumpType()})) - .pipe(gulp.dest('./')) - // .pipe($.git.add()) - // .pipe($.git.commit(releaseCommitMessage)) } -bumpVersion.displayName = 'Bump version'; +asserBranchAllowed.displayName = 'Verify branch'; -// Merges to the releases branch, tags the version on git and pushes it to github -var publishRelease = function(done) { - done(); -} -publishRelease.displayName = 'Publish release'; +// Asks for the bump type +var askBumpType = function(done) { + inquirer.prompt([bumpTypeQuestion], function( answers ) { + if (answers !== null && answers[bumpTypeQuestion.name] !== null) { + try { + bumpVersion(answers[bumpTypeQuestion.name], done); + } catch (e) { + done(); + } -// Commits the build folder to another branch and pushes it to github -var publishBuild = function(done) { - done(); + } else { + logger.error('ERR: There was an error with the provided bump type'); + done(); + } + }); } -publishBuild.displayName = 'Publish build release'; - +askBumpType.displayName = 'Ask bump type'; -var releaseTask = function () { - verifyBranch(); - return new Promise(gulp.series(bumpVersion, publishRelease, publishBuild)); +// Bumps the version of the project +var bumpVersion = function(bumpType, cb) { + var options = { stdio: ['ignore', 'ignore',process.stderr], cwd: process.cwd()} + var p = exec('npm', ['version', bumpType], options); + p.on('close', cb); } +bumpVersion.displayName = 'Bump Version'; -releaseTask.description = 'Makes a new release of the website'; +// Bumps the version on package.json and commits it locally and pushes to master +var releaseTask = function(done) { + return new Promise(gulp.series(asserBranchAllowed, askBumpType)); +} +releaseTask.description = 'Bumps the npm version'; module.exports = function(gulp, $, config) { return releaseTask; diff --git a/package.json b/package.json index 71d4fea..5fc72b6 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "test": "./node_modules/.bin/gulp test", "serve": "./node_modules/.bin/gulp serve", "deploy": "./node_modules/.bin/gulp deploy", - "release": "./node_modules/.bin/gulp release" + "release": "./node_modules/.bin/gulp release", + "postversion": "git push && git push --tags" }, "dependencies": { "sensible": "0.5.4" @@ -42,6 +43,7 @@ "gulp-sync": "^0.1.4", "gulp-util": "^3.0.4", "gulplog": "^1.0.0", + "inquirer": "^0.11.0", "jade": "^1.11.0", "jade-glob-include": "^1.0.1", "jade-inline-file": "^0.1.0", From f667385af7bd3a5978400150c33a9f2b98ec3694 Mon Sep 17 00:00:00 2001 From: lejoe Date: Thu, 10 Dec 2015 13:14:54 +0100 Subject: [PATCH 03/13] Improves the error logging of npm version --- gulp/tasks/release.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gulp/tasks/release.js b/gulp/tasks/release.js index 64c3313..7e13ed5 100644 --- a/gulp/tasks/release.js +++ b/gulp/tasks/release.js @@ -50,7 +50,13 @@ askBumpType.displayName = 'Ask bump type'; var bumpVersion = function(bumpType, cb) { var options = { stdio: ['ignore', 'ignore',process.stderr], cwd: process.cwd()} var p = exec('npm', ['version', bumpType], options); - p.on('close', cb); + p.on('close', function(code){ + if (code !== 0) { + logger.error('ERR: There was an error running \'npm version\' && git push && git push --tags.'); + } else { + cb(); + } + }); } bumpVersion.displayName = 'Bump Version'; From 9cca7ad87aa18619edcb262e4fded438cf76d2de Mon Sep 17 00:00:00 2001 From: lejoe Date: Thu, 10 Dec 2015 13:24:11 +0100 Subject: [PATCH 04/13] Adds propper error exits for the release task --- gulp/tasks/release.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gulp/tasks/release.js b/gulp/tasks/release.js index 7e13ed5..82453a3 100644 --- a/gulp/tasks/release.js +++ b/gulp/tasks/release.js @@ -40,7 +40,7 @@ var askBumpType = function(done) { } else { logger.error('ERR: There was an error with the provided bump type'); - done(); + process.exit(1); } }); } @@ -53,6 +53,7 @@ var bumpVersion = function(bumpType, cb) { p.on('close', function(code){ if (code !== 0) { logger.error('ERR: There was an error running \'npm version\' && git push && git push --tags.'); + process.exit(1); } else { cb(); } From 937908e4525e0613b37c25242535365e0495907e Mon Sep 17 00:00:00 2001 From: lejoe Date: Thu, 10 Dec 2015 14:15:19 +0100 Subject: [PATCH 05/13] Removes error catching It is already catched in side the function --- gulp/tasks/release.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/gulp/tasks/release.js b/gulp/tasks/release.js index 82453a3..5290b77 100644 --- a/gulp/tasks/release.js +++ b/gulp/tasks/release.js @@ -32,12 +32,7 @@ asserBranchAllowed.displayName = 'Verify branch'; var askBumpType = function(done) { inquirer.prompt([bumpTypeQuestion], function( answers ) { if (answers !== null && answers[bumpTypeQuestion.name] !== null) { - try { - bumpVersion(answers[bumpTypeQuestion.name], done); - } catch (e) { - done(); - } - + bumpVersion(answers[bumpTypeQuestion.name], done); } else { logger.error('ERR: There was an error with the provided bump type'); process.exit(1); From ee15b6b0b5f092382f07fa0d2c65cc58e8fde850 Mon Sep 17 00:00:00 2001 From: lejoe Date: Thu, 10 Dec 2015 14:15:45 +0100 Subject: [PATCH 06/13] Renames cb to done for consistency --- gulp/tasks/release.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gulp/tasks/release.js b/gulp/tasks/release.js index 5290b77..fcb178e 100644 --- a/gulp/tasks/release.js +++ b/gulp/tasks/release.js @@ -42,7 +42,6 @@ var askBumpType = function(done) { askBumpType.displayName = 'Ask bump type'; // Bumps the version of the project -var bumpVersion = function(bumpType, cb) { var options = { stdio: ['ignore', 'ignore',process.stderr], cwd: process.cwd()} var p = exec('npm', ['version', bumpType], options); p.on('close', function(code){ @@ -50,7 +49,7 @@ var bumpVersion = function(bumpType, cb) { logger.error('ERR: There was an error running \'npm version\' && git push && git push --tags.'); process.exit(1); } else { - cb(); + done(); } }); } From 2ecc30740b3a08e2ad3a2c08f71d4f67a17f767f Mon Sep 17 00:00:00 2001 From: lejoe Date: Thu, 10 Dec 2015 14:16:06 +0100 Subject: [PATCH 07/13] Removes the spaw options. We just need the default --- gulp/tasks/release.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gulp/tasks/release.js b/gulp/tasks/release.js index fcb178e..f3cf0ec 100644 --- a/gulp/tasks/release.js +++ b/gulp/tasks/release.js @@ -42,8 +42,8 @@ var askBumpType = function(done) { askBumpType.displayName = 'Ask bump type'; // Bumps the version of the project - var options = { stdio: ['ignore', 'ignore',process.stderr], cwd: process.cwd()} - var p = exec('npm', ['version', bumpType], options); +var bumpVersion = function(bumpType, done) { + var p = exec('npm', ['version', bumpType]); p.on('close', function(code){ if (code !== 0) { logger.error('ERR: There was an error running \'npm version\' && git push && git push --tags.'); From fcb1727a7d849bb96ed98bb4c62a99e3b1c42f77 Mon Sep 17 00:00:00 2001 From: lejoe Date: Thu, 10 Dec 2015 14:17:11 +0100 Subject: [PATCH 08/13] Adds display of next steps after a version bump --- gulp/tasks/release.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gulp/tasks/release.js b/gulp/tasks/release.js index f3cf0ec..61bc2af 100644 --- a/gulp/tasks/release.js +++ b/gulp/tasks/release.js @@ -55,9 +55,20 @@ var bumpVersion = function(bumpType, done) { } bumpVersion.displayName = 'Bump Version'; +// Display the next release steps +var displayNextReleaseSteps = function(done) { + logger.info('The project now has a new version and was pushed to master'); + logger.info('Next steps:'); + logger.info(' 1. Got to github and create a pull request from master to release'); + logger.info(' 2. Somebody else should review the PR and merge it'); + logger.info(' 3. The CI will publish it and create a release on github'); + done(); +} +bumpVersion.displayName = 'Display next release steps'; + // Bumps the version on package.json and commits it locally and pushes to master var releaseTask = function(done) { - return new Promise(gulp.series(asserBranchAllowed, askBumpType)); + return new Promise(gulp.series(asserBranchAllowed, askBumpType, displayNextReleaseSteps)); } releaseTask.description = 'Bumps the npm version'; From 46b2ffb5968377dd3804bc0b71e8b44527bb11e9 Mon Sep 17 00:00:00 2001 From: lejoe Date: Thu, 10 Dec 2015 14:19:05 +0100 Subject: [PATCH 09/13] Adds the npm log to git ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1676a24..7940c4c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules .DS_Store *.orig .tmp +npm-debug.log From 6c3bb7f3560994919a6650b32022a28faecccd74 Mon Sep 17 00:00:00 2001 From: lejoe Date: Thu, 10 Dec 2015 15:44:41 +0100 Subject: [PATCH 10/13] Better error logging of the npm errors --- gulp/tasks/release.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gulp/tasks/release.js b/gulp/tasks/release.js index 61bc2af..c2d8297 100644 --- a/gulp/tasks/release.js +++ b/gulp/tasks/release.js @@ -43,10 +43,18 @@ askBumpType.displayName = 'Ask bump type'; // Bumps the version of the project var bumpVersion = function(bumpType, done) { - var p = exec('npm', ['version', bumpType]); + var p = exec('npm', ['version', bumpType], { cwd: process.cwd()}); + var stderr = ''; + + p.stderr.on('data', function(buf) { + stderr += buf; + }); + p.on('close', function(code){ if (code !== 0) { - logger.error('ERR: There was an error running \'npm version\' && git push && git push --tags.'); + logger.error('ERR: There was an error running \'npm version\' && git push && git push --tags:'); + logger.error('Details:'); + logger.error('%s', stderr); process.exit(1); } else { done(); From 2e5132ebd6912b385e461bdb732c9cba8a681add Mon Sep 17 00:00:00 2001 From: lejoe Date: Thu, 10 Dec 2015 16:20:05 +0100 Subject: [PATCH 11/13] Re-instore the branch proof before release --- gulp/tasks/release.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gulp/tasks/release.js b/gulp/tasks/release.js index c2d8297..5034b7e 100644 --- a/gulp/tasks/release.js +++ b/gulp/tasks/release.js @@ -18,13 +18,12 @@ var bumpTypeQuestion = { // Makes sure we do this on the master branch var asserBranchAllowed = function(done) { $.git.revParse({args:'--abbrev-ref HEAD', quiet: true}, function(err, currentBranch) { - // if (currentBranch != allowedBranch) { - // logger.error('ERR: You need to be on the %s branch to be able to deploy', allowedBranch); - // process.exit(1); - // } + if (currentBranch != allowedBranch) { + logger.error('ERR: You need to be on the %s branch to be able to deploy', allowedBranch); + process.exit(1); + } done(); }); - } asserBranchAllowed.displayName = 'Verify branch'; From a7d4d01f0579a31ae91f32249140c283352f4a6a Mon Sep 17 00:00:00 2001 From: lejoe Date: Thu, 10 Dec 2015 16:26:38 +0100 Subject: [PATCH 12/13] updates the current skeleton version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5fc72b6..6bd0165 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "project-name", "description": "", - "version": "0.0.0", + "version": "0.3.0", "main": "dist/index.html", "scripts": { "start": "./node_modules/.bin/gulp", From 1e82149b048bba2829d82117ee96e7d83f4f9b71 Mon Sep 17 00:00:00 2001 From: lejoe Date: Fri, 18 Dec 2015 09:24:26 +0100 Subject: [PATCH 13/13] Corrects a typo in a function name asserBranchAllowed -> assertBranchAllowed --- gulp/tasks/release.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gulp/tasks/release.js b/gulp/tasks/release.js index 5034b7e..54e6a40 100644 --- a/gulp/tasks/release.js +++ b/gulp/tasks/release.js @@ -16,7 +16,7 @@ var bumpTypeQuestion = { }; // Makes sure we do this on the master branch -var asserBranchAllowed = function(done) { +var assertBranchAllowed = function(done) { $.git.revParse({args:'--abbrev-ref HEAD', quiet: true}, function(err, currentBranch) { if (currentBranch != allowedBranch) { logger.error('ERR: You need to be on the %s branch to be able to deploy', allowedBranch); @@ -25,7 +25,7 @@ var asserBranchAllowed = function(done) { done(); }); } -asserBranchAllowed.displayName = 'Verify branch'; +assertBranchAllowed.displayName = 'Verify branch'; // Asks for the bump type var askBumpType = function(done) { @@ -75,7 +75,7 @@ bumpVersion.displayName = 'Display next release steps'; // Bumps the version on package.json and commits it locally and pushes to master var releaseTask = function(done) { - return new Promise(gulp.series(asserBranchAllowed, askBumpType, displayNextReleaseSteps)); + return new Promise(gulp.series(assertBranchAllowed, askBumpType, displayNextReleaseSteps)); } releaseTask.description = 'Bumps the npm version';