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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. 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
  9. tar -xf phantomjs-2.1.1-linux-x86_64.tar.bz2
  10. rm phantomjs-2.1.1-linux-x86_64.tar.bz2
  11. fi
  12. popd > /dev/null
  13. export PHANTOMJS_HOME=~/phantomjs/phantomjs-2.1.1-linux-x86_64
  14. export PATH=$PHANTOMJS_HOME/bin:$PATH
  15. }
  16. function configureTravis {
  17. mkdir ~/.local
  18. curl -sSL https://github.com/SonarSource/travis-utils/tarball/v31 | tar zx --strip-components 1 -C ~/.local
  19. source ~/.local/bin/install
  20. }
  21. configureTravis
  22. . installJDK8
  23. case "$TARGET" in
  24. CI)
  25. export MAVEN_OPTS="-Xmx1G -Xms128m"
  26. MAVEN_OPTIONS="-Dmaven.test.redirectTestOutputToFile=false -Dsurefire.useFile=false -B -e -V"
  27. INITIAL_VERSION=`maven_expression "project.version"`
  28. if [[ $INITIAL_VERSION =~ "-SNAPSHOT" ]]; then
  29. echo "======= Found SNAPSHOT version ======="
  30. # Do not deploy a SNAPSHOT version but the release version related to this build
  31. set_maven_build_version $TRAVIS_BUILD_NUMBER
  32. else
  33. echo "======= Found RELEASE version ======="
  34. fi
  35. if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  36. echo 'Analyse and trigger QA of master branch'
  37. # Fetch all commit history so that SonarQube has exact blame information
  38. # for issue auto-assignment
  39. # This command can fail with "fatal: --unshallow on a complete repository does not make sense"
  40. # if there are not enough commits in the Git repository (even if Travis executed git clone --depth 50).
  41. # For this reason errors are ignored with "|| true"
  42. git fetch --unshallow || true
  43. mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy sonar:sonar \
  44. $MAVEN_OPTIONS \
  45. -Pdeploy-sonarsource \
  46. -Dsonar.host.url=$SONAR_HOST_URL \
  47. -Dsonar.login=$SONAR_TOKEN \
  48. -Dsonar.projectVersion=$INITIAL_VERSION
  49. elif [[ "$TRAVIS_BRANCH" == "branch-"* ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  50. echo 'release branch: trigger QA, no analysis'
  51. mvn deploy \
  52. $MAVEN_OPTIONS \
  53. -Pdeploy-sonarsource
  54. elif [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ -n "${GITHUB_TOKEN:-}" ]; then
  55. echo 'Internal pull request: trigger QA and analysis'
  56. mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy sonar:sonar \
  57. $MAVEN_OPTIONS \
  58. -Dsource.skip=true \
  59. -Pdeploy-sonarsource \
  60. -Dsonar.analysis.mode=preview \
  61. -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST \
  62. -Dsonar.github.repository=$TRAVIS_REPO_SLUG \
  63. -Dsonar.github.oauth=$GITHUB_TOKEN \
  64. -Dsonar.host.url=$SONAR_HOST_URL \
  65. -Dsonar.login=$SONAR_TOKEN
  66. else
  67. echo 'Feature branch or external pull request: no QA, no analysis. Skip sources'
  68. mvn install \
  69. $MAVEN_OPTIONS \
  70. -Dsource.skip=true
  71. fi
  72. installPhantomJs
  73. ./run-integration-tests.sh "Lite" "" -Dorchestrator.browser=phantomjs
  74. ;;
  75. WEB)
  76. set +eu
  77. source ~/.nvm/nvm.sh && nvm install 4
  78. npm install -g npm@3.5.2
  79. cd server/sonar-web && npm install && npm test
  80. ;;
  81. *)
  82. echo "Unexpected TARGET value: $TARGET"
  83. exit 1
  84. ;;
  85. esac