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 | |
parent | 5f09ded3a60950b1db7714f70f66850216acbff9 (diff) | |
download | sonarqube-7def7f15c9d024f2941680b3a82bd8a35cbfcd7c.tar.gz sonarqube-7def7f15c9d024f2941680b3a82bd8a35cbfcd7c.zip |
Ability to release versions without build number in artifact filenames
-rw-r--r-- | .travis.yml | 4 | ||||
-rw-r--r-- | sonar-plugin-api/pom.xml | 22 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/resources/sonar-api-version.txt | 2 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/resources/sq-version.txt | 2 | ||||
-rwxr-xr-x | travis.sh | 110 |
5 files changed, 102 insertions, 38 deletions
diff --git a/.travis.yml b/.travis.yml index b089bd33d91..a6f90221a1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,8 @@ jdk: oraclejdk8 script: ./travis.sh env: - - TARGET=CI - - TARGET=WEB + - TARGET=BUILD + - TARGET=WEB_TESTS matrix: fast_finish: true diff --git a/sonar-plugin-api/pom.xml b/sonar-plugin-api/pom.xml index 2cef8a0681f..e5dd6de1916 100644 --- a/sonar-plugin-api/pom.xml +++ b/sonar-plugin-api/pom.xml @@ -14,7 +14,18 @@ <name>SonarQube :: Plugin API</name> <properties> - <project.version.3digits>${project.version}</project.version.3digits> + <!-- + version as stored in JAR and displayed in webapp. It is + overridden on Travis when replacing SNAPSHOT version by + build unique version, for instance "6.3.0.12345". + --> + <buildVersion>${project.version}</buildVersion> + + <!-- + a truncated version on three fields is kept for backward-compatibility + with scanners + --> + <buildVersionOnThreeFields>${buildVersion}</buildVersionOnThreeFields> </properties> <dependencies> @@ -222,23 +233,22 @@ <artifactId>groovy-maven-plugin</artifactId> <executions> <execution> - <id>compute-3digits-version</id> + <id>compute-version-on-three-fields</id> <phase>generate-resources</phase> <goals> <goal>execute</goal> </goals> <configuration> <source><![CDATA[ - if (! "${project.version}".endsWith("-SNAPSHOT")) { + if (! "${buildVersion}".endsWith("-SNAPSHOT")) { String apiVersion - // example: "6.3.0.1234". To be backward-compatible with scanners, only "6.3.0" must be kept - String[] fields = "${project.version}".tokenize('.') + String[] fields = "${buildVersion}".tokenize('.') if (fields.length > 3) { apiVersion = fields[0..2].join('.') } else { apiVersion = fields.join('.') } - project.properties['project.version.3digits'] = apiVersion + project.properties['buildVersionOnThreeFields'] = apiVersion } ]]> </source> diff --git a/sonar-plugin-api/src/main/resources/sonar-api-version.txt b/sonar-plugin-api/src/main/resources/sonar-api-version.txt index ad96e7cf933..6b7ce460f25 100644 --- a/sonar-plugin-api/src/main/resources/sonar-api-version.txt +++ b/sonar-plugin-api/src/main/resources/sonar-api-version.txt @@ -1 +1 @@ -${project.version} +${buildVersion} diff --git a/sonar-plugin-api/src/main/resources/sq-version.txt b/sonar-plugin-api/src/main/resources/sq-version.txt index b9ca09a01c9..ab8c87a30ad 100644 --- a/sonar-plugin-api/src/main/resources/sq-version.txt +++ b/sonar-plugin-api/src/main/resources/sq-version.txt @@ -1 +1 @@ -${project.version.3digits}
\ No newline at end of file +${buildVersionOnThreeFields} 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 |