]> git.ipfire.org Git - thirdparty/systemd.git/blame - tools/coverity.sh
docs: add note about URL where to find recent Ubuntu CI logs
[thirdparty/systemd.git] / tools / coverity.sh
CommitLineData
ff12a795 1#!/usr/bin/env bash
9ee03516 2# SPDX-License-Identifier: LGPL-2.1-or-later
99127d20 3
176086a2 4set -eux
3b8e9881 5
176086a2
FS
6COVERITY_SCAN_TOOL_BASE="/tmp/coverity-scan-analysis"
7COVERITY_SCAN_PROJECT_NAME="systemd/systemd"
3b8e9881 8
176086a2
FS
9function coverity_install_script {
10 local platform tool_url tool_archive
99127d20 11
176086a2
FS
12 platform=$(uname)
13 tool_url="https://scan.coverity.com/download/${platform}"
14 tool_archive="/tmp/cov-analysis-${platform}.tgz"
99127d20 15
176086a2
FS
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
99127d20 20
176086a2
FS
21 mkdir -p "$COVERITY_SCAN_TOOL_BASE"
22 pushd "$COVERITY_SCAN_TOOL_BASE"
23 tar xzf "$tool_archive"
24 popd
99127d20
25}
26
176086a2
FS
27function run_coverity {
28 local results_dir tool_dir results_archive sha response status_code
99127d20 29
176086a2
FS
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)
cc5549ca 34
176086a2
FS
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"
cc5549ca 38
176086a2 39 tar czf "$results_archive" "$results_dir"
99127d20 40
176086a2 41 set +x # this is supposed to hide COVERITY_SCAN_TOKEN
cc5549ca
ZJS
42 echo -e "\033[33;1mUploading Coverity Scan Analysis results...\033[0m"
43 response=$(curl \
176086a2
FS
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)
cc5549ca
ZJS
52 printf "\033[33;1mThe response is\033[0m\n%s\n" "$response"
53 status_code=$(echo "$response" | sed -n '$p')
cc5549ca 54 if [ "$status_code" != "200" ]; then
176086a2
FS
55 echo -e "\033[33;1mCoverity Scan upload failed: $(echo "$response" | sed '$d').\033[0m"
56 return 1
cc5549ca 57 fi
176086a2 58 set -x
99127d20
59}
60
176086a2
FS
61coverity_install_script
62run_coverity