strolch/li.strolch.dev/setVersion.sh

153 lines
4.0 KiB
Bash
Raw Normal View History

2014-09-19 20:38:54 +02:00
#!/bin/bash
2014-09-19 22:36:59 +02:00
2014-09-22 21:04:18 +02:00
if [ ! $(which xmlstarlet) ] ; then
2014-09-22 21:04:38 +02:00
echo "ERROR: xmlstarlet is missing!"
2014-09-22 21:04:18 +02:00
exit 1
fi
function usage() {
echo "Usage: $0 [-c] [-p] [-o <old_version>] [-n <new_version>]" 1>&2;
echo " -c commit"
echo " -p push to origin"
echo " -o <old_version> old version e.g. 1.0.0-SNAPSHOT"
echo " -n <new_version> new version e.g. 1.0.0-RC3"
echo ""
exit 1;
}
# get arguments
while getopts ":b:o:n:r:cp" arg; do
case "${arg}" in
c)
c="true"
;;
p)
p="true"
;;
o)
o=${OPTARG}
;;
n)
n=${OPTARG}
;;
*)
echo "ERROR: Unknown arg ${arg}"
usage
;;
esac
done
shift $((OPTIND-1))
# validate arguments
if [ -z "${o}" ] || [ -z "${n}" ] ; then
echo "ERROR: Missing an argument!"
usage
fi
old_version="${o}"
new_version="${n}"
commit="${c}"
push="${p}"
2014-09-20 00:14:12 +02:00
2014-09-22 20:55:32 +02:00
declare SCRIPT_NAME="${0##*/}"
declare SCRIPT_DIR="$(cd ${0%/*} ; pwd)"
2014-09-22 21:04:18 +02:00
root="$(cd ${SCRIPT_DIR}/.. ; pwd)"
2014-09-22 21:52:49 +02:00
echo "old_version=${old_version}"
echo "new_version=${new_version}"
echo "root=${root}"
2014-09-20 00:14:12 +02:00
2014-09-20 00:28:42 +02:00
function fail() {
2014-09-20 12:27:20 +02:00
echo -e "\nERROR: Failed to set version of $1"
2014-09-20 00:28:42 +02:00
exit 1
}
function setVersion() {
2014-09-20 01:05:06 +02:00
if [ "$#" != 2 ] ; then
echo -e "ERROR: Missing version and/or file name"
exit 1
fi
2014-09-20 01:05:06 +02:00
version="$1"
file="$2"
2014-09-20 00:58:22 +02:00
if ! [ -f "${file}" ] ; then
echo -e "ERROR: The file does not exist: ${file}"
exit 1
2014-09-20 00:28:42 +02:00
fi
2014-09-20 00:20:10 +02:00
i=0
2014-09-22 20:55:32 +02:00
if xmlstarlet ed --ps -L -N my=http://maven.apache.org/POM/4.0.0 -u "/my:project/my:version" -v ${version} "${file}" 2>/dev/null ; then
i=$((i+1))
fi
if xmlstarlet ed --ps -L -N my=http://maven.apache.org/POM/4.0.0 -u "/my:project/my:parent/my:version" -v ${version} "${file}" 2>/dev/null ; then
i=$((i+1))
fi
if xmlstarlet ed --ps -L -N my=http://maven.apache.org/POM/4.0.0 -u "/my:project/my:properties/my:strolch.version/my:version" -v ${version} "${file}" 2>/dev/null ; then
i=$((i+1))
fi
if xmlstarlet ed --ps -L -N my=http://maven.apache.org/POM/4.0.0 -u "/my:project/my:properties/my:strolch.version" -v ${version} "${file}" 2>/dev/null ; then
i=$((i+1))
2014-09-20 00:28:42 +02:00
fi
if xmlstarlet ed --ps -L -N my=http://maven.apache.org/POM/4.0.0 -u "/my:project/my:properties/my:eitchnet.xmlpers.version" -v ${version} "${file}" 2>/dev/null ; then
i=$((i+1))
2014-09-20 00:28:42 +02:00
fi
if xmlstarlet ed --ps -L -N my=http://maven.apache.org/POM/4.0.0 -u "/my:project/my:properties/my:eitchnet.utils.version" -v ${version} "${file}" 2>/dev/null ; then
i=$((i+1))
2014-09-20 00:28:42 +02:00
fi
if xmlstarlet ed --ps -L -N my=http://maven.apache.org/POM/4.0.0 -u "/my:project/my:properties/my:eitchnet.privilege.version" -v ${version} "${file}" 2>/dev/null ; then
i=$((i+1))
fi
if [ $i -eq 0 ] ; then
echo -e "ERROR: Not one version was change for file ${file}"
exit 1
fi
return 0
}
cd "${root}"
setVersion "${new_version}" "${root}/pom.xml"
for project in li.* ; do
setVersion "${new_version}" "${root}/${project}/pom.xml"
done
for project in ch.* ; do
setVersion "${new_version}" "${root}/${project}/pom.xml"
2014-09-20 00:14:12 +02:00
done
2014-09-19 22:36:59 +02:00
2014-09-22 20:55:32 +02:00
2014-09-20 00:20:10 +02:00
cd "${root}"
2014-10-10 11:54:37 +02:00
create_script="li.strolch.dev/createBundle.sh"
if ! sed -i.bck "s/${old_version}/${new_version}/" "${create_script}" 2>/dev/null ; then
fail "${root}/${create_script}"
2014-09-20 00:28:42 +02:00
fi
2014-10-10 11:54:37 +02:00
rm -f "${create_script}.bck"
2014-09-22 20:55:32 +02:00
# Commit new version
if [ -n "${commit}" ] ; then
echo "INFO: Committing new version ${new_version}"
git submodule foreach git add .
git submodule foreach git commit -m "[Project] Bumped version from ${old_version} to ${new_version}"
if [ -n "${push}" ] ; then
echo "INFO: Pushing submodules to origin..."
git submodule foreach git push origin
fi
git add .
git commit -m "[Project] Bumped version from ${old_version} to ${new_version}"
if [ -n "${push}" ] ; then
echo "INFO: Pushing to origin..."
git push origin
fi
else
echo "INFO: NOT committing new version"
fi
2014-09-20 12:27:20 +02:00
echo -e "\nINFO: Bumped version from ${old_version} to ${new_version}"
2014-10-10 11:54:37 +02:00
exit 0