From: Simon Brandhof Date: Tue, 24 Nov 2015 16:42:32 +0000 (+0100) Subject: Improve travis.sh X-Git-Tag: 5.3-RC1~183 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=76b953f99279d1d8eb7e737a4064e5afe4ca17d7;p=sonarqube.git Improve travis.sh - Upgrade to travis-utils v21 - Merge PR analysis with CI - rename variables - execute IT category "plugins" if PR from same repo - fail if unknown $TARGET --- diff --git a/.travis.yml b/.travis.yml index c09504454c1..51db84b6e04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,23 +5,24 @@ jdk: oraclejdk7 script: ./travis.sh env: - - JOB=H2 - - JOB=POSTGRES - - JOB=MYSQL - - JOB=WEB - - JOB=ITS IT_CATEGORY=Category1 - - JOB=ITS IT_CATEGORY=Category2 - - JOB=ITS IT_CATEGORY=Category3 - - JOB=ITS IT_CATEGORY=Category4 - - JOB=ITS IT_CATEGORY=Plugins - - JOB=PULL_REQUEST_ANALYSIS + - TARGET=CI + - TARGET=POSTGRES + - TARGET=MYSQL + - TARGET=WEB + - TARGET=IT IT_CATEGORY=Category1 + - TARGET=IT IT_CATEGORY=Category2 + - TARGET=IT IT_CATEGORY=Category3 + - TARGET=IT IT_CATEGORY=Category4 + - TARGET=IT IT_CATEGORY=Plugins + matrix: fast_finish: true cache: directories: - - '$HOME/.m2/repository' + - $HOME/.m2/repository + - $HOME/.sonar - 'server/sonar-web/node' - 'server/sonar-web/node_modules' diff --git a/travis.sh b/travis.sh index 59af62537aa..ecb548df478 100755 --- a/travis.sh +++ b/travis.sh @@ -4,14 +4,50 @@ set -euo pipefail function installTravisTools { mkdir ~/.local - curl -sSL https://github.com/SonarSource/travis-utils/tarball/v19 | tar zx --strip-components 1 -C ~/.local + curl -sSL https://github.com/SonarSource/travis-utils/tarball/v21 | tar zx --strip-components 1 -C ~/.local source ~/.local/bin/install } -case "$JOB" in +function strongEcho { + echo "" + echo "================ $1 =================" +} + +case "$TARGET" in + +CI) + if [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ -n "$SONAR_GITHUB_OAUTH" ]; then + # For security reasons environment variables are not available on the pull requests + # coming from outside repositories + # http://docs.travis-ci.com/user/pull-requests/#Security-Restrictions-when-testing-Pull-Requests + # That's why the analysis does not need to be executed if the variable SONAR_GITHUB_OAUTH is not defined. + + strongEcho 'Build and analyze pull request' + # this pull request must be built and analyzed (without upload of report) + mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent verify -Pcoverage-per-test,analysis -Dclirr=true -Dmaven.test.redirectTestOutputToFile=false -B -e -V -H2) - mvn verify -B -e -V + # Switch to java 8 as the Dory HTTPS certificate is not supported by Java 7 + export JAVA_HOME=/usr/lib/jvm/java-8-oracle + export PATH=$JAVA_HOME/bin:$PATH + + mvn sonar:sonar -B -e -V \ + -Dsonar.analysis.mode=issues \ + -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST \ + -Dsonar.github.repository=$TRAVIS_REPO_SLUG \ + -Dsonar.github.oauth=$SONAR_GITHUB_OAUTH \ + -Dsonar.host.url=$SONAR_HOST_URL \ + -Dsonar.login=$SONAR_LOGIN \ + -Dsonar.password=$SONAR_PASSWORD + + + else + strongEcho 'Build, no analysis' + # Build branch, without any analysis + + # No need for Maven goal "install" as the generated JAR file does not need to be installed + # in Maven local repository + mvn verify -Dmaven.test.redirectTestOutputToFile=false -B -e -V + fi ;; POSTGRES) @@ -34,44 +70,14 @@ MYSQL) ;; WEB) -set +eu + set +eu source ~/.nvm/nvm.sh && nvm install 4 cd server/sonar-web && npm install && npm test ;; -PULL_REQUEST_ANALYSIS) - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then - - # For security reasons environment variables are not available on the pull requests - # coming from outside repositories - # http://docs.travis-ci.com/user/pull-requests/#Security-Restrictions-when-testing-Pull-Requests - if [ -n "$SONAR_GITHUB_OAUTH" ]; then - - # Switch to java 8 as the Dory HTTPS certificate is not supported by Java 7 - export JAVA_HOME=/usr/lib/jvm/java-8-oracle - export PATH=$JAVA_HOME/bin:$PATH - - echo "Analyze pull request" - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent verify sonar:sonar -B -e -V -Panalysis \ - -Dmaven.test.failure.ignore=true \ - -Dclirr=true \ - -Dsonar.analysis.mode=issues \ - -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST \ - -Dsonar.github.repository=$TRAVIS_REPO_SLUG \ - -Dsonar.github.login=$SONAR_GITHUB_LOGIN \ - -Dsonar.github.oauth=$SONAR_GITHUB_OAUTH \ - -Dsonar.host.url=$SONAR_HOST_URL \ - -Dsonar.login=$SONAR_LOGIN \ - -Dsonar.password=$SONAR_PASSWORD - else - echo "Pull requests are not analyzed when coming from outside repositories" - fi - fi - ;; - -ITS) - if [ "$IT_CATEGORY" == "Plugins" ] && [ "$TRAVIS_PULL_REQUEST" != "false" ]; then - echo "Ignore this job since it needs access to private test licenses." +IT) + if [ "$IT_CATEGORY" == "Plugins" ] && [ -n "$SONAR_GITHUB_OAUTH" ]; then + echo "This job is ignored as it needs to access a private GitHub repository" else installTravisTools @@ -81,4 +87,9 @@ ITS) fi ;; +*) + echo "Unexpected TARGET value: $TARGET" + exit 1 + ;; + esac