-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun-sonar.sh
More file actions
executable file
·151 lines (131 loc) · 4.5 KB
/
Copy pathrun-sonar.sh
File metadata and controls
executable file
·151 lines (131 loc) · 4.5 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
SONAR_ZIP_FILENAME="sonar-scanner-cli-3.3.0.zip"
SONAR_EXTRACTED_FOLDER="sonar-scanner-3.3.0"
function install() {
wget -N "https://s3-eu-west-1.amazonaws.com/saga-ops/${SONAR_ZIP_FILENAME}";
unzip -o "${SONAR_ZIP_FILENAME}";
}
function getJsCoverage() {
if [ -f "sonar-project.properties" ];
then SAGA_JS_COV=$(<sonar-project.properties grep 'sonar.javascript.lcov.reportPath=' | grep -o '[^=]*$');
fi
if [ -z $SAGA_JS_COV ] & [ -f "coverage/lcov.info" ];
then SAGA_JS_COV="lcov_report.info"
sed -e "s=/var/www=$(pwd)=" coverage/lcov.info > "$SAGA_JS_COV";
fi
if [ $SAGA_JS_COV ];
then DEFAULT_SONAR_PARAMS+=" -Dsonar.javascript.lcov.reportPath=$SAGA_JS_COV";
fi
}
function getPyCoverage() {
if [ -f "sonar-project.properties" ];
then SAGA_PY_COV=$(<sonar-project.properties grep 'sonar.python.coverage.reportPath=' | grep -o '[^=]*$');
fi
if [ -z $SAGA_PY_COV ] & [ -f "coverage/cov.xml" ];
then SAGA_PY_COV="coverage/cov.xml"
fi
if [ $SAGA_PY_COV ];
then DEFAULT_SONAR_PARAMS+=" -Dsonar.python.coverage.reportPath=$SAGA_PY_COV";
fi
}
function getPyLintReport() {
# detect if is python project;
if (( $(find $SAGA_SOURCE_DIR | grep .py$ | wc -l) == 0 ));
then return; # Not a python project
fi
if [ -f "sonar-project.properties" ];
then SAGA_PY_LINT=$(<sonar-project.properties grep 'sonar.python.pylint.reportPath =' | grep -o '[^=]*$');
fi
if [ -z $SAGA_PY_LINT ];
then if [ -f "coverage/pylint.report" ];
then DEFAULT_SONAR_PARAMS+=" -sonar.python.pylint.reportPath=coverage/pylint.report";
else pip install pylint;
fi
fi
}
function findSourceDir() {
if [ $SAGA_SOURCE_DIR ]; then return; fi;
if [ -f "sonar-project.properties" ];
then SAGA_SOURCE_DIR=$(<sonar-project.properties grep 'sonar.sources=' | grep -o '[^=]*$');
fi
if [ $SAGA_SOURCE_DIR ]; then return; fi;
if [ -d "src" ];
then SAGA_SOURCE_DIR="src"
else echo "No src folder and no sonar-project.properties file."
echo "Can't find project's sources."
exit -1
fi
}
function run() {
findSourceDir;
# Params used everywhere
DEFAULT_SONAR_PARAMS="-Dsonar.host.url=$SONAR_HOST
-Dsonar.login=$SONAR_LOGIN
-Dsonar.password=$SONAR_PASSWORD
-Dsonar.projectName=$CIRCLE_PROJECT_REPONAME
-Dsonar.projectVersion=$CIRCLE_BUILD_NUM
-Dsonar.links.homepage=$CIRCLE_REPOSITORY_URL
-Dsonar.links.ci=$CIRCLE_BUILD_URL
-Dsonar.links.issue=$CIRCLE_REPOSITORY_URL/issues
-Dsonar.links.scm=$CIRCLE_REPOSITORY_URL
-Dsonar.sourceEncoding=UTF-8
-Dsonar.sources=$SAGA_SOURCE_DIR"
if [ $CIRCLE_PULL_REQUEST ] || [ "$CIRCLE_BRANCH" == "master" ]
then
getJsCoverage;
getPyCoverage;
getPyLintReport;
if [ $CIRCLE_PULL_REQUEST ];
then
SONAR_PROJECT_KEY=$CIRCLE_PROJECT_USERNAME:$CIRCLE_PROJECT_REPONAME;
./$SONAR_EXTRACTED_FOLDER/bin/sonar-scanner $DEFAULT_SONAR_PARAMS \
-Dsonar.projectKey=$SONAR_PROJECT_KEY \
-Dsonar.github.repository=$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME \
-Dsonar.github.pullRequest=${CI_PULL_REQUEST##*/} \
-Dsonar.github.oauth=$SAGA_STALIN_TOKEN;
elif [ "$CIRCLE_BRANCH" == "master" ];
then
./$SONAR_EXTRACTED_FOLDER/bin/sonar-scanner $DEFAULT_SONAR_PARAMS \
-Dsonar.projectKey=$CIRCLE_PROJECT_USERNAME:$CIRCLE_PROJECT_REPONAME;
fi
else
echo "To analyze your code you must create a pull request and relaunch analysis"
fi
}
function check() {
if type -p java; then
echo found java executable in PATH
_java=java
elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
echo found java executable in JAVA_HOME
_java="$JAVA_HOME/bin/java"
else
echo "no java"
exit 1
fi
if [[ "$_java" ]]; then
version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
echo version "$version"
if [[ "$version" == *"1.8"* ]]; then
echo "version is 1.8"
else
echo "version is not 1.8"
echo "https://github.com/Sagacify/atlas/wiki/Continuous-integration#java-8"
exit 1
fi
fi
}
case "$1" in
install)
install
;;
run)
run
;;
check)
check
;;
*)
echo $"Usage: $0 {install|run|check}"
exit 1
esac