Skip to content

Commit

Permalink
Clean up build process for new branch structure
Browse files Browse the repository at this point in the history
  • Loading branch information
eKoopmans committed Feb 19, 2020
1 parent db15497 commit 278aa48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 41 deletions.
52 changes: 13 additions & 39 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var fs = require('fs');
// Fetch command-line arguments.
var args = minimist(process.argv.slice(2), {
string: ['env', 'newversion', 'tagmessage'],
alias: { v: 'newversion', m: 'tagmessage' },
default: {
env: process.env.NODE_ENV || 'production',
newversion: 'patch',
Expand All @@ -16,25 +17,12 @@ var args = minimist(process.argv.slice(2), {
});
args.newversion = args.newversion || 'patch';

/* ----- REUSABLE TASKS ----- */

// Get package version from package.json.
function getVersion() {
var pkg = JSON.parse(fs.readFileSync('./package.json'));
return 'v' + pkg.version;
}

// Merge the specified branch back into master and develop.
function mergeBranch(branch) {
var mergeCmd = 'git merge --no-ff --no-edit ' + branch;

console.log('Merging release into master.')
return exec('git checkout master && ' + mergeCmd).then(function() {
console.log('Merging release into develop.')
return exec('git checkout develop && ' + mergeCmd);
});
}

/* ----- TASKS ----- */

// Bump version using NPM (only affects package*.json, doesn't commit).
Expand All @@ -43,39 +31,25 @@ gulp.task('bump-version', function bumpVersion() {
return exec('npm --no-git-tag-version version ' + args.newversion);
});

// Stage a release (bump version and create a 'release/[version]' branch).
gulp.task('stage-release', gulp.series('bump-version', function stageRelease() {
var version = getVersion();
var branch = 'release/' + version;
var cmd = 'git checkout -b ' + branch + ' && git add -A';
cmd += ' && git commit -m "Prepare release ' + version + '"';

console.log('Creating release branch and committing changes.');
return exec(cmd);
}));

gulp.task('finalize-release', function finalizeRelease() {
// Bump version, build, commit, tag, and merge into stable.
gulp.task('release', gulp.series('bump-version', function release() {
var version = getVersion();
var branch = 'release/' + version;
var branch = 'master';
var cmd = 'git checkout ' + branch + ' && npm run build';

console.log('Running build process in release branch.');
console.log('Running build process in master branch.');
return exec(cmd).then(function() {
console.log('Adding all changes and performing final commit.');
return exec('git add -A && git commit --allow-empty -m "Build ' + version + '"');
}).then(function() {
}).then(function () {
console.log('Tagging with provided tag message.');
return exec('git tag -a ' + version + ' -m "' + version + ' ' + args.tagmessage + '"');
});
});

// Tag and merge the latest release into master/develop.
gulp.task('release', gulp.series('finalize-release', function release() {
var version = getVersion();
var branch = 'release/' + version;

return mergeBranch(branch).then(function() {
console.log('Deleting release branch.');
return exec('git branch -d ' + branch);
}).then(function () {
console.log('Getting repo root location.');
return exec('git rev-parse --show-toplevel');
}).then(function (res) {
console.log('Pushing release to stable branch.');
var repoRoot = res.stdout.trim('\n');
return exec('git push --follow-tags ' + repoRoot + ' master:stable')
});
}));
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
"build": "rollup -c",
"clean": "rimraf dist",
"test": "echo \"Error: no test specified\" && exit 1",
"stage-release": "gulp stage-release --newversion",
"release": "gulp release --tagmessage",
"release": "gulp release --newversion",
"publish": "npm publish",
"prebuild": "npm install && npm run clean"
}
Expand Down

0 comments on commit 278aa48

Please sign in to comment.