|
| 1 | +#!/bin/bash |
| 2 | +# -e: exit on any non-true return value |
| 3 | +# -u: exit, if an unset variable is being used |
| 4 | +# https://ss64.com/bash/set.html |
| 5 | +set -eu |
| 6 | + |
| 7 | +echo "TRAVIS_PULL_REQUEST = ${TRAVIS_PULL_REQUEST}" |
| 8 | +echo "TRAVIS_BRANCH = ${TRAVIS_BRANCH}" |
| 9 | +echo "TRAVIS_JDK_VERSION = ${TRAVIS_JDK_VERSION}" |
| 10 | + |
| 11 | +##################### |
| 12 | +# functions |
| 13 | +##################### |
| 14 | +function perform_snapshot_release() { |
| 15 | + echo "----------------" |
| 16 | + echo build and deploy to sourceforge \(SNAPSHOT only\) |
| 17 | + echo "----------------" |
| 18 | + mvn clean deploy javadoc:javadoc -P sourceforge-release --settings ./cicd/settings.xml |
| 19 | +} |
| 20 | + |
| 21 | +function init_github() { |
| 22 | + git config --global user.email "[email protected]" |
| 23 | + git config --global user.name "Travis CI" |
| 24 | + git remote add origin-github https://${GH_TOKEN}@github.com/chewiebug/gcviewer.git > /dev/null 2>&1 |
| 25 | +} |
| 26 | + |
| 27 | +function push_to_github() { |
| 28 | + # https://gist.github.com/willprice/e07efd73fb7f13f917ea |
| 29 | + echo "pushing $1 to github" |
| 30 | + git status |
| 31 | + git push --quiet --set-upstream origin-github $1 |
| 32 | +} |
| 33 | + |
| 34 | +function merge_with_develop_branch() { |
| 35 | + # assumption: we are not on the develop branch and should merge TRAVIS_BRANCH into develop |
| 36 | + echo "merging ${TRAVIS_BRANCH} into develop" |
| 37 | + # since travis did a shallow clone (git clone --depth=50 ...), we need to fetch the develop branch first |
| 38 | + git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" |
| 39 | + git fetch --depth=10 |
| 40 | + git checkout -t -b develop origin/develop |
| 41 | + git merge ${TRAVIS_BRANCH} |
| 42 | +} |
| 43 | + |
| 44 | +function perform_release() { |
| 45 | + echo "----------------" |
| 46 | + echo perform release |
| 47 | + echo "----------------" |
| 48 | + # maven release needs a locally checked out branch, otherwise "git symbolic-ref HEAD" will fail |
| 49 | + git checkout ${TRAVIS_BRANCH} |
| 50 | + openssl version |
| 51 | + openssl enc -d -aes-256-cbc -md sha1 -pass pass:$ENCRYPTION_PASSWORD -in $GPG_DIR/pubring.gpg.enc -out $GPG_DIR/pubring.gpg |
| 52 | + openssl enc -d -aes-256-cbc -md sha1 -pass pass:$ENCRYPTION_PASSWORD -in $GPG_DIR/secring.gpg.enc -out $GPG_DIR/secring.gpg |
| 53 | + mvn --batch-mode release:clean release:prepare release:perform --settings ./cicd/settings.xml |
| 54 | + # remove decrypted keyrings |
| 55 | + rm $GPG_DIR/*.gpg |
| 56 | + init_github |
| 57 | + push_to_github ${TRAVIS_BRANCH} |
| 58 | + # push tag, which was just generated by maven-release-plugin |
| 59 | + git push origin-github $(git describe --tags --abbrev=0) |
| 60 | + merge_with_develop_branch |
| 61 | + push_to_github develop |
| 62 | +} |
| 63 | + |
| 64 | +function perform_verify() { |
| 65 | + echo "----------------" |
| 66 | + echo only verify |
| 67 | + echo "----------------" |
| 68 | + mvn clean verify javadoc:javadoc |
| 69 | +} |
| 70 | + |
| 71 | +##################### |
| 72 | +# script |
| 73 | +##################### |
| 74 | +# Since the same script is run several times with different jdks by the build process, |
| 75 | +# only under certain conditions, a (snapshot) release should be built. |
| 76 | +# Among others, a build loop must be prevented after a "perform_release" build was executed. |
| 77 | +# All other cases (like pull requests) only perform a "verify" |
| 78 | +if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [[ ! "${TRAVIS_COMMIT_MESSAGE}" = \[maven-release-plugin\]* ]] && [ "${TRAVIS_JDK_VERSION}" = "openjdk8" ] |
| 79 | +then |
| 80 | + if [ "${TRAVIS_BRANCH}" = "develop" ] |
| 81 | + then |
| 82 | + perform_snapshot_release |
| 83 | + elif [[ "${TRAVIS_BRANCH}" = "master" ]] |
| 84 | + then |
| 85 | + perform_release |
| 86 | + else |
| 87 | + # will be done for all other branches pushed into this repository |
| 88 | + perform_verify |
| 89 | + fi |
| 90 | +else |
| 91 | + perform_verify |
| 92 | +fi |
0 commit comments