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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. ./.travis/setup_ramdisk.sh
  4. #
  5. # Configure Maven settings and install some script utilities
  6. #
  7. configureTravis() {
  8. mkdir -p ~/.local
  9. curl -sSL https://github.com/SonarSource/travis-utils/tarball/v62 | tar zx --strip-components 1 -C ~/.local
  10. # shellcheck disable=SC1090
  11. source ~/.local/bin/install
  12. }
  13. configureTravis
  14. #
  15. # Travis fails on timeout when build does not print logs
  16. # during 10 minutes. This aims to bypass this
  17. # behavior when building the slow sonar-server sub-project.
  18. #
  19. keep_alive() {
  20. while true; do
  21. echo -en "\a"
  22. sleep 60
  23. done
  24. }
  25. keep_alive &
  26. # When a pull request is open on the branch, then the job related
  27. # to the branch does not need to be executed and should be canceled.
  28. # It does not book slaves for nothing.
  29. # @TravisCI please provide the feature natively, like at AppVeyor or CircleCI ;-)
  30. cancel_branch_build_with_pr || if [[ $? -eq 1 ]]; then exit 0; fi
  31. # Used by Next
  32. INITIAL_VERSION=$(grep version gradle.properties | awk -F= '{print $2}')
  33. export INITIAL_VERSION
  34. source ./.travis/setup_environment.sh
  35. # Analyse SonarQube on NEXT
  36. export SONAR_HOST_URL=https://next.sonarqube.com/sonarqube
  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. BUILD_START_DATETIME=$(date --utc +%FT%TZ)
  44. echo "$BUILD_START_DATETIME" > /tmp/build_start_time
  45. ./gradlew build --console plain
  46. # exclude external pull requests
  47. if [[ -n "${NEXT_TOKEN-}" ]]; then
  48. sonar_params=(-Dsonar.projectKey=sonarqube
  49. -Dsonar.host.url="$SONAR_HOST_URL"
  50. -Dsonar.login="$NEXT_TOKEN"
  51. -Dsonar.analysis.buildNumber="$BUILD_NUMBER"
  52. -Dsonar.analysis.pipeline="$BUILD_NUMBER"
  53. -Dsonar.analysis.sha1="$GIT_SHA1"
  54. -Dsonar.analysis.repository="$TRAVIS_REPO_SLUG")
  55. if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
  56. echo '======= Analyze pull request'
  57. ./gradlew jacocoTestReport :server:sonar-web:yarn_validate-ci sonarqube --info --console plain \
  58. "${sonar_params[@]}" \
  59. -Dsonar.analysis.prNumber="$PULL_REQUEST_NUMBER" \
  60. -Dsonar.pullrequest.branch="$GIT_BRANCH" \
  61. -Dsonar.pullrequest.base="$PULL_REQUEST_BASE_BRANCH" \
  62. -Dsonar.pullrequest.key="$PULL_REQUEST_NUMBER"
  63. elif [ "${TRAVIS_BRANCH}" == "master" ]; then
  64. echo '======= Analyze master'
  65. ./gradlew jacocoTestReport :server:sonar-web:yarn_validate-ci sonarqube --info --console plain \
  66. "${sonar_params[@]}" \
  67. -Dsonar.projectVersion="$INITIAL_VERSION"
  68. else
  69. echo '======= Analyze branch'
  70. ./gradlew jacocoTestReport :server:sonar-web:yarn_validate-ci sonarqube --info --console plain \
  71. "${sonar_params[@]}" \
  72. -Dsonar.branch.name="$GIT_BRANCH" \
  73. -Dsonar.projectVersion="$INITIAL_VERSION"
  74. fi
  75. # Wait for 5mins, hopefully the report will be processed.
  76. sleep 5m
  77. ./.travis/run_iris.sh
  78. BUILD_END_DATETIME=$(date --utc +%FT%TZ)
  79. notify_burgr "build" "build" "$TRAVIS_JOB_WEB_URL" "$BUILD_START_DATETIME" "$BUILD_END_DATETIME" || true
  80. fi