From 4b991a53a3d67b4ccb032b032b87475f35050832 Mon Sep 17 00:00:00 2001 From: PoAn Yang Date: Thu, 16 Nov 2023 11:48:56 +0800 Subject: [PATCH] feat: add -cover build to master/version-head branch Signed-off-by: PoAn Yang --- scripts/build | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/build b/scripts/build index 43688ebf4..7ffb5f31f 100755 --- a/scripts/build +++ b/scripts/build @@ -3,7 +3,15 @@ set -e source $(dirname $0)/version -if [ "$(git rev-parse --abbrev-ref HEAD)" = "master" ]; then +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/longhorn-instance-manager/..." fi @@ -11,9 +19,4 @@ fi cd $(dirname $0)/.. mkdir -p bin -go build -tags netgo -ldflags \ - "-X main.Version=$VERSION \ - -X main.GitCommit=$GITCOMMIT \ - -X main.BuildDate=$BUILDDATE \ - -linkmode external -extldflags -static" \ - "$COVER" "$COVERPKG" -o bin/longhorn-instance-manager +go build -o bin/longhorn-instance-manager -tags netgo -ldflags "$LINKFLAGS" $COVER $COVERPKG