dotfiles/bin/release
Jacob Kiers 5e9e061e4f Make sure the repo is clean before releasing.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-09-25 09:47:21 +02:00

132 lines
3.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Release next version of the product
# Usage:
# release <major|minor|patch>
# release <VERSION> --force
#
# 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"; }
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; }
if [ "$1" == "" ]; then
usage
exit 1
fi
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
# 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")
cmpnt_ver=$(find . -maxdepth 1 -name "bower.json" | xargs cat | jq -r ".version")
pkg_ver=$(find . -maxdepth 1 -name "package.json" | xargs cat | jq -r ".version")
git_ver=$(git tag | sort -rV | head -n1)
# Non npm package
[ "$pkg_ver" == "0.0.0" ] && pkg_ver=
# Verify current versions
current_ver=
[ -n "$jq_ver" ] && current_ver="$jq_ver"
[ -n "$cmpnt_ver" ] && current_ver="$cmpnt_ver"
[ -n "$pkg_ver" ] && current_ver="$pkg_ver"
[ -n "$git_ver" ] && current_ver="$git_ver"
[ -z "$current_ver" ] && current_ver="0.0.0"
# Validate current versions and determine new version
if [ "$1" == "major" ] || [ "$1" == "minor" ] || [ "$1" == "patch" ]; then
dont_match="Versions in *.jquery.json, bower.json and package.json dont match."
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
else
if [ "$1" != "--force" ]; then
error "Custom versions possible only with --force key."
echo
usage
exit 1
fi
new_ver="$1"
fi
if [ -z "$new_ver" ]; then
[ "$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..."
# Update bower.json
if [ -n "$cmpnt_ver" ]; then
sed -i '' "s^$current_ver^$new_ver^" bower.json
fi
# Update package.json
if [ -n "$pkg_ver" ]; then
sed -i '' "s^$current_ver^$new_ver^" package.json
fi
# Update *.jquery.json
if [ -n "$jq_ver" ]; then
find . -maxdepth 1 -name "*.jquery.json" | xargs sed -i '' "s^$current_ver^$new_ver^"
fi
# Build files
[ -f Gruntfile.js ] || [ -f Gruntfile.coffee ] && grunt build
if [ -f src/Gruntfile.js ]; then
pushd src
grunt build
popd
fi
# Commit changed files
git commit -am "$new_ver"
git push origin
# Create tag
git tag "$new_ver"
git push origin --tags
# Publish npm package
if [ -n "$pkg_ver" ]; then
npm publish
fi
echo "Done."