From 773517699726f0681791a42d3d2fe100e7ffb5a3 Mon Sep 17 00:00:00 2001 From: PoAn Yang Date: Thu, 16 Nov 2023 11:50:18 +0800 Subject: [PATCH] feat: add -cover build to master/version-head branch Signed-off-by: PoAn Yang --- scripts/build | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/build b/scripts/build index e97b2b5b..df231045 100755 --- a/scripts/build +++ b/scripts/build @@ -3,12 +3,20 @@ set -e source $(dirname $0)/version +LINKFLAGS="-X main.Version=$VERSION + -X main.GitCommit=$GITCOMMIT + -X main.BuildDate=$BUILDDATE + -linkmode external -extldflags -static" + +# add coverage flags if there is no tag and it's on master or a version branch like v1.6.x +COMMIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) +COMMIT_TAG=$(git tag --points-at HEAD | head -n 1) +if [[ "$COMMIT_TAG" == "" ]] && [[ "$COMMIT_BRANCH" == master || "$COMMIT_BRANCH" =~ ^v[0-9]+\.[0-9]+\.x$ ]]; then + COVER="-cover" + COVERPKG="-coverpkg=github.com/longhorn/backing-image-manager/..." +fi + cd $(dirname $0)/.. mkdir -p bin -go build -ldflags \ - "-X main.Version=$VERSION \ - -X main.GitCommit=$GITCOMMIT \ - -X main.BuildDate=$BUILDDATE \ - -linkmode external -extldflags -static" \ - -o bin/backing-image-manager +go build -o bin/backing-image-manager -ldflags "$LINKFLAGS" $COVER $COVERPKG