gitee.com/quant1x/engine@v1.8.4/publish-compile.sh (about)

     1  #!/bin/sh
     2  # 获取当前路径, 用于返回
     3  #p0=`pwd`
     4  # 获取脚本所在路径, 防止后续操作在非项目路径
     5  p2=$(cd $(dirname $0);pwd)
     6  
     7  #COLOR_NORMAL="\033[0m"
     8  #COLOR_GREEN="\033[1;32m"
     9  #COLOR_YELLOW="\033[1;33m"
    10  #COLOR_RED="\033[1;33m"
    11  #COLOR_GREY="\033[1;30m"
    12  #echo "${COLOR_GREEN} 绿色 ${COLOR_NORMAL}"
    13  #echo "${COLOR_RED} 红色 ${COLOR_NORMAL}"
    14  
    15  #golang
    16  echo "----------------< go env >----------------"
    17  GOVERSION=$(go env GOVERSION)
    18  GOOS=$(go env GOOS)
    19  GOARCH=$(go env GOARCH)
    20  echo "   GOOS: ${GOOS}"
    21  echo " GOARCH: ${GOARCH}"
    22  echo "version: ${GOVERSION:2}"
    23  
    24  export GO111MODULE=auto
    25  export GOPRIVATE=gitee.com
    26  export GOPROXY=https://goproxy.cn,direct
    27  
    28  echo "----------------< project >----------------"
    29  module=$(awk 'NR==1 {print}' go.mod)
    30  module=`echo $module | awk '{split($0,a," ");print a[2]}'`
    31  echo " go mod: ${module}"
    32  tag=$(git describe --tags `git rev-list --tags --max-count=1`)
    33  version=${tag:1}
    34  echo "version: ${version}"
    35  last_commit=`git rev-parse HEAD`
    36  author=`git log ${tag} --pretty=format:"%an"|sed -n 1p`
    37  echo " author: ${author}"
    38  
    39  function compile() {
    40      echo "----------------< compile >----------------"
    41      BIN=$p2/bin
    42      app=$1
    43      EXT=$2
    44      echo "   GOOS: ${GOOS}"
    45      echo " GOARCH: ${GOARCH}"
    46      echo "正在编译应用:${app} => ${BIN}/${app}${EXT}..."
    47      env GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-s -w -X 'main.MinVersion=${version}'" -o ${BIN}/${app}${EXT} ${module}
    48      echo "正在编译应用:${app} => ${BIN}/${app}${EXT}...OK"
    49  }