diff --git a/scripts/build b/scripts/build index 17402f61eb..24849b4396 100755 --- a/scripts/build +++ b/scripts/build @@ -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"