[Project] created autoRelease.sh and added cleanup trap
This commit is contained in:
parent
84d3ca4666
commit
e147594a9d
|
@ -0,0 +1,131 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# usage
|
||||||
|
if [ $# != 1 ] ; then
|
||||||
|
echo -e "Usage: ${0} <release_branch>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
releaseBranch="${1}"
|
||||||
|
|
||||||
|
lastTag="$(git for-each-ref --format="%(refname)" --sort=-taggerdate --count=1 refs/tags | cut -d '/' -f 3)"
|
||||||
|
majorVersion=$(echo $lastTag | cut -d '.' -f 1)
|
||||||
|
minorVersion=$(echo $lastTag | cut -d '.' -f 2)
|
||||||
|
updateVersion=$(echo $lastTag | cut -d '.' -f 3)
|
||||||
|
newUpdateVersion=$((updateVersion+1))
|
||||||
|
newVersion="${majorVersion}.${minorVersion}.${newUpdateVersion}"
|
||||||
|
|
||||||
|
|
||||||
|
# cleanup trap
|
||||||
|
function cleanup {
|
||||||
|
echo -e "\nINFO: Cleaning up..."
|
||||||
|
git checkout ${releaseBranch}
|
||||||
|
git branch -D temp
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
|
||||||
|
# Confirm
|
||||||
|
echo -e "INFO: Previous tag: ${lastTag}"
|
||||||
|
echo -e "INFO: Do you want to create release ${newVersion} from release branch ${releaseBranch}? y/n"
|
||||||
|
read a
|
||||||
|
if [[ "${a}" != "y" && "${a}" != "Y" ]] ; then
|
||||||
|
exit 0;
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# validate tag does not exist
|
||||||
|
echo -e "INFO: Fetching tags and branches and validating they do not exist..."
|
||||||
|
if ! git fetch --all --tags > /dev/null ; then
|
||||||
|
echo -e "ERROR: Tags and branches could not be fetched!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if git tag | grep ${hotfixVersion} > /dev/null ; then
|
||||||
|
echo -e "ERROR: Tag already exists!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# make sure gpg-agent is available and loaded
|
||||||
|
echo -e "\nINFO: Searching for gpg-agent..."
|
||||||
|
if ! which gpg-agent ; then
|
||||||
|
echo -e "ERROR: gpg-agent missing!"
|
||||||
|
fi
|
||||||
|
if ! gpg-agent 2>&1 | grep "running and available" ; then
|
||||||
|
echo -e "WARN: gpg-agent not running, trying to start..."
|
||||||
|
if ! gpg-agent --daemon ; then
|
||||||
|
echo -e "ERROR: Failed to initialize gpg-agent, please make sure it is up and running before continuing!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! gpg-agent 2>&1 | grep "running and available" ; then
|
||||||
|
echo -e "ERROR: Failed to initialize gpg-agent, please make sure it is up and running before continuing!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Checkout release branch
|
||||||
|
echo -e "\nINFO: Checking out release branch ${releaseBranch}"
|
||||||
|
if ! git checkout ${releaseBranch} ; then
|
||||||
|
echo -e "ERROR: Failed to checkout branch ${releaseBranch}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# create temp branch
|
||||||
|
echo -e "\nINFO: Creating temp branch..."
|
||||||
|
if ! git checkout -b temp ; then
|
||||||
|
echo -e "ERROR: Failed to create temp branch!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# set hotfix version
|
||||||
|
echo -e "\nINFO: Setting version..."
|
||||||
|
if ! mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${hotfixVersion} > /dev/null ; then
|
||||||
|
echo -e "ERROR: Failed to set new version!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# build
|
||||||
|
echo -e "\nINFO: Doing a build with new version..."
|
||||||
|
if ! mvn clean package -DskipTests > /dev/null ; then
|
||||||
|
echo -e "ERROR: Failed to build with new version!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# commit to tag
|
||||||
|
echo -e "\nINFO: Creating tag..."
|
||||||
|
if ! git add . ; then
|
||||||
|
echo -e "ERROR: Failed to git add"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! git commit -m "[Project] Set new version ${hotfixVersion}" ; then
|
||||||
|
echo -e "ERROR: Failed to git commit"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! git tag --sign --message "[Project] New Version ${hotfixVersion}" ${hotfixVersion} ; then
|
||||||
|
echo -e "ERROR: Failed to git tag"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# git push
|
||||||
|
echo -e "\nINFO: Hotfix ${hotfixVersion} created. Do you want to push to origin? y/n"
|
||||||
|
read a
|
||||||
|
if [[ "${a}" == "y" || "${a}" == "Y" ]] ; then
|
||||||
|
echo -e "INFO: Pushing to origin..."
|
||||||
|
if ! git push origin ${hotfixVersion} ; then
|
||||||
|
echo -e "ERROR: Failed to push tag"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo -e "\nINFO: Pushed hotfix tag ${hotfixVersion}"
|
||||||
|
else
|
||||||
|
echo -e "WARN: Release not pushed!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echo -e "\nINFO: Hotfix ${hotfixVersion} created."
|
||||||
|
exit 0
|
23
release.sh
23
release.sh
|
@ -7,6 +7,15 @@ if [ $# != 2 ] ; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# cleanup trap
|
||||||
|
function cleanup {
|
||||||
|
echo -e "\nINFO: Cleaning up..."
|
||||||
|
git checkout ${releaseBranch}
|
||||||
|
git branch -D temp
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
|
||||||
# Confirm
|
# Confirm
|
||||||
releaseBranch="${1}"
|
releaseBranch="${1}"
|
||||||
hotfixVersion="${2}"
|
hotfixVersion="${2}"
|
||||||
|
@ -95,18 +104,6 @@ if ! git tag --sign --message "[Project] New Version ${hotfixVersion}" ${hotfixV
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
echo -e "\nINFO: Cleaning up..."
|
|
||||||
if ! git checkout ${releaseBranch} ; then
|
|
||||||
echo -e "ERROR: Failed to checkout release branch"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if ! git branch -D temp ; then
|
|
||||||
echo -e "ERROR: Failed to delete temp branch"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# git push
|
# git push
|
||||||
echo -e "\nINFO: Hotfix ${hotfixVersion} created. Do you want to push to origin? y/n"
|
echo -e "\nINFO: Hotfix ${hotfixVersion} created. Do you want to push to origin? y/n"
|
||||||
read a
|
read a
|
||||||
|
@ -123,6 +120,4 @@ fi
|
||||||
|
|
||||||
|
|
||||||
echo -e "\nINFO: Hotfix ${hotfixVersion} created."
|
echo -e "\nINFO: Hotfix ${hotfixVersion} created."
|
||||||
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue