Go框架demo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.7 KiB

3 years ago
  1. #!/bin/sh
  2. # build.sh
  3. # This script for build go projects.
  4. # @version 170227:1
  5. # @author zhangxuhong <zhangxuhong@xitu.io>
  6. #
  7. # [config]
  8. echo "-[config]-"
  9. # ----------------------------[manual config here]------------------------------
  10. # REPO_SRC=/data/repo/collection_set_api
  11. # BUILD_TARGET=collection_set_api
  12. # ------------------------------------------------------------------------------
  13. echo -e "\033[34mREPO_SRC set to: ${REPO_SRC}\033[0m"
  14. echo -e "\033[34mBUILD_TARGET set to: ${BUILD_TARGET}\033[0m"
  15. echo ""
  16. sleep 1
  17. # [set env]
  18. echo "-[set env]-"
  19. # $GOBIN
  20. export GOBIN="${REPO_SRC}/bin"
  21. echo -e "\033[34mGOBIN set to: ${GOBIN}\033[0m"
  22. # $GOPATH
  23. export GOPATH="${REPO_SRC}"
  24. echo -e "\033[34mGOPATH set to: ${GOPATH}\033[0m"
  25. echo ""
  26. sleep 1
  27. # [check old build target]
  28. echo "-[check old build target]-"
  29. if [ ! -d $GOBIN ]; then mkdir $GOBIN; fi
  30. if [ -f "${GOBIN}/${BUILD_TARGET}" ]; then
  31. echo -e "\033[43m[WARRING!] build target alerady exists, will remove it. \033[0m";
  32. echo "old build_target detail:"
  33. ls -alh "${GOBIN}/${BUILD_TARGET}";
  34. oldShaSum=`shasum "${GOBIN}/${BUILD_TARGET}" | awk -F' ' '{print $1}'`;
  35. echo "target sha: ${oldShaSum}";
  36. rm -rf "${GOBIN}/${BUILD_TARGET}";
  37. echo "old build target removed.";
  38. fi
  39. echo "done."
  40. echo ""
  41. sleep 1
  42. # [build]
  43. echo "-[build]-"
  44. echo "build start: "
  45. echo "go build -o ${GOBIN}/${BUILD_TARGET}"
  46. cd "${GOPATH}/src"
  47. go build -o "${GOBIN}/${BUILD_TARGET}"
  48. ls -alh "${GOBIN}/${BUILD_TARGET}"
  49. newShaSum=`shasum "${GOBIN}/${BUILD_TARGET}" | awk -F' ' '{print $1}'`;
  50. echo "target sha: ${newShaSum}";
  51. if [ "$oldShaSum" == "$newShaSum" ];then
  52. echo -e "\033[43m[WARRING!] old build target shasum is equals to new build target. \033[0m"
  53. fi
  54. echo "done."