Skip to content

Commit

Permalink
feat: add -cover build to master/version-head branch
Browse files Browse the repository at this point in the history
Signed-off-by: PoAn Yang <poan.yang@suse.com>
  • Loading branch information
FrankYang0529 committed Nov 16, 2023
1 parent 463dd8e commit 79d20f4
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ set -e -x

source $(dirname $0)/version

cd $(dirname $0)/..

mkdir -p bin

[ "$(uname)" != "Darwin" ] && LINKFLAGS="-extldflags -static -s"
LINKFLAGS="-X github.com/longhorn/longhorn-manager/meta.Version=$VERSION
-X github.com/longhorn/longhorn-manager/meta.GitCommit=$GITCOMMIT
-X github.com/longhorn/longhorn-manager/meta.BuildDate=$BUILDDATE"
[ "$(uname)" != "Darwin" ] && OTHER_LINKFLAGS="-extldflags -static -s"

if [ "$(git rev-parse --abbrev-ref HEAD)" = "master" ]; then
# 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-manager/..."
fi

CGO_ENABLED=0 go build -ldflags \
"-X github.com/longhorn/longhorn-manager/meta.Version=$VERSION \
-X github.com/longhorn/longhorn-manager/meta.GitCommit=$GITCOMMIT \
-X github.com/longhorn/longhorn-manager/meta.BuildDate=$BUILDDATE \
$LINKFLAGS" "$COVER" "$COVERPKG" -o bin/longhorn-manager
cd $(dirname $0)/..

mkdir -p bin

CGO_ENABLED=0 go build -o bin/longhorn-manager -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" "$COVER" "$COVERPKG"

0 comments on commit 79d20f4

Please sign in to comment.