2013-02-19 04:43:49 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2013-08-08 09:30:55 +00:00
|
|
|
|
# Release next version of the product
|
|
|
|
|
# Usage:
|
|
|
|
|
# release <major|minor|patch>
|
|
|
|
|
# release <VERSION> --force
|
2013-02-19 04:43:49 +00:00
|
|
|
|
#
|
|
|
|
|
# Require:
|
|
|
|
|
# - semver - https://github.com/sekati/semver
|
|
|
|
|
# - jq - brew install jq
|
|
|
|
|
|
|
|
|
|
# Common stuff
|
|
|
|
|
RED="$(tput setaf 1)"
|
|
|
|
|
CYAN="$(tput setaf 6)"
|
|
|
|
|
UNDERLINE="$(tput sgr 0 1)"
|
|
|
|
|
NOCOLOR="$(tput sgr0)"
|
|
|
|
|
function header() { echo -e "$UNDERLINE$CYAN$1$NOCOLOR\n"; }
|
|
|
|
|
function error() { echo -e "$UNDERLINE$RED$1$NOCOLOR"; }
|
|
|
|
|
|
2013-08-08 09:30:55 +00:00
|
|
|
|
function usage() {
|
|
|
|
|
echo "Usage:"
|
|
|
|
|
echo " `basename $0` <major|minor|patch>"
|
|
|
|
|
echo " `basename $0` <VERSION> --force"
|
|
|
|
|
echo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
command -v semver >/dev/null 2>&1 || { error "semver not installed: see comments for instructions."; exit 1; }
|
|
|
|
|
command -v jq >/dev/null 2>&1 || { error "jq not installed: see comments for instructions."; exit 1; }
|
2013-02-19 04:43:49 +00:00
|
|
|
|
|
|
|
|
|
if [ "$1" == "" ]; then
|
2013-08-08 09:30:55 +00:00
|
|
|
|
usage
|
2013-02-19 04:43:49 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2014-09-25 07:47:21 +00:00
|
|
|
|
git pull
|
|
|
|
|
|
|
|
|
|
# Make sure all changes are merged.
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
|
error "Branch did not contain the latest changes and could not be merged automatically."
|
|
|
|
|
echo "Please merge by hand before continue."
|
|
|
|
|
echo
|
|
|
|
|
git status
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2013-02-19 04:43:49 +00:00
|
|
|
|
# Dirty repo?
|
|
|
|
|
if [ "$(git status --porcelain 2>/dev/null)" ]; then
|
|
|
|
|
error "Repo is dirty."
|
|
|
|
|
echo "Pleae commit changes before continue."
|
|
|
|
|
echo
|
|
|
|
|
git status
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Read existing versions
|
|
|
|
|
jq_ver=$(find . -maxdepth 1 -name "*.jquery.json" | xargs cat | jq -r ".version")
|
2013-08-08 09:30:55 +00:00
|
|
|
|
cmpnt_ver=$(find . -maxdepth 1 -name "bower.json" | xargs cat | jq -r ".version")
|
2013-02-19 04:43:49 +00:00
|
|
|
|
pkg_ver=$(find . -maxdepth 1 -name "package.json" | xargs cat | jq -r ".version")
|
2014-05-05 14:16:51 +00:00
|
|
|
|
git_ver=$(git tag | sort -rV | head -n1)
|
2013-02-19 04:43:49 +00:00
|
|
|
|
|
|
|
|
|
# Non npm package
|
2013-03-17 06:03:24 +00:00
|
|
|
|
[ "$pkg_ver" == "0.0.0" ] && pkg_ver=
|
2013-02-19 04:43:49 +00:00
|
|
|
|
|
|
|
|
|
# Verify current versions
|
2013-03-17 06:03:24 +00:00
|
|
|
|
current_ver=
|
|
|
|
|
[ -n "$jq_ver" ] && current_ver="$jq_ver"
|
|
|
|
|
[ -n "$cmpnt_ver" ] && current_ver="$cmpnt_ver"
|
|
|
|
|
[ -n "$pkg_ver" ] && current_ver="$pkg_ver"
|
2014-05-05 14:16:51 +00:00
|
|
|
|
[ -n "$git_ver" ] && current_ver="$git_ver"
|
2013-03-17 06:03:24 +00:00
|
|
|
|
[ -z "$current_ver" ] && current_ver="0.0.0"
|
2013-02-19 04:43:49 +00:00
|
|
|
|
|
|
|
|
|
# Validate current versions and determine new version
|
|
|
|
|
if [ "$1" == "major" ] || [ "$1" == "minor" ] || [ "$1" == "patch" ]; then
|
2013-08-08 09:30:55 +00:00
|
|
|
|
dont_match="Versions in *.jquery.json, bower.json and package.json don’t match."
|
2013-03-17 06:03:24 +00:00
|
|
|
|
if [ -n "$jq_ver" ] && [ "$current_ver" != "$jq_ver" ]; then error $dont_match; fi
|
|
|
|
|
if [ -n "$cmpnt_ver" ] && [ "$current_ver" != "$cmpnt_ver" ]; then error $dont_match; fi
|
|
|
|
|
if [ -n "$pkg_ver" ] && [ "$current_ver" != "$pkg_ver" ]; then error $dont_match; fi
|
2013-02-19 04:43:49 +00:00
|
|
|
|
else
|
2013-08-08 09:30:55 +00:00
|
|
|
|
if [ "$1" != "--force" ]; then
|
|
|
|
|
error "Custom versions possible only with --force key."
|
|
|
|
|
echo
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2013-02-19 04:43:49 +00:00
|
|
|
|
new_ver="$1"
|
|
|
|
|
fi
|
2013-03-17 06:03:24 +00:00
|
|
|
|
if [ -z "$new_ver" ]; then
|
2013-02-19 04:43:49 +00:00
|
|
|
|
[ "$1" == "patch" ] && new_ver=$(semver -p $current_ver)
|
|
|
|
|
[ "$1" == "minor" ] && new_ver=$(semver -n $current_ver)
|
|
|
|
|
[ "$1" == "major" ] && new_ver=$(semver -m $current_ver)
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
header "Releasing v$new_ver..."
|
|
|
|
|
|
2013-08-08 09:30:55 +00:00
|
|
|
|
# Update bower.json
|
2013-03-17 06:03:24 +00:00
|
|
|
|
if [ -n "$cmpnt_ver" ]; then
|
2013-08-08 09:30:55 +00:00
|
|
|
|
sed -i '' "s^$current_ver^$new_ver^" bower.json
|
2013-02-19 04:43:49 +00:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Update package.json
|
2013-03-17 06:03:24 +00:00
|
|
|
|
if [ -n "$pkg_ver" ]; then
|
|
|
|
|
sed -i '' "s^$current_ver^$new_ver^" package.json
|
2013-02-19 04:43:49 +00:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Update *.jquery.json
|
2013-03-17 06:03:24 +00:00
|
|
|
|
if [ -n "$jq_ver" ]; then
|
|
|
|
|
find . -maxdepth 1 -name "*.jquery.json" | xargs sed -i '' "s^$current_ver^$new_ver^"
|
2013-02-19 04:43:49 +00:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Build files
|
2013-07-01 20:21:21 +00:00
|
|
|
|
[ -f Gruntfile.js ] || [ -f Gruntfile.coffee ] && grunt build
|
2013-02-19 04:43:49 +00:00
|
|
|
|
if [ -f src/Gruntfile.js ]; then
|
|
|
|
|
pushd src
|
|
|
|
|
grunt build
|
|
|
|
|
popd
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Commit changed files
|
2014-05-05 14:16:51 +00:00
|
|
|
|
git commit -am "$new_ver"
|
2013-02-19 04:43:49 +00:00
|
|
|
|
git push origin
|
|
|
|
|
|
|
|
|
|
# Create tag
|
2014-05-05 14:16:51 +00:00
|
|
|
|
git tag "$new_ver"
|
2013-02-19 04:43:49 +00:00
|
|
|
|
git push origin --tags
|
|
|
|
|
|
|
|
|
|
# Publish npm package
|
2013-03-17 06:03:24 +00:00
|
|
|
|
if [ -n "$pkg_ver" ]; then
|
2013-02-19 04:43:49 +00:00
|
|
|
|
npm publish
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Done."
|