]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env bash | |
2 | # SPDX-License-Identifier: LGPL-2.1-or-later | |
3 | ||
4 | set -eux | |
5 | ||
6 | COVERITY_SCAN_TOOL_BASE="/tmp/coverity-scan-analysis" | |
7 | COVERITY_SCAN_PROJECT_NAME="systemd/systemd" | |
8 | ||
9 | function coverity_install_script { | |
10 | local platform tool_url tool_archive | |
11 | ||
12 | platform=$(uname) | |
13 | tool_url="https://scan.coverity.com/download/${platform}" | |
14 | tool_archive="/tmp/cov-analysis-${platform}.tgz" | |
15 | ||
16 | set +x # this is supposed to hide COVERITY_SCAN_TOKEN | |
17 | echo -e "\033[33;1mDownloading Coverity Scan Analysis Tool...\033[0m" | |
18 | wget -nv -O "$tool_archive" "$tool_url" --post-data "project=$COVERITY_SCAN_PROJECT_NAME&token=${COVERITY_SCAN_TOKEN:?}" | |
19 | set -x | |
20 | ||
21 | mkdir -p "$COVERITY_SCAN_TOOL_BASE" | |
22 | pushd "$COVERITY_SCAN_TOOL_BASE" | |
23 | tar xzf "$tool_archive" | |
24 | popd | |
25 | } | |
26 | ||
27 | function run_coverity { | |
28 | local results_dir tool_dir results_archive sha response status_code | |
29 | ||
30 | results_dir="cov-int" | |
31 | tool_dir=$(find "$COVERITY_SCAN_TOOL_BASE" -type d -name 'cov-analysis*') | |
32 | results_archive="analysis-results.tgz" | |
33 | sha=$(git rev-parse --short HEAD) | |
34 | ||
35 | meson -Dman=false build | |
36 | COVERITY_UNSUPPORTED=1 "$tool_dir/bin/cov-build" --dir "$results_dir" sh -c "ninja -C ./build -v" | |
37 | "$tool_dir/bin/cov-import-scm" --dir "$results_dir" --scm git --log "$results_dir/scm_log.txt" | |
38 | ||
39 | tar czf "$results_archive" "$results_dir" | |
40 | ||
41 | set +x # this is supposed to hide COVERITY_SCAN_TOKEN | |
42 | echo -e "\033[33;1mUploading Coverity Scan Analysis results...\033[0m" | |
43 | response=$(curl \ | |
44 | --silent --write-out "\n%{http_code}\n" \ | |
45 | --form project="$COVERITY_SCAN_PROJECT_NAME" \ | |
46 | --form token="${COVERITY_SCAN_TOKEN:?}" \ | |
47 | --form email="${COVERITY_SCAN_NOTIFICATION_EMAIL:?}" \ | |
48 | --form file="@$results_archive" \ | |
49 | --form version="$sha" \ | |
50 | --form description="Daily build" \ | |
51 | https://scan.coverity.com/builds) | |
52 | printf "\033[33;1mThe response is\033[0m\n%s\n" "$response" | |
53 | status_code=$(echo "$response" | sed -n '$p') | |
54 | if [ "$status_code" != "200" ]; then | |
55 | echo -e "\033[33;1mCoverity Scan upload failed: $(echo "$response" | sed '$d').\033[0m" | |
56 | return 1 | |
57 | fi | |
58 | set -x | |
59 | } | |
60 | ||
61 | coverity_install_script | |
62 | run_coverity |