strolch/li.strolch.dev/release.sh

213 lines
4.4 KiB
Bash
Raw Normal View History

2014-09-20 12:27:20 +02:00
#!/bin/bash
2014-09-22 21:04:18 +02:00
if [ ! $(which xmlstarlet) ] ; then
echo "ERROR: xmlstarlet is missing!"s
exit 1
fi
2014-09-20 12:27:20 +02:00
function usage() {
2014-09-20 15:02:47 +02:00
echo "Usage: $0 [-c] [-p] [-r <release_branch>] [-b <branch>] [-o <old_version>] [-n <new_version>]" 1>&2;
2014-09-20 12:27:20 +02:00
exit 1;
}
2014-09-20 15:02:47 +02:00
while getopts ":b:o:n:r:cp" arg; do
2014-09-20 12:27:20 +02:00
case "${arg}" in
c)
c="true"
;;
2014-09-20 15:02:47 +02:00
p)
p="true"
;;
2014-09-20 12:27:20 +02:00
r)
r=${OPTARG}
;;
b)
b=${OPTARG}
;;
o)
o=${OPTARG}
;;
n)
n=${OPTARG}
;;
*)
echo "ERROR: Unknown arg ${arg}"
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${r}" ] || [ -z "${b}" ] || [ -z "${o}" ] || [ -z "${n}" ] ; then
echo "ERROR: Missing an argument!"
usage
fi
2014-09-22 22:13:50 +02:00
if [ "$(git status --short)" != "" ] ; then
echo "You have uncommitted changes!"
exit 1
fi
2014-09-20 12:27:20 +02:00
2014-09-22 20:55:32 +02:00
declare SCRIPT_NAME="${0##*/}"
declare SCRIPT_DIR="$(cd ${0%/*} ; pwd)"
2014-09-20 12:27:20 +02:00
create_release_branch="${c}"
release_branch="${r}"
branch="${b}"
old_version="${o}"
new_version="${n}"
2014-09-20 15:02:47 +02:00
push="${p}"
2014-09-20 12:27:20 +02:00
2014-09-22 20:55:32 +02:00
root="$(cd ${SCRIPT_DIR}/.. ; pwd)"
2014-09-20 12:27:20 +02:00
2014-09-22 20:55:32 +02:00
echo "root=${root}"
2014-09-20 12:27:20 +02:00
echo "old_version=${old_version}"
echo "new_version=${new_version}"
echo "branch=${branch}"
echo "release_branch=${release_branch}"
if [ -n "${create_release_branch}" ] ; then
echo "Creating release branch."
else
echo "NOT creating release branch."
fi
2014-09-20 15:02:47 +02:00
if [ -n "${push}" ] ; then
echo "Pushing to origin."
else
echo "NOT pusing to origin."
fi
2014-09-20 12:27:20 +02:00
2014-09-22 21:43:29 +02:00
echo ""
2014-09-20 12:27:20 +02:00
function fail() {
2014-09-22 21:43:29 +02:00
echo -e "\nWARN: Cleaning up after fail..."
2014-09-20 12:27:20 +02:00
git submodule foreach git reset --hard origin/${branch}
git submodule foreach git checkout ${branch}
if [ -n "${create_release_branch}" ] ; then
2014-09-20 14:37:44 +02:00
git submodule foreach git branch -D ${release_branch}
2014-09-20 12:27:20 +02:00
fi
git submodule foreach git tag -d ${new_version}
git checkout ${branch}
git reset --hard origin/${branch}
2014-09-20 14:37:44 +02:00
if [ -n "${create_release_branch}" ] ; then
git branch -D ${release_branch}
fi
2014-09-20 12:27:20 +02:00
git tag -d ${new_version}
echo -e "\nERROR: Failed to release version ${new_version}"
exit 1
}
2014-09-22 20:55:32 +02:00
2014-09-20 12:27:20 +02:00
# create release branch
if [ -n "${create_release_branch}" ] ; then
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Creating release branch..."
2014-09-20 12:27:20 +02:00
if ! git branch ${release_branch} ${branch} ; then
fail
fi
if ! git submodule foreach git branch ${release_branch} ${branch} ; then
fail
fi
fi
2014-09-22 20:55:32 +02:00
2014-09-20 12:27:20 +02:00
# checkout release branch
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Checking out release branch..."
2014-09-20 12:27:20 +02:00
if ! git checkout ${release_branch} ; then
fail
fi
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Checking out submodules..."
2014-09-20 12:27:20 +02:00
if ! git submodule foreach git checkout ${release_branch} ; then
fail
fi
2014-09-22 20:55:32 +02:00
2014-09-20 12:27:20 +02:00
# bump version
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Bumping versions..."
${root}/li.strolch.dev/setVersion.sh ${old_version} ${new_version}
if [ $? -ne 0 ] ; then
2014-09-20 12:27:20 +02:00
fail
fi
2014-09-22 20:55:32 +02:00
2014-09-20 12:27:20 +02:00
# show status
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Git Status:"
2014-09-20 12:27:20 +02:00
if ! git status --short ; then
fail
fi
if ! git submodule foreach git status --short ; then
fail
fi
2014-09-22 20:55:32 +02:00
2014-09-20 14:52:34 +02:00
# commit and tag submodules
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Committing and tagging submodules..."
2014-09-20 12:27:20 +02:00
if ! git submodule foreach git add . ; then
fail
fi
if ! git submodule foreach git commit -m "[Project] bumped version from ${old_version} to ${new_version}" ; then
fail
fi
if ! git submodule foreach git tag ${new_version} ; then
fail
fi
2014-09-22 20:55:32 +02:00
2014-09-20 14:52:34 +02:00
# commit and tag including ref to submodules
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Synching submodules..."
2014-09-20 12:27:20 +02:00
if ! git submodule sync ; then
fail
fi
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Committing and tagging..."
2014-09-20 12:27:20 +02:00
if ! git add . ; then
fail
fi
if ! git commit -m "[Project] bumped version from ${old_version} to ${new_version}" ; then
fail
fi
if ! git tag ${new_version} ; then
fail
fi
2014-09-22 20:55:32 +02:00
2014-09-20 15:02:47 +02:00
# update local working directory to original branch
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Updating local work directory..."
2014-09-20 14:42:31 +02:00
if ! git submodule foreach git checkout ${branch} ; then
2014-09-20 14:37:44 +02:00
fail
fi
2014-09-20 12:27:20 +02:00
if [ -n "${create_release_branch}" ] ; then
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Removing submodule release branches..."
2014-09-20 14:42:31 +02:00
if ! git submodule foreach git branch -D ${release_branch} ; then
2014-09-20 14:37:44 +02:00
fail
fi
fi
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Checking out branch..."
2014-09-20 14:42:31 +02:00
if ! git checkout ${branch} ; then
2014-09-20 14:37:44 +02:00
fail
2014-09-20 12:27:20 +02:00
fi
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Removing release branch..."
2014-09-20 12:27:20 +02:00
if [ -n "${create_release_branch}" ] ; then
2014-09-20 14:42:31 +02:00
if ! git branch -D ${release_branch} ; then
2014-09-20 14:37:44 +02:00
fail
fi
2014-09-20 12:27:20 +02:00
fi
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Updating submodules..."
2014-09-20 15:02:47 +02:00
if ! git submodule update ; then
fail
fi
2014-09-20 14:52:34 +02:00
2014-09-22 20:55:32 +02:00
2014-09-20 15:06:40 +02:00
# push to origin
if [ -n "${push}" ] ; then
2014-09-22 21:43:29 +02:00
echo -e "\nINFO: Pushing to origin..."
2014-09-20 15:06:40 +02:00
git push origin ${new_version}
git submodule foreach git push origin ${new_version}
fi
2014-09-20 14:59:04 +02:00
2014-09-22 20:55:32 +02:00
2014-09-20 12:27:20 +02:00
echo -e "\nINFO: Released version ${new_version}"
exit 0