2015-09-15 02:54:27 +03:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2015-09-15 20:45:02 +03:00
|
|
|
var fs = require('fs')
|
2015-09-15 02:54:27 +03:00
|
|
|
var exec = require('child_process').exec
|
2015-09-15 20:45:02 +03:00
|
|
|
var series = require('async').series
|
|
|
|
var semver = require('semver')
|
2015-09-15 02:54:27 +03:00
|
|
|
|
2015-09-15 20:45:02 +03:00
|
|
|
series([
|
|
|
|
section('Preparing to roll the railcars'),
|
2015-09-15 02:54:27 +03:00
|
|
|
checkCleanWorkingTree,
|
2015-09-15 20:45:02 +03:00
|
|
|
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')
|
2015-09-15 02:54:27 +03:00
|
|
|
], finish)
|
|
|
|
|
2015-09-15 20:45:02 +03:00
|
|
|
function checkCleanWorkingTree (next) {
|
|
|
|
run('git status --porcelain')(function (error, output) {
|
2015-09-15 03:34:41 +03:00
|
|
|
if (error) return next(error)
|
2015-09-15 20:45:02 +03:00
|
|
|
if (output.trim().length > 0) return next(new Error('Cannot run the railcars with a dirty working tree'))
|
|
|
|
next()
|
2015-09-15 02:54:27 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-09-15 20:45:02 +03:00
|
|
|
function bumpStableVersion (next) {
|
|
|
|
run('npm version patch')(next)
|
2015-09-15 02:54:27 +03:00
|
|
|
}
|
|
|
|
|
2015-09-15 20:45:02 +03:00
|
|
|
function bumpBetaVersion (next) {
|
2015-09-17 20:39:45 +03:00
|
|
|
var newVersion = semver.inc(getCurrentVersion(), 'preminor', 'beta')
|
2015-09-15 20:45:02 +03:00
|
|
|
run('npm version ' + newVersion)(next)
|
2015-09-15 02:54:27 +03:00
|
|
|
}
|
|
|
|
|
2015-09-15 20:45:02 +03:00
|
|
|
function bumpDevVersion (next) {
|
2015-09-17 20:39:45 +03:00
|
|
|
var newVersion = semver.inc(getCurrentVersion(), 'preminor', 'dev').replace(/\.0$/, '')
|
2015-09-15 20:45:02 +03:00
|
|
|
series([
|
|
|
|
run('npm --no-git-tag-version version ' + newVersion),
|
|
|
|
run('git commit -am "' + newVersion + '"')
|
|
|
|
], next)
|
2015-09-15 02:54:27 +03:00
|
|
|
}
|
|
|
|
|
2015-09-15 20:45:02 +03:00
|
|
|
function finish (error) {
|
|
|
|
if (error) {
|
|
|
|
console.log('Error: ' + error.message)
|
|
|
|
process.exit(1)
|
2015-09-15 02:54:27 +03:00
|
|
|
}
|
|
|
|
|
2015-09-15 20:45:02 +03:00
|
|
|
console.log('OK, now just wait for all CI builds to pass on beta and stable')
|
2015-09-15 02:54:27 +03:00
|
|
|
}
|
|
|
|
|
2015-09-15 20:45:02 +03:00
|
|
|
function getCurrentVersion () {
|
|
|
|
return JSON.parse(fs.readFileSync(require.resolve('../package.json'))).version
|
2015-09-15 02:54:27 +03:00
|
|
|
}
|
|
|
|
|
2015-09-15 20:45:02 +03:00
|
|
|
function run (command) {
|
|
|
|
return function (next) {
|
|
|
|
console.log('>', command)
|
|
|
|
exec(command, next)
|
|
|
|
}
|
2015-09-15 02:54:27 +03:00
|
|
|
}
|
|
|
|
|
2015-09-15 20:45:02 +03:00
|
|
|
function section (message) {
|
|
|
|
return function (next) {
|
|
|
|
console.log()
|
|
|
|
console.log(message)
|
|
|
|
next()
|
2015-09-15 02:54:27 +03:00
|
|
|
}
|
|
|
|
}
|