Blame ci/coverity.sh

Packit Service 20376f
#!/bin/bash
Packit Service 20376f
Packit Service 20376f
set -e
Packit Service 20376f
Packit Service 20376f
# Environment check
Packit Service 20376f
[ -z "$COVERITY_TOKEN" ] && echo "Need to set a coverity token" && exit 1
Packit Service 20376f
Packit Service 20376f
SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
Packit Service 20376f
BUILD_DIR=$(pwd)
Packit Service 20376f
Packit Service 20376f
case $(uname -m) in
Packit Service 20376f
	i?86)				BITS=32 ;;
Packit Service 20376f
	amd64|x86_64)	BITS=64 ;;
Packit Service 20376f
esac
Packit Service 20376f
SCAN_TOOL=https://scan.coverity.com/download/cxx/linux${BITS}
Packit Service 20376f
TOOL_BASE=$(pwd)/_coverity-scan
Packit Service 20376f
Packit Service 20376f
# Install coverity tools
Packit Service 20376f
if [ ! -d "$TOOL_BASE" ]; then
Packit Service 20376f
	echo "Downloading coverity..."
Packit Service 20376f
	mkdir -p "$TOOL_BASE"
Packit Service 20376f
	pushd "$TOOL_BASE"
Packit Service 20376f
	wget -O coverity_tool.tgz $SCAN_TOOL \
Packit Service 20376f
		--post-data "project=libgit2&token=$COVERITY_TOKEN"
Packit Service 20376f
	tar xzf coverity_tool.tgz
Packit Service 20376f
	popd
Packit Service 20376f
	TOOL_DIR=$(find "$TOOL_BASE" -type d -name 'cov-analysis*')
Packit Service 20376f
	ln -s "$TOOL_DIR" "$TOOL_BASE"/cov-analysis
Packit Service 20376f
fi
Packit Service 20376f
Packit Service 20376f
cp "${SOURCE_DIR}/script/user_nodefs.h" "$TOOL_BASE"/cov-analysis/config/user_nodefs.h
Packit Service 20376f
Packit Service 20376f
COV_BUILD="$TOOL_BASE/cov-analysis/bin/cov-build"
Packit Service 20376f
Packit Service 20376f
# Configure and build
Packit Service 20376f
cmake ${SOURCE_DIR}
Packit Service 20376f
Packit Service 20376f
COVERITY_UNSUPPORTED=1 \
Packit Service 20376f
	$COV_BUILD --dir cov-int \
Packit Service 20376f
	cmake --build .
Packit Service 20376f
Packit Service 20376f
# Upload results
Packit Service 20376f
tar czf libgit2.tgz cov-int
Packit Service 20376f
SHA=$(cd ${SOURCE_DIR} && git rev-parse --short HEAD)
Packit Service 20376f
Packit Service 20376f
HTML="$(curl \
Packit Service 20376f
	--silent \
Packit Service 20376f
	--write-out "\n%{http_code}" \
Packit Service 20376f
	--form token="$COVERITY_TOKEN" \
Packit Service 20376f
	--form email=libgit2@gmail.com \
Packit Service 20376f
	--form file=@libgit2.tgz \
Packit Service 20376f
	--form version="$SHA" \
Packit Service 20376f
	--form description="libgit2 build" \
Packit Service 20376f
	https://scan.coverity.com/builds?project=libgit2)"
Packit Service 20376f
# Body is everything up to the last line
Packit Service 20376f
BODY="$(echo "$HTML" | head -n-1)"
Packit Service 20376f
# Status code is the last line
Packit Service 20376f
STATUS_CODE="$(echo "$HTML" | tail -n1)"
Packit Service 20376f
Packit Service 20376f
echo "${BODY}"
Packit Service 20376f
Packit Service 20376f
if [ "${STATUS_CODE}" != "200" -a "${STATUS_CODE}" != "201" ]; then
Packit Service 20376f
	echo "Received error code ${STATUS_CODE} from Coverity"
Packit Service 20376f
	exit 1
Packit Service 20376f
fi