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.2KB

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