You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

travis.sh 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #!/bin/bash
  2. set -euo pipefail
  3. function installPhantomJs {
  4. echo "Setup PhantomJS 2.1"
  5. mkdir -p ~/phantomjs
  6. pushd ~/phantomjs > /dev/null
  7. if [ ! -d "phantomjs-2.1.1-linux-x86_64" ]; then
  8. echo "Download PhantomJS"
  9. wget https://repox.sonarsource.com/public-3rd-parties/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O phantomjs-2.1.1-linux-x86_64.tar.bz2
  10. tar -xf phantomjs-2.1.1-linux-x86_64.tar.bz2
  11. rm phantomjs-2.1.1-linux-x86_64.tar.bz2
  12. fi
  13. popd > /dev/null
  14. export PHANTOMJS_HOME=~/phantomjs/phantomjs-2.1.1-linux-x86_64
  15. export PATH=$PHANTOMJS_HOME/bin:$PATH
  16. }
  17. #
  18. # A (too) old version of JDK8 is installed by default on Travis.
  19. # This method is preferred over Travis apt oracle-java8-installer because
  20. # JDK is kept in cache. It does not need to be downloaded from Oracle
  21. # at each build.
  22. #
  23. function installJdk8 {
  24. echo "Setup JDK 1.8u131"
  25. mkdir -p ~/jvm
  26. pushd ~/jvm > /dev/null
  27. if [ ! -d "jdk1.8.0_131" ]; then
  28. wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
  29. tar xzf jdk-8u131-linux-x64.tar.gz
  30. rm jdk-8u131-linux-x64.tar.gz
  31. fi
  32. popd > /dev/null
  33. export JAVA_HOME=~/jvm/jdk1.8.0_131
  34. export PATH=$JAVA_HOME/bin:$PATH
  35. }
  36. #
  37. # Maven 3.2.5 is installed by default on Travis. Maven 3.3.9 is preferred.
  38. #
  39. function installMaven {
  40. echo "Setup Maven"
  41. mkdir -p ~/maven
  42. pushd ~/maven > /dev/null
  43. if [ ! -d "apache-maven-3.3.9" ]; then
  44. echo "Download Maven 3.3.9"
  45. curl -sSL http://apache.mirrors.ovh.net/ftp.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz | tar zx -C ~/maven
  46. fi
  47. popd > /dev/null
  48. export M2_HOME=~/maven/apache-maven-3.3.9
  49. export PATH=$M2_HOME/bin:$PATH
  50. }
  51. #
  52. # Replaces the version defined in sources, usually x.y-SNAPSHOT,
  53. # by a version identifying the build.
  54. # The build version is composed of 4 fields, including the semantic version and
  55. # the build number provided by Travis.
  56. #
  57. # Exported variables:
  58. # - INITIAL_VERSION: version as defined in pom.xml
  59. # - BUILD_VERSION: version including the build number
  60. # - PROJECT_VERSION: target Maven version. The name of this variable is important because
  61. # it's used by QA when extracting version from Artifactory build info.
  62. #
  63. # Example of SNAPSHOT
  64. # INITIAL_VERSION=6.3-SNAPSHOT
  65. # BUILD_VERSION=6.3.0.12345
  66. # PROJECT_VERSION=6.3.0.12345
  67. #
  68. # Example of RC
  69. # INITIAL_VERSION=6.3-RC1
  70. # BUILD_VERSION=6.3.0.12345
  71. # PROJECT_VERSION=6.3-RC1
  72. #
  73. # Example of GA
  74. # INITIAL_VERSION=6.3
  75. # BUILD_VERSION=6.3.0.12345
  76. # PROJECT_VERSION=6.3
  77. #
  78. function fixBuildVersion {
  79. export INITIAL_VERSION=`maven_expression "project.version"`
  80. # remove suffix -SNAPSHOT or -RC
  81. without_suffix=`echo $INITIAL_VERSION | sed "s/-.*//g"`
  82. IFS=$'.'
  83. fields_count=`echo $without_suffix | wc -w`
  84. unset IFS
  85. if [ $fields_count -lt 3 ]; then
  86. export BUILD_VERSION="$without_suffix.0.$TRAVIS_BUILD_NUMBER"
  87. else
  88. export BUILD_VERSION="$without_suffix.$TRAVIS_BUILD_NUMBER"
  89. fi
  90. if [[ "${INITIAL_VERSION}" == *"-SNAPSHOT" ]]; then
  91. # SNAPSHOT
  92. export PROJECT_VERSION=$BUILD_VERSION
  93. mvn org.codehaus.mojo:versions-maven-plugin:2.2:set -DnewVersion=$PROJECT_VERSION -DgenerateBackupPoms=false -B -e
  94. else
  95. # not a SNAPSHOT: milestone, RC or GA
  96. export PROJECT_VERSION=$INITIAL_VERSION
  97. fi
  98. echo "Build Version : $BUILD_VERSION"
  99. echo "Project Version: $PROJECT_VERSION"
  100. }
  101. #
  102. # Configure Maven settings and install some script utilities
  103. #
  104. function configureTravis {
  105. mkdir ~/.local
  106. curl -sSL https://github.com/SonarSource/travis-utils/tarball/v36 | tar zx --strip-components 1 -C ~/.local
  107. source ~/.local/bin/install
  108. }
  109. configureTravis
  110. # When pull request exists on the branch, then the job related to the branch does not need
  111. # to be executed and should be canceled. It does not book slaves for nothing.
  112. # @TravisCI please provide the feature natively, like at AppVeyor or CircleCI ;-)
  113. cancel_branch_build_with_pr
  114. case "$TARGET" in
  115. BUILD)
  116. # Hack to keep job alive even if no logs during more than 10 minutes.
  117. # That can occur when uploading sonarqube.zip to Artifactory.
  118. ./clock.sh &
  119. installJdk8
  120. installMaven
  121. fixBuildVersion
  122. # Minimal Maven settings
  123. export MAVEN_OPTS="-Xmx1G -Xms128m"
  124. MAVEN_ARGS="-Dmaven.test.redirectTestOutputToFile=false -Dsurefire.useFile=false -B -e -V -DbuildVersion=$BUILD_VERSION"
  125. if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  126. echo 'Build and analyze master'
  127. # Fetch all commit history so that SonarQube has exact blame information
  128. # for issue auto-assignment
  129. # This command can fail with "fatal: --unshallow on a complete repository does not make sense"
  130. # if there are not enough commits in the Git repository (even if Travis executed git clone --depth 50).
  131. # For this reason errors are ignored with "|| true"
  132. git fetch --unshallow || true
  133. mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy sonar:sonar \
  134. $MAVEN_ARGS \
  135. -Pdeploy-sonarsource,release \
  136. -Dsonar.host.url=$SONAR_HOST_URL \
  137. -Dsonar.login=$SONAR_TOKEN \
  138. -Dsonar.projectVersion=$INITIAL_VERSION
  139. elif [[ "$TRAVIS_BRANCH" == "branch-"* ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  140. echo 'Build release branch'
  141. mvn deploy $MAVEN_ARGS -Pdeploy-sonarsource,release
  142. elif [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ -n "${GITHUB_TOKEN:-}" ]; then
  143. echo 'Build and analyze internal pull request'
  144. mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy sonar:sonar \
  145. $MAVEN_ARGS \
  146. -Dsource.skip=true \
  147. -Pdeploy-sonarsource \
  148. -Dsonar.analysis.mode=preview \
  149. -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST \
  150. -Dsonar.github.repository=$TRAVIS_REPO_SLUG \
  151. -Dsonar.github.oauth=$GITHUB_TOKEN \
  152. -Dsonar.host.url=$SONAR_HOST_URL \
  153. -Dsonar.login=$SONAR_TOKEN
  154. else
  155. echo 'Build feature branch or external pull request'
  156. mvn install $MAVEN_ARGS -Dsource.skip=true
  157. fi
  158. installPhantomJs
  159. ./run-integration-tests.sh "Lite" "" -Dorchestrator.browser=phantomjs
  160. ;;
  161. WEB_TESTS)
  162. set +u
  163. source ~/.nvm/nvm.sh && nvm install 6
  164. curl -o- -L https://yarnpkg.com/install.sh | bash
  165. export PATH=$HOME/.yarn/bin:$PATH
  166. cd server/sonar-web && yarn && yarn validate
  167. ;;
  168. *)
  169. echo "Unexpected TARGET value: $TARGET"
  170. exit 1
  171. ;;
  172. esac
  173. #stop the clock
  174. touch stop