build.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #!/bin/bash
  2. #set -x
  3. set -e
  4. codePath=~/ws/yxt_lmis
  5. pushPath=~/build/yxt_lmis
  6. pushGitUrl=ssh://www@122.9.140.63:3022/bot_yxt/yxt_lmis.git
  7. gitUrlArr=(
  8. "www@git.yvanui.com:yvan-private/yvan-framework.git"
  9. "www@git.yvanui.com:jztd/thinkingwms-ui.git"
  10. "www@git.yvanui.com:jztd/wms-core.git"
  11. "www@git.yvanui.com:jztd/yvan-ext.git"
  12. "www@git.yvanui.com:jztd/wms8.git"
  13. "www@git.yvanui.com:jztd/yvan-studio.git"
  14. "www@git.yvanui.com:jztd/lmis-report-system.git"
  15. )
  16. branchArr=(
  17. "master"
  18. "master"
  19. "yxt_20211025"
  20. "master"
  21. "master"
  22. "master"
  23. "master"
  24. )
  25. positionArr=(
  26. "."
  27. "thinkingwms-ui"
  28. "lmis"
  29. "yvan-ext"
  30. "wms8"
  31. "yvan-studio"
  32. "lmis-report-system"
  33. )
  34. # 是否需要构建,-1:自动;0:不需要;1:需要
  35. needBuild=(
  36. "-1"
  37. "-1"
  38. "-1"
  39. "-1"
  40. "-1"
  41. "-1"
  42. "-1"
  43. )
  44. echoPrefix="\033[36m+"
  45. echoSuffix="\033[0m"
  46. buildCode() {
  47. # 构建 yvan-ext
  48. if [ "${needBuild[3]}" != "0" ]; then
  49. echo -e "$echoPrefix cd $codePath/yvan-ext $echoSuffix"
  50. cd "$codePath/yvan-ext"
  51. echo -e "$echoPrefix yarn $echoSuffix"
  52. yarn
  53. echo -e "$echoPrefix yarn link $echoSuffix"
  54. yarn link
  55. echo -e "$echoPrefix yarn build $echoSuffix"
  56. yarn build
  57. echo ""
  58. else
  59. echo "yvan-ext 文件未变化"
  60. fi
  61. # 构建 thinkingwms-ui/client
  62. if [ "${needBuild[1]}" != "0" ]; then
  63. echo -e "$echoPrefix cd $codePath/thinkingwms-ui/client $echoSuffix"
  64. cd "$codePath/thinkingwms-ui/client"
  65. echo -e "$echoPrefix yarn $echoSuffix"
  66. yarn
  67. echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
  68. yarn link yvan-ext
  69. echo -e "$echoPrefix yarn build $echoSuffix"
  70. yarn build
  71. echo ""
  72. else
  73. echo "thinkingwms-ui 文件未变化"
  74. fi
  75. # 构建 lmis/client
  76. if [ "${needBuild[2]}" != "0" ]; then
  77. echo -e "$echoPrefix cd lmis/client $echoSuffix"
  78. cd "$codePath/lmis/client"
  79. echo -e "$echoPrefix yarn $echoSuffix"
  80. yarn
  81. echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
  82. yarn link yvan-ext
  83. echo -e "$echoPrefix yarn build $echoSuffix"
  84. yarn build
  85. echo ""
  86. else
  87. echo "lmis 文件未变化"
  88. fi
  89. # 构建 lmis-report-system/client
  90. if [ "${needBuild[2]}" != "0" ]; then
  91. echo -e "$echoPrefix cd lmis-report-system/client $echoSuffix"
  92. cd "$codePath/lmis-report-system/client"
  93. echo -e "$echoPrefix yarn $echoSuffix"
  94. yarn
  95. echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
  96. yarn link yvan-ext
  97. echo -e "$echoPrefix yarn build $echoSuffix"
  98. yarn build
  99. echo ""
  100. else
  101. echo "lmis-report-system 文件未变化"
  102. fi
  103. # 构建 java
  104. echo -e "$echoPrefix cd $codePath $echoSuffix"
  105. cd $codePath
  106. echo -e "$echoPrefix gradle build -x test $echoSuffix"
  107. gradle build -x test
  108. echo ""
  109. }
  110. deployPush() {
  111. # 更新push git
  112. pullCode $pushPath $pushGitUrl "master" "."
  113. # 同步 lmis/ent/build/libs
  114. echo -e "$echoPrefix rsync -av --delete --exclude '.git/' --exclude 'client/' --exclude 'dist/' --exclude '*-javadoc.jar' --exclude '*-sources.jar' $codePath/lmis/ent/build/libs/ $pushPath/ $echoSuffix"
  115. rsync -av --delete --exclude '.git/' --exclude 'client/' --exclude 'dist/' --exclude '*-javadoc.jar' --exclude '*-sources.jar' "$codePath/lmis/ent/build/libs/" "$pushPath/"
  116. echo ""
  117. # 同步 lmis/client/tsconfig.json
  118. echo -e "$echoPrefix rsync -av --delete --include 'tsconfig.json' --exclude '/*' $codePath/lmis/client/ $pushPath/client/ $echoSuffix"
  119. rsync -av --delete --include 'tsconfig.json' --exclude '/*' "$codePath/lmis/client/" "$pushPath/client/"
  120. echo ""
  121. # 同步 lmis/client/node_modules
  122. echo -e "$echoPrefix rsync -av --delete --exclude 'yvan-ext/' $codePath/lmis/client/node_modules/ $pushPath/client/node_modules/ $echoSuffix"
  123. rsync -av --delete --exclude 'yvan-ext' "$codePath/lmis/client/node_modules/" "$pushPath/client/node_modules/"
  124. echo ""
  125. # 同步 lmis/client/public
  126. echo -e "$echoPrefix rsync -av --delete $codePath/lmis/client/public/ $pushPath/client/public/ $echoSuffix"
  127. rsync -av --delete "$codePath/lmis/client/public/" "$pushPath/client/public/"
  128. echo ""
  129. # 同步 yvan-ext
  130. echo -e "$echoPrefix rsync -av --delete --include 'assets/' --include 'build/' --include 'dist/' --exclude '/*' $codePath/yvan-ext/ $pushPath/client/node_modules/yvan-ext/ $echoSuffix"
  131. rsync -av --delete --include 'assets/' --include 'build/' --include 'dist/' --exclude '/*' "$codePath/yvan-ext/" "$pushPath/client/node_modules/yvan-ext/"
  132. echo ""
  133. # 同步 lmis/dist
  134. echo -e "$echoPrefix rsync -av --delete $codePath/lmis/dist/ $pushPath/dist/ $echoSuffix"
  135. rsync -av --delete "$codePath/lmis/dist/" "$pushPath/dist/"
  136. echo ""
  137. # 提交文件
  138. echo -e "$echoPrefix cd $pushPath $echoSuffix"
  139. cd "$pushPath"
  140. if [ -n "$(git config user.name)" ]; then
  141. echo -e "$echoPrefix git config user.name 'bot' $echoSuffix"
  142. git config user.name 'bot'
  143. echo -e "$echoPrefix git config user.email 'bot@git.com' $echoSuffix"
  144. git config user.email 'bot@git.com'
  145. fi
  146. echo -e "$echoPrefix git add -A $echoSuffix"
  147. git add -A
  148. if [ -n "$(git status -s)" ]; then
  149. echo -e "$echoPrefix git commit -am 自动deploy提交 $echoSuffix"
  150. git commit -am "自动deploy提交"
  151. echo -e "$echoPrefix git push origin master $echoSuffix"
  152. git push origin master
  153. else
  154. echo "文件未变化不需要push"
  155. fi
  156. echo ""
  157. }
  158. isChange="1" # 仓库是否发生变化,0未:变化;非0:变化
  159. pullCode() {
  160. # Usage: pullCode "codePath" "gitUrl" "branch" "position"
  161. path=$1 # 代码保存路径
  162. gitUrl=$2 # git仓库地址
  163. branch=${3:-"master"} # git分支
  164. position=${4:-""} # 使用“.”clone到当前文件夹
  165. isChange="1"
  166. # 创建文件夹
  167. if [ ! -d "$path" ]; then
  168. echo -e "$echoPrefix mkdir -p $path $echoSuffix"
  169. mkdir -p $path
  170. fi
  171. # git clone
  172. echo -e "$echoPrefix cd $path $echoSuffix"
  173. cd $path
  174. if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then
  175. echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix"
  176. git clone $gitUrl $position
  177. isChange="2"
  178. fi
  179. # 进入文件夹,切换分支,git pull
  180. if [ "$position" != "" ]; then
  181. echo -e "$echoPrefix cd $position $echoSuffix"
  182. cd $position
  183. fi
  184. echo -e "$echoPrefix git checkout $branch $echoSuffix"
  185. git checkout $branch
  186. echo -e "$echoPrefix git pull $echoSuffix"
  187. if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == 1 ]; then
  188. isChange="0"
  189. fi
  190. echo ""
  191. }
  192. for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
  193. pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
  194. if [ "${needBuild[idx]}" == "-1" ]; then
  195. needBuild[idx]=$isChange
  196. fi
  197. done
  198. echo "###--代码更新完成--------------------------------------------------------------------------###"
  199. echo ""
  200. buildCode
  201. echo "###--代码构建完成--------------------------------------------------------------------------###"
  202. echo ""
  203. deployPush
  204. echo "###--文件推送完成--------------------------------------------------------------------------###"
  205. echo ""