Skip to content

Commit

Permalink
Update deploy.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Magesh Chandramouli authored Jan 19, 2019
1 parent f1c578e commit 5dfb215
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions .travis/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,31 @@ PULL_REQUEST=${TRAVIS_PULL_REQUEST}
USERNAME=${SONATYPE_USERNAME}
PASSWORD=${SONATYPE_PASSWORD}
SHA=${TRAVIS_COMMIT}
TAG_NAME=${TRAVIS_TAG}

#!/usr/bin/env bash
function fix_git {
echo "Fixing git setup for ${BRANCH}"
git checkout ${BRANCH}
git branch -u origin/${BRANCH}
git config branch.${BRANCH}.remote origin
git config branch.${BRANCH}.merge refs/heads/${BRANCH}
}

# Only if this is a master branch and it is not a PR - meaning, this commit
# is from master branch most merge
if [[ "${BRANCH}" == 'master' && "${PULL_REQUEST}" == 'false' ]]; then
if [[ -z "${USERNAME}" || -z "${PASSWORD}" ]]; then
if [[ -z "${USERNAME}" || -z "${PASSWORD}" ]]; then
echo "ERROR! Please set SONATYPE_USERNAME and SONATYPE_PASSWORD environment variable"
exit 1
fi

# if the current commit has a tag and if the tag matches the semantic versioning pattern `x.y.z`
# then release it
TAG_NAME=`git describe ${SHA} --tags`
echo "Tag associated with the current commit ${SHA} is ${TAG_NAME}"
fi

if [[ ! -z "${TAG_NAME}" && ${TAG_NAME} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
echo "travis tag is set -> updating pom.xml <version> attribute to ${TAG_NAME}"
fix_git
./mvnw --batch-mode --settings .travis/settings.xml -DskipTests=true -DreleaseVersion=${TAG_NAME} release:clean release:prepare release:perform
SUCCESS=$?
if [[ "${BRANCH}" == 'master' && "${PULL_REQUEST}" == 'false' ]] || [[ -n "${TAG_NAME}" ]]; then
if [[ ! -z "${TAG_NAME}" ]]; then
echo "Ensuring that pom <version> matches ${TAG_NAME}"
./mvnw org.codehaus.mojo:versions-maven-plugin:2.5:set -DnewVersion=${TAG_NAME}
else
echo "no travis tag is set, hence keeping the snapshot version in pom.xml"
./mvnw --batch-mode --settings .travis/settings.xml clean deploy -DskipTests=true -B -U
SUCCESS=$?
fi

echo "Uploading to oss repo and GitHub"
./mvnw deploy --settings .travis/settings.xml -DskipTests=true --batch-mode --update-snapshots -Prelease
SUCCESS=$?
if [[ ${SUCCESS} -eq 0 ]]; then
echo "successfully deployed the jars to nexus"
fi

exit ${SUCCESS}
else
echo "Skipping artifact deployment for branch ${BRANCH}, commit ${SHA} with PR=${PULL_REQUEST}"
exit 0
echo "Skipping artifact deployment for branch ${BRANCH} with PR=${PULL_REQUEST} and TAG=${TAG_NAME}"
fi

exit 0

0 comments on commit 5dfb215

Please sign in to comment.