Skip to content

Commit

Permalink
Scripts: Update release script
Browse files Browse the repository at this point in the history
  • Loading branch information
rxaviers committed Jun 15, 2017
1 parent 0a56d38 commit 56b9e64
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"iana-tz-data": ">=2017.0.0",
"matchdep": "0.3.0",
"mocha": "^3.3.0",
"semver": "^5.3.0",
"zoned-date-time": "0.0.4"
},
"commitplease": {
Expand Down
7 changes: 7 additions & 0 deletions script/lib/version_inc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var packageJson = require( "../../package.json" );
var semver = require( "semver" );

// Note argv[0] is supposed to be `node`, argv[1] to be this file.
var next = process.argv[ 2 ];
var prereleaseIdentifier = process.argv[ 3 ];
console.log( semver.inc( packageJson.version, next, prereleaseIdentifier ) );
11 changes: 11 additions & 0 deletions script/lib/version_update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var fs = require( "fs" );
var packageJson = require( "../../package.json" );
var path = require( "path" );

// Note argv[0] is supposed to be `node`, argv[1] to be this file.
packageJson.version = process.argv[ 2 ];

fs.writeFileSync(
path.join( __dirname, "../../package.json" ),
JSON.stringify( packageJson, null, 2 ) + "\n"
);
119 changes: 95 additions & 24 deletions script/release.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,95 @@
#! /bin/bash

function assertions {
if [ -z "$1" ]; then
echo Usage: $0 "<version>"
SCRIPT_ROOT=`dirname $0`

function abort {
echo Quiting...
exit 1
}

function process_args {
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
major|minor|patch|premajor|preminor|prepatch|prerelease)
NEXT=$key
;;
--prerelease-identifier=*)
PRERELEASE_IDENTIFIER="${key#*=}"
;;
-h|--help)
HELP=true
;;
*)
UNKNOWN="$1"
;;
esac
shift
done
if [ :$NEXT = : -a :$HELP = : ]; then
echo 'You must choose a version bump type.'
HELP=true
fi
if [ ! -z "$UNKNOWN" ]; then
echo 'Illegal option: '$UNKNOWN
HELP=true
fi
if [ :$HELP = :true ]; then
echo 'Usage:'
echo ' version major | minor | patch | premajor | preminor | prepatch | prerelease'
echo ' [--prerelease-identifier=<identifier>]'
echo ''
echo ' major, minor, patch, premajor, preminor, prepatch, prerelease'
echo ' Type of bump, see semver for more details'
echo ''
echo ' --prerelease-identifier=<identifier>'
echo ' String argument that will append the value of the string as a prerelease'
echo ' identifier, e.g., beta. The default is alpha.'
echo ''
echo ' -h, --help'
echo ' Show this help.'
exit 1
fi
VERSION=$(node $SCRIPT_ROOT/lib/version_inc.js $NEXT $PRERELEASE_IDENTIFIER)
TARGET_BRANCH=b$VERSION
PRERELEASE_IDENTIFIER=alpha
}

if ! git diff --quiet --exit-code; then
function assertions {
if ! git diff-index --quiet HEAD; then
echo Current branch "isn't" clean. Use '`git status` for more details.'
echo Quiting...
exit 1
abort
fi

if git rev-parse --verify --quiet $1 > /dev/null; then
echo 'Target tag `'$1'` already exists.'
echo Quiting...
exit 1
if git rev-parse --verify --quiet refs/tags/$VERSION > /dev/null; then
echo 'Target tag `'$VERSION'` already exists.'
abort
fi

assert_git_origin

if git ls-remote --exit-code origin refs/tags/$VERSION > /dev/null; then
echo 'Target tag `'$VERSION'` already exists in *origin*.'
abort
fi

if npm show globalize versions | grep "'"$VERSION"'" >/dev/null; then
echo 'Target npm version `'$VERSION'` already exists.'
abort
fi

if [ ! -z `git branch --list $TARGET_BRANCH` ]; then
echo 'Target branch `'$TARGET_BRANCH'` already exists.'
echo Quiting...
exit 1
abort
fi

CURRENT_BRANCH=`git name-rev --name-only HEAD`
if [ :$CURRENT_BRANCH != :master ]; then
echo 'Current branch `'$CURRENT_BRANCH'`' "isn't" '`master`.'
echo Quiting...
exit 1
abort
fi

echo Preparing release for '`'$1'`'
echo Preparing release for '`'$VERSION'`'
echo -n Proceed? "[Y|n] "
read input
test :$input = :N -o :$input = :n && exit 1
Expand All @@ -40,6 +98,20 @@ function assertions {
grunt
}

function assert_git_origin {
# Abort unless origin points to git@github.com:globalizejs/globalize.git.
if [ :`git config remote.origin.url` != :git@github.com:globalizejs/globalize.git ]; then
echo 'remote.origin.url should be `git@github.com:globalizejs/globalize.git`.'
abort
fi

echo 'Fetching origin ('`git config remote.origin.url`')'
if ! git fetch origin; then
echo "Couldn't"' fetch origin.'
abort
fi
}

function h1 {
echo
echo '## '$*
Expand All @@ -63,8 +135,8 @@ function update_authors {

function update_version {
h1 Update package.json '`versions`' attribute
sed -i.orig 's/"version": "[^"]\+"/"version": "'$1'"/' package.json &&
git commit -a -m $1 &&
node $SCRIPT_ROOT/lib/version_update.js $VERSION &&
git commit -a -m $VERSION &&
git show
}

Expand All @@ -81,8 +153,8 @@ function build {
}

function tag {
h1 'Tag `'$1'` (detached)'
git tag -a -m $1 $1 > /dev/null
h1 'Tag `'$VERSION'` (detached)'
git tag -a -m $VERSION $VERSION > /dev/null
}

function checkout_back_to_master {
Expand All @@ -99,12 +171,11 @@ function final_message {
echo git branch -D $TARGET_BRANCH
}

TARGET_BRANCH=b$1

assertions $1 &&
process_args "$@" &&
assertions &&
update_authors &&
update_version $1 &&
update_version &&
git checkout -b $TARGET_BRANCH &&
build &&
tag $1 &&
tag &&
final_message

0 comments on commit 56b9e64

Please sign in to comment.