github.com/m3db/m3@v1.5.0/scripts/go-build-ldflags.sh (about)

     1  #!/bin/sh
     2  
     3  MODE=$1
     4  
     5  if [ "$MODE" != "LDFLAG" ] && [ "$MODE" != "ECHO" ]; then
     6      echo "Usage: $0 <LDFLAG|ECHO>"
     7      exit 1
     8  fi
     9  
    10  export GIT_REVISION=$(git rev-parse --short HEAD)
    11  export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
    12  export GIT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo unknown)
    13  export BUILD_DATE=$(date '+%F-%T') # outputs something in this format 2017-08-21-18:58:45
    14  export BUILD_TS_UNIX=$(date '+%s') # second since epoch
    15  export BASE_PACKAGE=github.com/m3db/m3/src/x/instrument
    16  
    17  if [ "$MODE" = "LDFLAG" ]; then
    18    LD_FLAGS="-X ${BASE_PACKAGE}.Revision=${GIT_REVISION} \
    19    -X ${BASE_PACKAGE}.Branch=${GIT_BRANCH}               \
    20    -X ${BASE_PACKAGE}.Version=${GIT_VERSION}             \
    21    -X ${BASE_PACKAGE}.BuildDate=${BUILD_DATE}            \
    22    -X ${BASE_PACKAGE}.BuildTimeUnix=${BUILD_TS_UNIX}     \
    23    -X ${BASE_PACKAGE}.LogBuildInfoAtStartup=true"
    24  
    25    echo $LD_FLAGS
    26  fi
    27  
    28  if [ "$MODE" = "ECHO" ]; then
    29    cat <<EOF
    30  BASE_PACKAGE=${BASE_PACKAGE}
    31  GIT_REVISION=${GIT_REVISION}
    32  GIT_BRANCH=${GIT_BRANCH}
    33  GIT_VERSION=${GIT_VERSION}
    34  BUILD_DATE=${BUILD_DATE}
    35  BUILD_TS_UNIX=${BUILD_TS_UNIX}
    36  EOF
    37  fi