diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-02-20 21:45:22 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-02-21 10:05:08 +0100 |
commit | 7def7f15c9d024f2941680b3a82bd8a35cbfcd7c (patch) | |
tree | 7f41ec952c077d4334678f9616874e9f62f068de /travis.sh | |
parent | 5f09ded3a60950b1db7714f70f66850216acbff9 (diff) | |
download | sonarqube-7def7f15c9d024f2941680b3a82bd8a35cbfcd7c.tar.gz sonarqube-7def7f15c9d024f2941680b3a82bd8a35cbfcd7c.zip |
Ability to release versions without build number in artifact filenames
Diffstat (limited to 'travis.sh')
-rwxr-xr-x | travis.sh | 110 |
1 files changed, 82 insertions, 28 deletions
diff --git a/travis.sh b/travis.sh index a68f7a2de11..8e32e42eb33 100755 --- a/travis.sh +++ b/travis.sh @@ -1,5 +1,4 @@ #!/bin/bash - set -euo pipefail function installPhantomJs { @@ -16,26 +15,92 @@ function installPhantomJs { export PATH=$PHANTOMJS_HOME/bin:$PATH } +# +# A (too) old version of JDK8 is installed by default on Travis +# +function installJdk8 { + echo "Setup JDK 1.8u92" + mkdir -p ~/jvm + pushd ~/jvm > /dev/null + if [ ! -d "jdk1.8.0_92" ]; then + wget -c --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u92-b14/jdk-8u92-linux-x64.tar.gz + tar xzf jdk-8u92-linux-x64.tar.gz + rm jdk-8u92-linux-x64.tar.gz + fi + popd > /dev/null + export JAVA_HOME=~/jvm/jdk1.8.0_92 + export PATH=$JAVA_HOME/bin:$PATH +} + +# +# Replaces the SNAPSHOT version by a version identifying the build. +# +# Exports the variables: +# - INITIAL_VERSION: version as defined in pom.xml +# - PROJECT_VERSION: build version. The name of this variable is important because +# it's used by QA when extracting version from Artifactory build info. +# +# The build version is composed of 4 fields, including the semantic version and +# the build number provided by Travis. +# +# Example +# Before: 6.3-SNAPSHOT +# After: 6.3.0.12345 +# +# Exception: GA release like "6.3" is kept as-is. +# +function fixBuildVersion { + export INITIAL_VERSION=`maven_expression "project.version"` + + # remove suffix like -SNAPSHOT or -RC + without_suffix=`echo $INITIAL_VERSION | sed "s/-.*//g"` + + # set the third field to '0' if missing, for example 6.3 becomes 6.3.0 + IFS=$'.' + fields_count=`echo $without_suffix | wc -w` + unset IFS + if [ $fields_count -lt 3 ]; then + without_suffix="$without_suffix.0" + fi + + export PROJECT_VERSION="$without_suffix.$TRAVIS_BUILD_NUMBER" + + echo "Source Version: $INITIAL_VERSION" + echo "Build Version : $PROJECT_VERSION" + + if [[ "$INITIAL_VERSION" == *"-"* ]]; then + # SNAPSHOT or RC + mvn org.codehaus.mojo:versions-maven-plugin:2.2:set -DnewVersion=$PROJECT_VERSION -DgenerateBackupPoms=false -B -e + fi +} + +# +# Configure Maven settings and install some script utilities +# function configureTravis { mkdir ~/.local curl -sSL https://github.com/SonarSource/travis-utils/tarball/v33 | tar zx --strip-components 1 -C ~/.local source ~/.local/bin/install } configureTravis -. installJDK8 - -./clock.sh & case "$TARGET" in -CI) - export MAVEN_OPTS="-Xmx1G -Xms128m" - MAVEN_OPTIONS="-Dmaven.test.redirectTestOutputToFile=false -Dsurefire.useFile=false -B -e -V" +BUILD) + + # Hack to keep job alive even if no logs during more than 10 minutes. + # That can occur when uploading sonarqube.zip to Artifactory. + ./clock.sh & + + installJdk8 + fixBuildVersion - INITIAL_VERSION=`maven_expression "project.version"` + # Minimal Maven settings + export MAVEN_OPTS="-Xmx1G -Xms128m" + MAVEN_ARGS="-Dmaven.test.redirectTestOutputToFile=false -Dsurefire.useFile=false -B -e -V -DbuildVersion=$PROJECT_VERSION" if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then - echo 'Analyse and trigger QA of master branch' + echo 'Build and analyze master' # Fetch all commit history so that SonarQube has exact blame information # for issue auto-assignment @@ -44,31 +109,23 @@ CI) # For this reason errors are ignored with "|| true" git fetch --unshallow || true - . set_maven_build_version $TRAVIS_BUILD_NUMBER - mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy sonar:sonar \ - $MAVEN_OPTIONS \ + $MAVEN_ARGS \ -Pdeploy-sonarsource,release \ -Dsonar.host.url=$SONAR_HOST_URL \ -Dsonar.login=$SONAR_TOKEN \ -Dsonar.projectVersion=$INITIAL_VERSION elif [[ "$TRAVIS_BRANCH" == "branch-"* ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then - echo 'release branch: trigger QA, no analysis' - - . set_maven_build_version $TRAVIS_BUILD_NUMBER + echo 'Build release branch' - mvn deploy \ - $MAVEN_OPTIONS \ - -Pdeploy-sonarsource,release + mvn deploy $MAVEN_ARGS -Pdeploy-sonarsource,release elif [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ -n "${GITHUB_TOKEN:-}" ]; then - echo 'Internal pull request: trigger QA and analysis' - - . set_maven_build_version $TRAVIS_BUILD_NUMBER + echo 'Build and analyze internal pull request' mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy sonar:sonar \ - $MAVEN_OPTIONS \ + $MAVEN_ARGS \ -Dsource.skip=true \ -Pdeploy-sonarsource \ -Dsonar.analysis.mode=preview \ @@ -79,19 +136,16 @@ CI) -Dsonar.login=$SONAR_TOKEN else - echo 'Feature branch or external pull request: no QA, no analysis. Skip sources' + echo 'Build feature branch or external pull request' - mvn install \ - $MAVEN_OPTIONS \ - -Dsource.skip=true + mvn install $MAVEN_ARGS -Dsource.skip=true fi - installPhantomJs ./run-integration-tests.sh "Lite" "" -Dorchestrator.browser=phantomjs ;; -WEB) +WEB_TESTS) set +u source ~/.nvm/nvm.sh && nvm install 6 curl -o- -L https://yarnpkg.com/install.sh | bash |