Debian Codegraph @

.ci/coverity.run

raw
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: BSD-3-Clause
3
4 set -eo pipefail
5
6 # Override project to the old project name becuase coverity didn't understand the rename from
7 # 01org/TPM2.0-TSS to tpm2-software/tpm2-tss
8 export PROJECT='01org/TPM2.0-TSS'
9 echo "PROJECT=$PROJECT"
10
11 if [ -z "$COVERITY_SCAN_TOKEN" ]; then
12 echo "coverity.run invoked without COVERITY_SCAN_TOKEN set...exiting!"
13 exit 1
14 fi
15
16 if [ -z "$COVERITY_SUBMISSION_EMAIL" ]; then
17 echo "coverity.run invoked without COVERITY_SUBMISSION_EMAIL set...exiting!"
18 exit 1
19 fi
20
21 # Sanity check, this should only be executing on the coverity_scan branch
22 if [[ "$REPO_BRANCH" != *coverity_scan ]]; then
23 echo "coverity.run invoked for non-coverity branch $REPO_BRANCH...exiting!"
24 exit 1
25 fi
26
27 if [[ "$CC" == clang* ]]; then
28 echo "Coverity scan branch detected, not running with clang...exiting!"
29 exit 1
30 fi
31
32 # branch is coverity_scan
33 echo "Running coverity build"
34
35 # ensure coverity_scan tool is available to the container
36 # We cannot package these in the docker image, as we would be distributing their software
37 # for folks not coupled to our COVERITY_SCAN_TOKEN.
38 if [ ! -f "$(pwd)/cov-analysis/bin/cov-build" ]; then
39 curl --data-urlencode "project=$PROJECT" \
40 --data-urlencode "token=$COVERITY_SCAN_TOKEN" \
41 "https://scan.coverity.com/download/linux64" -o coverity_tool.tgz
42
43 stat coverity_tool.tgz
44
45 curl --data-urlencode "project=$PROJECT" \
46 --data-urlencode "token=$COVERITY_SCAN_TOKEN" \
47 --data-urlencode "md5=1" \
48 "https://scan.coverity.com/download/linux64" -o coverity_tool.md5
49
50 stat coverity_tool.md5
51 cat coverity_tool.md5
52 md5sum coverity_tool.tgz
53 echo "$(cat coverity_tool.md5)" coverity_tool.tgz | md5sum -c
54
55 echo "unpacking cov-analysis"
56 tar -xf coverity_tool.tgz
57 mv cov-analysis-* cov-analysis
58 fi
59
60 export PATH=$PATH:$(pwd)/cov-analysis/bin
61
62 echo "Which cov-build: $(which cov-build)"
63
64 pushd "$DOCKER_BUILD_DIR"
65
66 source ".ci/docker-prelude.sh"
67
68 echo "Performing build with Coverity Scan"
69 rm -rf cov-int
70 ./bootstrap && ./configure --enable-debug && make clean
71 cov-build --dir $DOCKER_BUILD_DIR/cov-int make -j $(nproc)
72
73 echo "Collecting Coverity data for submission"
74 rm -fr README
75 AUTHOR="$(git log -1 $HEAD --pretty="%aN")"
76 AUTHOR_EMAIL="$(git log -1 $HEAD --pretty="%aE")"
77 VERSION="$(git rev-parse HEAD)"
78 echo "Name: $AUTHOR" >> README
79 echo "Email: $AUTHOR_EMAIL" >> README
80 echo "Project: $PROJECT" >> README
81 echo "Build-Version: $VERSION" >> README
82 echo "Description: $REPO_NAME $REPO_BRANCH" >> README
83 echo "Submitted-by: $PROJECT CI" >> README
84 echo "---README---"
85 cat README
86 echo "---EOF---"
87
88 rm -f scan.tgz
89 tar -czf scan.tgz README cov-int
90
91 rm -rf README cov-int
92
93 # upload the results
94 echo "Testing for scan results..."
95 scan_file=$(stat --printf='%n' scan.tgz)
96
97 echo "Submitting data to Coverity"
98 curl --form token="$COVERITY_SCAN_TOKEN" \
99 --form email="$COVERITY_SUBMISSION_EMAIL" \
100 --form project="$PROJECT" \
101 --form file=@"$scan_file" \
102 --form version="$VERSION" \
103 --form description="$REPO_NAME $REPO_BRANCH" \
104 "https://scan.coverity.com/builds?project=$PROJECT"
105
106 rm -rf scan.tgz
107
108 popd
109
110 exit 0