strolch/li.strolch.dev/release.sh

282 lines
6.8 KiB
Bash
Raw Normal View History

2014-09-20 12:27:20 +02:00
#!/bin/bash
declare SCRIPT_NAME="${0##*/}"
declare SCRIPT_DIR="$(cd ${0%/*} ; pwd)"
root="$(cd ${SCRIPT_DIR}/.. ; pwd)"
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;
echo " -c create release branch"
echo " -p push tags"
echo " -r <release_branch> release branch to create or using for tagging and checkout"
echo " -b <branch> branch to checkout from (important when creating the release_branch)"
echo " -o <old_version> version from which to release from e.g. 1.0.0-SNAPSHOT"
echo " -n <new_version> release version e.g. 1.0.0-RC3"
echo ""
2014-09-20 12:27:20 +02:00
exit 1;
}
# get arguments
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))
# validate arguments
2014-09-20 12:27:20 +02:00
if [ -z "${r}" ] || [ -z "${b}" ] || [ -z "${o}" ] || [ -z "${n}" ] ; then
echo "ERROR: Missing an argument!"
usage
fi
# validate no uncommitted changes
2014-09-22 22:13:50 +02:00
if [ "$(git status --short)" != "" ] ; then
echo -e "ERROR: You have uncommitted changes! Please commit them before continuing."
2014-09-22 22:13:50 +02:00
exit 1
fi
2014-09-20 12:27:20 +02:00
# First make sure we use SSH for pushing
if find .git/modules -type f -name config | xargs grep "https://github.com" ; then
echo -e "ERROR: There is at least one submodule which has its remote set to https://github.com"
echo -e "ERROR: Please change this before your continuing, using the following command:"
echo -e " find .git/modules -type f -name config | xargs sed -i .bck \"s|https://github.com/|git@github.com:|g\""
exit 1
fi
2014-09-22 20:55:32 +02:00
# set vars
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
# log what we are doing
echo "INFO: root=${root}"
echo "INFO: old_version=${old_version}"
echo "INFO: new_version=${new_version}"
echo "INFO: branch=${branch}"
echo "INFO: release_branch=${release_branch}"
2014-09-20 12:27:20 +02:00
if [ -n "${create_release_branch}" ] ; then
echo "INFO: Creating release branch."
2014-09-20 12:27:20 +02:00
else
echo "INFO: NOT creating release branch."
2014-09-20 12:27:20 +02:00
fi
2014-09-20 15:02:47 +02:00
if [ -n "${push}" ] ; then
echo "INFO: Pushing to origin."
2014-09-20 15:02:47 +02:00
else
echo "INFO: NOT pushing to origin."
2014-09-20 15:02:47 +02:00
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
}
function build() {
cd ${root}
if mvn clean package -DskipTests 1> /dev/null ; then
echo "INFO: Build OK"
return 0;
else
echo "ERROR: Build failed!"
echo "INFO: Run mvn clean package -DskipTests to see the build problems!"
return 1;
fi
}
function createBundle() {
cd "${root}/li.strolch.dev"
if ./createBundle.sh 1> /dev/null ; then
echo "INFO: Bundle creation OK"
return 0;
else
echo "ERROR: Bundle creation failed!"
echo "INFO: Run ${root}/li.strolch.dev/createBundle.sh to see the bundle creation problems!"
return 1;
fi
}
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
# build with old version
echo "INFO: Building current version ${old_version}..."
if ! build ; then
fail
fi
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
# build with new version
echo -e "\nINFO: Building new version ${new_version}..."
if ! build ; then
fail
fi
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
2014-09-20 12:27:20 +02:00
fail
fi
if ! git tag ${new_version} ; then
fail
fi
2014-09-22 20:55:32 +02:00
# create bundle for new version
echo -e "\nINFO: Creating bundle for version ${new_version}..."
if ! createBundle ; then
fail
fi
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
echo -e "\nINFO: Pushing ${new_version} to origin..."
2014-09-20 15:06:40 +02:00
git submodule foreach git push origin ${new_version}
git push origin ${new_version}
2014-10-10 11:57:33 +02:00
else
2014-10-10 12:02:59 +02:00
echo -e "\nINFO: To push tags perform the following:"
echo -e " git push origin ${new_version}"
echo -e " git submodule foreach git push origin ${new_version}"
2014-10-10 12:02:59 +02:00
echo -e "\nINFO: Or to delete the tags:"
echo -e " git submodule foreach git tag -d ${new_version}"
echo -e " git tag -d ${new_version}"
2014-09-20 15:06:40 +02:00
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