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 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/bin/bash
  2. set -euo pipefail
  3. ./.travis/setup_ramdisk.sh
  4. #
  5. # A (too) old version of JDK8 is installed by default on Travis.
  6. # This method is preferred over Travis apt oracle-java8-installer because
  7. # JDK is kept in cache. It does not need to be downloaded from Oracle
  8. # at each build.
  9. #
  10. function installJDK8 {
  11. JDK_RELEASE=201
  12. echo "Setup JDK 1.8u$JDK_RELEASE"
  13. mkdir -p ~/jvm
  14. pushd ~/jvm > /dev/null
  15. if [ ! -d "jdk1.8.0_$JDK_RELEASE" ]; then
  16. {
  17. wget --quiet --continue --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz
  18. } || {
  19. echo "failed to download JDK 1.8u$JDK_RELEASE"
  20. exit 1
  21. }
  22. tar xzf jdk-8u$JDK_RELEASE-linux-x64.tar.gz
  23. rm jdk-8u$JDK_RELEASE-linux-x64.tar.gz
  24. fi
  25. popd > /dev/null
  26. export JAVA_HOME=~/jvm/jdk1.8.0_$JDK_RELEASE
  27. export PATH=$JAVA_HOME/bin:$PATH
  28. echo "JDK 1.8u$JDK_RELEASE installed"
  29. }
  30. #
  31. # Maven 3.2.5 is installed by default on Travis. Maven 3.5 is preferred.
  32. #
  33. function installMaven {
  34. echo "Setup Maven"
  35. mkdir -p ~/maven
  36. pushd ~/maven > /dev/null
  37. if [ ! -d "apache-maven-3.5.4" ]; then
  38. echo "Download Maven 3.5.4"
  39. curl -sSL https://archive.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz | tar zx -C ~/maven
  40. fi
  41. popd > /dev/null
  42. export M2_HOME=~/maven/apache-maven-3.5.4
  43. export PATH=$M2_HOME/bin:$PATH
  44. echo 'Maven installed'
  45. }
  46. function installNode {
  47. set +u
  48. source ~/.nvm/nvm.sh && nvm install 8
  49. set -u
  50. echo 'Node installed'
  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/v55 | tar zx --strip-components 1 -C ~/.local
  108. source ~/.local/bin/install
  109. }
  110. configureTravis
  111. # When a pull request is open on the branch, then the job related
  112. # to the branch does not need to be executed and should be canceled.
  113. # It does not book slaves for nothing.
  114. # @TravisCI please provide the feature natively, like at AppVeyor or CircleCI ;-)
  115. cancel_branch_build_with_pr || if [[ $? -eq 1 ]]; then exit 0; fi
  116. case "$TARGET" in
  117. BUILD)
  118. installJDK8
  119. installMaven
  120. installNode
  121. fixBuildVersion
  122. # Minimal Maven settings
  123. export MAVEN_OPTS="-Xmx1G -Xms128m"
  124. MAVEN_ARGS="-T 1C -Dmaven.test.redirectTestOutputToFile=false -Dsurefire.useFile=false -B -e -V -DbuildVersion=$BUILD_VERSION -Dtests.es.logger.level=WARN -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn"
  125. if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  126. echo 'Build and analyze master'
  127. mvn deploy \
  128. $MAVEN_ARGS \
  129. -Pdeploy-sonarsource,release
  130. elif [[ "$TRAVIS_BRANCH" == "branch-"* ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  131. echo 'Build release branch'
  132. mvn deploy \
  133. $MAVEN_ARGS \
  134. -Pdeploy-sonarsource,release
  135. elif [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ -n "${GITHUB_TOKEN:-}" ]; then
  136. echo 'Build and analyze internal pull request'
  137. mvn deploy \
  138. $MAVEN_ARGS \
  139. -Dsource.skip=true \
  140. -Pdeploy-sonarsource
  141. else
  142. echo 'Build feature branch or external pull request'
  143. mvn install $MAVEN_ARGS -Dsource.skip=true
  144. fi
  145. ./run-integration-tests.sh "Lite" ""
  146. ;;
  147. WEB_TESTS)
  148. installNode
  149. curl -o- -L https://yarnpkg.com/install.sh | bash
  150. export PATH=$HOME/.yarn/bin:$PATH
  151. cd server/sonar-web && yarn && yarn validate
  152. ;;
  153. *)
  154. echo "Unexpected TARGET value: $TARGET"
  155. exit 1
  156. ;;
  157. esac