|
1 | 1 | #!/bin/bash |
2 | 2 | cd `dirname $0`/.. |
3 | 3 |
|
4 | | -if [ "${TRAVIS_BRANCH}" == 'master' -a "${TRAVIS_PULL_REQUEST}" == 'false' ] || [ -n "${TRAVIS_TAG}" ]; then |
5 | | - if [[ -z "${SONATYPE_USERNAME}" || -z "${SONATYPE_PASSWORD}" ]]; then |
| 4 | +BRANCH=${TRAVIS_BRANCH} |
| 5 | +PULL_REQUEST=${TRAVIS_PULL_REQUEST} |
| 6 | +USERNAME=${SONATYPE_USERNAME} |
| 7 | +PASSWORD=${SONATYPE_PASSWORD} |
| 8 | +SHA=${TRAVIS_COMMIT} |
| 9 | + |
| 10 | +# Only if this is a master branch and it is not a PR - meaning, this commit |
| 11 | +# is from master branch most merge |
| 12 | +if [[ "${BRANCH}" == 'master' && "${PULL_REQUEST}" == 'false' ]]; then |
| 13 | + if [[ -z "${USERNAME}" || -z "${PASSWORD}" ]]; then |
6 | 14 | echo "ERROR! Please set SONATYPE_USERNAME and SONATYPE_PASSWORD environment variable" |
7 | 15 | exit 1 |
8 | 16 | fi |
9 | 17 |
|
10 | | - TAG_NAME=`git describe ${TRAVIS_COMMIT} --tags` |
11 | | - echo "Tag associated with the current commit ${TRAVIS_COMMIT} is ${TAG_NAME}" |
12 | | - |
13 | | - if [ ! -z "${TRAVIS_TAG}" ]; then |
14 | | - echo "travis tag is set -> updating pom.xml <version> attribute to ${TRAVIS_TAG}" |
15 | | - ./mvnw --batch-mode --settings .travis/settings.xml -DskipTests=true -DreleaseVersion=${TRAVIS_TAG} release:clean release:prepare release:perform |
| 18 | + # if the current commit has a tag and if the tag matches the semantic versioning pattern `x.y.z` |
| 19 | + # then release it |
| 20 | + TAG_NAME=`git describe ${SHA} --tags` |
| 21 | + echo "Tag associated with the current commit ${SHA} is ${TAG_NAME}" |
| 22 | + |
| 23 | + if [[ ! -z "${TAG_NAME}" && ${TAG_NAME} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then |
| 24 | + echo "travis tag is set -> updating pom.xml <version> attribute to ${TAG_NAME}" |
| 25 | + ./mvnw --batch-mode --settings .travis/settings.xml -DskipTests=true -DreleaseVersion=${TAG_NAME} release:clean release:prepare release:perform |
16 | 26 | SUCCESS=$? |
17 | 27 | else |
18 | 28 | echo "no travis tag is set, hence keeping the snapshot version in pom.xml" |
19 | 29 | ./mvnw --batch-mode --settings .travis/settings.xml clean deploy -DskipTests=true -B -U |
20 | 30 | SUCCESS=$? |
21 | 31 | fi |
22 | 32 |
|
23 | | - if [ ${SUCCESS} -eq 0 ]; then |
| 33 | + if [[ ${SUCCESS} -eq 0 ]]; then |
24 | 34 | echo "successfully deployed the jars to nexus" |
25 | 35 | fi |
26 | 36 |
|
27 | 37 | exit ${SUCCESS} |
28 | 38 | else |
29 | | - echo "Skipping artifact deployment for branch ${TRAVIS_BRANCH} with PR=${TRAVIS_PULL_REQUEST} and TAG=${TRAVIS_TAG}" |
| 39 | + echo "Skipping artifact deployment for branch ${BRANCH}, commit ${SHA} with PR=${PULL_REQUEST}" |
| 40 | + exit 0 |
30 | 41 | fi |
31 | | - |
32 | | -exit 0 |
|
0 commit comments