nginx-proxy-manager/scripts/ci/test-backend
Jamie Curnow d8a3726f3a
Expose backend coverage in dev mode through web
Generate backend coverage in ci
2023-07-27 13:44:38 +10:00

71 lines
1.9 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e
set +x
IMAGE=jc21/gotools:latest
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
. "$DIR/../.common.sh"
BUILD_DATE=$(date '+%Y-%m-%d %T %Z')
NOW=$(date --rfc-3339=s)
cd $DIR/../..
if [ "$BUILD_COMMIT" = "" ]; then
BUILD_COMMIT=$(git log -n 1 --format=%h)
fi
if [ "$BUILD_VERSION" = "" ]; then
BUILD_VERSION=$(cat .version)
fi
echo -e "${BLUE} ${GREEN}test-backend: ${YELLOW}${1:-}${RESET}"
echo " BUILD_COMMIT: ${BUILD_COMMIT:-notset}"
echo " BUILD_DATE: $BUILD_DATE"
echo " BUILD_VERSION: $BUILD_VERSION"
echo " CGO_ENABLED: ${CGO_ENABLED:-not set}"
echo " GO111MODULE: ${GO111MODULE:-}"
echo " GOPRIVATE: ${GOPRIVATE:-}"
echo " GOPROXY: ${GOPROXY:-}"
echo " NOW: $NOW"
if [ "${1:-}" = "--inside-docker" ]; then
mkdir -p /workspace
echo -e "${BLUE} ${CYAN}govulncheck setup${RESET}"
cd /workspace
cp /app/backend/go.mod /app/backend/go.sum .
go mod download
echo -e "${BLUE} ${CYAN}govulncheck testing${RESET}"
govulncheck ./...
rm -rf /workspace
echo -e "${BLUE} ${CYAN}Testing backend code${RESET}"
cd /app/backend
[ -z "$(go tool fix -diff ./internal)" ]
go test -json -cover -coverprofile="$DIR/../../coverage.out" ./internal/... | tparse
go tool cover -html="$DIR/../../coverage.out" -o "$DIR/../../coverage.html"
rm -f "$DIR/../../coverage.out"
golangci-lint -v run ./...
else
# run this script from within docker
docker pull "${IMAGE}"
docker run --rm \
-e BUILD_COMMIT="${BUILD_COMMIT:-notset}" \
-e BUILD_DATE="$BUILD_DATE" \
-e BUILD_VERSION="$BUILD_VERSION" \
-e GOARCH="${2}" \
-e GOOS="${1}" \
-e GOPRIVATE="${GOPRIVATE:-}" \
-e GOPROXY="${GOPROXY:-}" \
-e NOW="$NOW" \
-e TZ="${TZ:-Australia/Brisbane}" \
-v "$(pwd):/app" \
-w '/app/backend' \
"${IMAGE}" \
/app/scripts/ci/test-backend --inside-docker
fi
echo -e "${BLUE} ${GREEN}test-backend ${YELLOW}${1:-} ${GREEN}completed${RESET}"
exit 0