blob: 22a42c2d5539137e42cdf831e629eb36fa681ef5 [file] [log] [blame]
Artem Naluzhnyy6ba95782019-06-10 16:39:54 +02001#!/bin/bash
2
3# Copyright 2019 Samsung Electronics Co., Ltd.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17set -Eeuxo pipefail
18PS4='+['$(readlink -f "$0")' ${FUNCNAME[0]%main}#$LINENO] '
19
20echo '---> maven-coverity.sh'
21
22#-----------------------------------------------------------------------------
Artem Naluzhnyy59bc0372019-07-01 10:52:48 +020023# Process parameters for JS/PHP/Ruby files analysis
24
25FS_CAPTURE_SEARCH_PARAMS=''
26if [ -n "${SEARCH_PATHS:=}" ]; then
27 for SEARCH_PATH in ${SEARCH_PATHS}; do
28 if [ -d "${SEARCH_PATH}" ]; then
29 FS_CAPTURE_SEARCH_PARAMS="${FS_CAPTURE_SEARCH_PARAMS} --fs-capture-search '${SEARCH_PATH}'"
30 else
31 echo "'${SEARCH_PATH}' from \$SEARCH_PATHS is not an existing directory." >&2
32 exit 1
33 fi
34 done
35fi
36
37for EXCLUDE_REGEX in ${SEARCH_EXCLUDE_REGEXS:=}; do
38 FS_CAPTURE_SEARCH_PARAMS="${FS_CAPTURE_SEARCH_PARAMS} --fs-capture-search-exclude-regex '${EXCLUDE_REGEX}'"
39done
40
41#-----------------------------------------------------------------------------
Artem Naluzhnyy373fc1c2019-06-11 17:14:07 +020042# Check if we are allowed to submit results to Coverity Scan service
43# and have not exceeded our upload quota limits
44# See also: https://scan.coverity.com/faq#frequency
45
46CURL_OUTPUT=$(
47 curl \
48 --verbose \
49 --silent \
50 --show-error \
51 --fail \
52 --form "project=${COVERITY_PROJECT_NAME}" \
53 --form "token=${COVERITY_TOKEN}" \
54 'https://scan.coverity.com/api/upload_permitted'
55)
56
57IS_COVERITY_UPLOAD_PERMITTED=$(
58 echo "${CURL_OUTPUT}" \
59 | jq '.upload_permitted'
60)
61if [ x"${IS_COVERITY_UPLOAD_PERMITTED}" != x'true' ]; then
62 echo "Upload quota reached. Next upload permitted at "$(echo "${CURL_OUTPUT}" | jq '.next_upload_permitted_at') >&2
63 exit 1
64fi
65
66#-----------------------------------------------------------------------------
Artem Naluzhnyy6ba95782019-06-10 16:39:54 +020067# Get Coverity Scan build tool
68
69curl \
70 --verbose \
71 --silent \
72 --show-error \
73 --fail \
74 --form "project=${COVERITY_PROJECT_NAME}" \
75 --form "token=${COVERITY_TOKEN}" \
76 --output 'coverity_tool.tgz' \
77 'https://scan.coverity.com/download/linux64'
78
Artem Naluzhnyy450f6c62019-06-11 17:19:40 +020079curl \
80 --verbose \
81 --silent \
82 --show-error \
83 --fail \
84 --form "project=${COVERITY_PROJECT_NAME}" \
85 --form "token=${COVERITY_TOKEN}" \
86 --form 'md5=1' \
87 --output 'coverity_tool.md5' \
88 'https://scan.coverity.com/download/linux64'
89
90echo -n ' coverity_tool.tgz' >> 'coverity_tool.md5'
91md5sum --check 'coverity_tool.md5'
92
Artem Naluzhnyy6ba95782019-06-10 16:39:54 +020093tar \
94 --extract \
95 --gunzip \
96 --file='coverity_tool.tgz'
97
98COVERITY_BUILD_TOOL_DIRECTORY=$(
99 head -1 <( \
100 tar \
101 --list \
102 --gunzip \
103 --file='coverity_tool.tgz'
104 )
105)
106COVERITY_BINARY_DIRECTORY="${COVERITY_BUILD_TOOL_DIRECTORY}bin"
107test -d "${COVERITY_BINARY_DIRECTORY}" \
108 || exit 1
109export PATH="${PATH}:${COVERITY_BINARY_DIRECTORY}"
110
111rm 'coverity_tool.tgz'
112
113#-----------------------------------------------------------------------------
114# Build
115
116export MAVEN_OPTS
117
Artem Naluzhnyy59bc0372019-07-01 10:52:48 +0200118eval cov-build \
Artem Naluzhnyy6ba95782019-06-10 16:39:54 +0200119 --dir 'cov-int' \
Artem Naluzhnyy59bc0372019-07-01 10:52:48 +0200120 ${FS_CAPTURE_SEARCH_PARAMS} \
Artem Naluzhnyy6ba95782019-06-10 16:39:54 +0200121 "${MVN}" clean install \
122 --errors \
123 --global-settings "${GLOBAL_SETTINGS_FILE}" \
124 --settings "${SETTINGS_FILE}" \
125 ${MAVEN_OPTIONS:=} \
126 ${MAVEN_PARAMS:=}
127
128cov-import-scm \
129 --dir 'cov-int' \
130 --scm 'git'
131
Artem Naluzhnyy097f7342019-06-27 14:14:14 +0200132cov-manage-emit \
133 --dir cov-int \
134 list \
135| grep \
136 --invert-match \
137 '^Translation unit:$' \
138| sed \
139 's!^[[:digit:]]\+ -> !!' \
140> 'coverity-scan-analysed-files.log'
141
Artem Naluzhnyy6ba95782019-06-10 16:39:54 +0200142#-----------------------------------------------------------------------------
143# Submit results to Coverity service
144
145tar \
146 --create \
147 --gzip \
148 --file='results.tgz' \
149 'cov-int'
150
151curl \
152 --verbose \
153 --silent \
154 --show-error \
155 --fail \
156 --form "project=${COVERITY_PROJECT_NAME}" \
157 --form "email=${COVERITY_USER_EMAIL}" \
158 --form "token=${COVERITY_TOKEN}" \
159 --form 'file=@results.tgz' \
160 --form "version=${GIT_COMMIT:0:7}" \
161 --form "description=${GIT_BRANCH}" \
162 'https://scan.coverity.com/builds'
163
164#-----------------------------------------------------------------------------
165
166exit 0