forked from SonarSource/sonar-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
travis.sh
executable file
·138 lines (116 loc) · 5.16 KB
/
travis.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
set -euo pipefail
function configureTravis {
mkdir -p ~/.local
curl -sSL https://github.com/SonarSource/travis-utils/tarball/v43 | tar zx --strip-components 1 -C ~/.local
source ~/.local/bin/install
}
configureTravis
. ~/.local/bin/installMaven35
function strongEcho {
echo ""
echo "================ $1 ================="
}
case "$TEST" in
CI)
if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
SONAR_PROJECT_VERSION=`maven_expression "project.version"`
# Do not deploy a SNAPSHOT version but the release version related to this build
. set_maven_build_version $TRAVIS_BUILD_NUMBER
# integration of jacoco report is quite memory-consuming
export MAVEN_OPTS="-Xmx1536m -Xms128m"
git fetch --unshallow
strongEcho "Build commit in master"
mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy -B -e -V \
-Dmaven.test.redirectTestOutputToFile=false \
-Pcoverage-per-test,deploy-sonarsource,release
strongEcho "Analyze commit in master"
# do not use 'deploy' goal, which makes shade plugin hide some of the modules (notably sonar-jacoco-previous)
mvn sonar:sonar -B -e -V \
-Dsonar.analysis.buildNumber=$TRAVIS_BUILD_NUMBER \
-Dsonar.analysis.pipeline=$TRAVIS_BUILD_NUMBER \
-Dsonar.analysis.sha1=$TRAVIS_COMMIT \
-Dsonar.analysis.repository=$TRAVIS_REPO_SLUG \
-Dsonar.host.url=$SONAR_HOST_URL \
-Dsonar.projectVersion=$SONAR_PROJECT_VERSION \
-Dsonar.login=$SONAR_TOKEN
elif [[ "${TRAVIS_BRANCH}" == "branch-"* ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
# no dory analysis on release branch
# Fetch all commit history so that SonarQube has exact blame information
# for issue auto-assignment
# This command can fail with "fatal: --unshallow on a complete repository does not make sense"
# if there are not enough commits in the Git repository (even if Travis executed git clone --depth 50).
# For this reason errors are ignored with "|| true"
git fetch --unshallow || true
# get current version from pom
CURRENT_VERSION=`maven_expression "project.version"`
if [[ $CURRENT_VERSION =~ "-SNAPSHOT" ]]; then
echo "======= Found SNAPSHOT version ======="
# Do not deploy a SNAPSHOT version but the release version related to this build
. set_maven_build_version $TRAVIS_BUILD_NUMBER
else
echo "======= Found RELEASE version ======="
fi
export MAVEN_OPTS="-Xmx1536m -Xms128m"
mvn deploy \
-Pdeploy-sonarsource,release \
-B -e -V $*
elif [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
strongEcho "Build and analyze pull request"
export MAVEN_OPTS="-Xmx1G -Xms128m"
git fetch --unshallow || true
SONAR_PROJECT_VERSION=`maven_expression "project.version"`
if [ -n "${GITHUB_TOKEN-}" ]; then
strongEcho "Build SonarSource pull request"
# Do not deploy a SNAPSHOT version but the release version related to this build
. set_maven_build_version $TRAVIS_BUILD_NUMBER
mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy -B -e -V \
-Pcoverage-per-test,deploy-sonarsource
strongEcho "Branch analysis"
# do not use 'deploy' goal, which makes shade plugin hide some of the modules (notably sonar-jacoco-previous)
mvn sonar:sonar -B -e -V \
-Dsonar.host.url=$SONAR_HOST_URL \
-Dsonar.login=$SONAR_TOKEN \
-Dsonar.analysis.buildNumber=$TRAVIS_BUILD_NUMBER \
-Dsonar.analysis.pipeline=$TRAVIS_BUILD_NUMBER \
-Dsonar.analysis.sha1=$TRAVIS_PULL_REQUEST_SHA \
-Dsonar.analysis.repository=$TRAVIS_REPO_SLUG \
-Dsonar.analysis.prNumber=$TRAVIS_PULL_REQUEST \
-Dsonar.branch.name=$TRAVIS_PULL_REQUEST_BRANCH \
-Dsonar.branch.target=$TRAVIS_BRANCH \
-Dsonar.pullrequest.github.id=$TRAVIS_PULL_REQUEST \
-Dsonar.pullrequest.github.repository=$TRAVIS_REPO_SLUG
else
strongEcho "External pull request"
# external PR : no deployment to repox
mvn install sonar:sonar -B -e -V \
-Dsonar.analysis.mode=issues \
-Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST \
-Dsonar.github.repository=$TRAVIS_REPO_SLUG \
-Dsonar.github.oauth=$GITHUB_TOKEN_EXTERNAL_PR \
-Dsonar.host.url=$SONAR_HOST_URL_EXTERNAL_PR \
-Dsonar.login=$SONAR_TOKEN_EXTERNAL_PR
fi
else
strongEcho 'Build, no analysis'
# Build branch, without any analysis
# No need for Maven goal "install" as the generated JAR file does not need to be installed
# in Maven local repository
mvn verify -B -e -V
fi
;;
ruling)
if [ "$TRAVIS_PULL_REQUEST" == "false" ] || [ -n "${GITHUB_TOKEN-}" ]; then
strongEcho "External Pull Request ONLY. For internal PRs, ruling is only played during internal QA!"
exit 0;
fi
[ "$TEST" = "ruling" ] && git submodule update --init --recursive
EXTRA_PARAMS=
[ -n "${PROJECT:-}" ] && EXTRA_PARAMS="-DfailIfNoTests=false -Dtest=JavaRulingTest#$PROJECT"
mvn install -Dsonar.runtimeVersion="$SQ_VERSION" -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Pit-$TEST $EXTRA_PARAMS
;;
*)
echo "Unexpected TEST mode: $TEST"
exit 1
;;
esac