diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..dfe9a81 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# Your mvn settings.xml: +# +# +# +# +# oss.sonatype.org +# ... +# ... +# +# +# +# + +# usage +if [ $# != 1 ] ; then + echo -e "Usage: ${0} " + exit 1 +fi + + +# Confirm +releaseVersion=${1} +echo -e "INFO: Do you want to deploy version ${releaseVersion} to Maven Central? y/n" +read a +if [[ "${a}" != "y" && "${a}" != "Y" ]] ; then + exit 0; +fi + + +# Verify tag +echo -e "\nINFO: Verifying tag ${releaseVersion}\n\n" +if ! git tag --verify ${releaseVersion} ; then + echo -e "ERROR: Failed to verify tag ${releaseVersion}" + exit 1 +fi +echo +echo + + +# Checkout tag +echo -e "\nINFO: Checking out tag ${releaseVersion}" +if ! git checkout ${releaseVersion} ; then + echo -e "ERROR: Failed to checkout tag ${releaseVersion}" + exit 1 +fi + + +# Build and deploy +echo -e "\nINFO: Building and deploying to Maven Central..." +if ! mvn clean deploy -DskipTests -Pdeploy > /dev/null ; then + echo -e "ERROR: Failed to build and deploy to Maven Central!" + exit 1 +fi + + +echo -e "\nINFO: Release ${releaseVersion} deployed to Maven Central." +echo -e "INFO: Remember, it can take up to 10minutes to be available, and 2 hours for all synching." + +echo -e "\nRepository is at: https://oss.sonatype.org/service/local/repositories/releases/content/" + +exit 0 diff --git a/hotfix.sh b/hotfix.sh new file mode 100755 index 0000000..b053073 --- /dev/null +++ b/hotfix.sh @@ -0,0 +1,129 @@ +#!/bin/bash + +# usage +if [ $# != 2 ] ; then + echo -e "Usage: ${0} " + exit 1 +fi + + +# Confirm +releaseVersion="${1}" +releaseBranch="release/${1}" +hotfixVersion="${2}" +echo -e "INFO: Do you want to make hotfix version ${hotfixVersion} 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 + + +# 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 +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 diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..0a98d0c --- /dev/null +++ b/release.sh @@ -0,0 +1,147 @@ +#!/bin/bash + +# usage +if [ $# != 2 ] ; then + echo -e "Usage: ${0} " + exit 1 +fi + + +# Confirm +sourceBranch=${1} +releaseVersion=${2} +echo -e "INFO: Do you want to release version ${releaseVersion} from branch ${sourceBranch}? y/n" +read a +if [[ "${a}" != "y" && "${a}" != "Y" ]] ; then + exit 0; +fi + + +# validate tag and release branch do 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 "${releaseVersion}" > /dev/null ; then + echo -e "ERROR: Tag already exists!" + exit 1 +fi +if git branch --all | grep "release/${releaseVersion}" > /dev/null ; then + echo -e "ERROR: Tag already exists!" + exit 1 +fi + +# validate tag does not exist +if git tag | grep "${releaseVersion}" > /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 source branch +echo -e "\nINFO: Checking out source branch ${sourceBranch}" +if ! git checkout ${sourceBranch} ; then + echo -e "ERROR: Failed to checkout branch ${sourceBranch}" + exit 1 +fi + + +# create new release branch, and temp tag +echo -e "\nINFO: Creating release and temp branches..." +if ! git checkout -b release/${releaseVersion} ; then + echo -e "ERROR: Failed to create release branch!" + exit 1 +fi +if ! git checkout -b temp ; then + echo -e "ERROR: Failed to create temp branch!" + exit 1 +fi + + +# set release version +echo -e "\nINFO: Setting version..." +if ! mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${releaseVersion} > /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 ${releaseVersion}" ; then + echo -e "ERROR: Failed to git commit" + exit 1 +fi +if ! git tag --sign --message "[Project] New Version ${releaseVersion}" ${releaseVersion} ; then + echo -e "ERROR: Failed to git tag" + exit 1 +fi + + +# cleanup +echo -e "\nINFO: Cleaning up..." +if ! git checkout release/${releaseVersion} ; 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 +echo -e "\nINFO: Release ${releaseVersion} 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 release/${releaseVersion} ; then + echo -e "ERROR: Failed to push release branch" + exit 1 + fi + if ! git push origin ${releaseVersion} ; then + echo -e "ERROR: Failed to push tag" + exit 1 + fi + echo -e "\nINFO: Pushed release branch and tag for release version ${releaseVersion}" +else + echo -e "WARN: Release not pushed!" +fi + + +echo -e "\nINFO: Release ${releaseVersion} created." +echo -e "INFO: Don't forget to update snapshot version!" + + +exit 0 diff --git a/setVersion.sh b/setVersion.sh new file mode 100755 index 0000000..3d00dc4 --- /dev/null +++ b/setVersion.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ $# != 1 ] ; then + echo "Usage: ${0} " + exit 1 +fi + +projectVersion=${1} + +mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${projectVersion} + +exit 0