Script stable and beta releases together

This commit is contained in:
Max Brunsfeld 2015-09-15 10:45:02 -07:00
parent 6bfa467a15
commit a9845e3d7f

View File

@ -1,103 +1,89 @@
#!/usr/bin/env node
var fs = require('fs')
var exec = require('child_process').exec
var async = require('../build/node_modules/async')
var series = require('async').series
var semver = require('semver')
var branchName, leadingBranchName
async.series([
parseArguments,
series([
section('Preparing to roll the railcars'),
checkCleanWorkingTree,
checkoutBranch,
pullUpstreamChanges,
mergeLeadingBranch,
fetchUpstreamTags,
updateVersionNumber,
pushLocalChanges,
pushLocalTags,
run('git fetch origin master:master beta:beta stable:stable'),
run('git fetch origin --tags'),
section('Updating stable branch'),
run('git checkout stable'),
run('git merge --ff-only origin/stable'),
run('git merge --ff-only origin/beta'),
bumpStableVersion,
section('Updating beta branch'),
run('git checkout beta'),
run('git merge --ff-only origin/beta'),
run('git merge --ff-only origin/master'),
run('git merge --strategy ours origin/stable'),
bumpBetaVersion,
section('Updating master branch'),
run('git checkout master'),
run('git merge --ff-only origin/master'),
run('git merge --strategy ours origin/beta'),
bumpDevVersion,
section('Pushing changes upstream'),
run('git push origin master:master beta:beta stable:stable'),
run('git push origin --tags')
], finish)
function parseArguments(next) {
branchName = process.argv[2]
switch (branchName) {
case 'beta':
leadingBranchName = 'master'
break
case 'stable':
leadingBranchName = 'beta'
break
default:
return next(new Error('Usage: script/railcar <beta|stable>'))
}
next()
}
function checkCleanWorkingTree(next) {
console.log('Checking for a clean working tree');
exec('git status --porcelain', function(error, output) {
function checkCleanWorkingTree (next) {
run('git status --porcelain')(function (error, output) {
if (error) return next(error)
var modifiedEntries = output.split('\n').filter(function(line) {
return !/^\?\?/.test(line) && line.length > 0
});
next(
modifiedEntries.length === 0 ?
null :
new Error('Cannot run the railcars with a dirty working tree')
)
if (output.trim().length > 0) return next(new Error('Cannot run the railcars with a dirty working tree'))
next()
})
}
function checkoutBranch(next) {
console.log('Checking out ' + branchName);
exec('git checkout ' + branchName, next)
function bumpStableVersion (next) {
run('npm version patch')(next)
}
function pullUpstreamChanges(next) {
console.log('Pulling upstream changes on ' + branchName);
exec('git pull --ff-only origin ' + branchName, next)
function bumpBetaVersion (next) {
var newVersion = semver.inc(getCurrentVersion(), 'prerelease', 'beta')
run('npm version ' + newVersion)(next)
}
function mergeLeadingBranch(next) {
console.log('Merging new changes from ' + leadingBranchName);
exec('git pull --ff-only origin ' + leadingBranchName, next)
function bumpDevVersion (next) {
var newVersion = semver.inc(getCurrentVersion(), 'preminor', 'dev')
series([
run('npm --no-git-tag-version version ' + newVersion),
run('git commit -am "' + newVersion + '"')
], next)
}
function fetchUpstreamTags(next) {
console.log('Fetching upstream tags');
exec('git fetch --tags', next)
}
function updateVersionNumber(next) {
var newVersion
if (branchName === 'beta') {
newVersion = require('../package.json')
.version
.replace(/-\w+$/, '-beta-0')
} else {
newVersion = 'patch'
}
console.log('Updating version to ' + newVersion);
exec('npm version ' + newVersion, next)
}
function pushLocalChanges(next) {
console.log('Pushing local changes');
exec('git push origin ' + branchName, next)
}
function pushLocalTags(next) {
console.log('Pushing local tags');
exec('git push --tags origin', next)
}
function finish(error) {
function finish (error) {
if (error) {
console.log('Error: ' + error.message)
process.exit(1)
}
console.log('Success! Now just wait for all CI builds to pass on ' + branchName)
console.log('OK, now just wait for all CI builds to pass on beta and stable')
}
function getCurrentVersion () {
return JSON.parse(fs.readFileSync(require.resolve('../package.json'))).version
}
function run (command) {
return function (next) {
console.log('>', command)
exec(command, next)
}
}
function section (message) {
return function (next) {
console.log()
console.log(message)
next()
}
}