build.sh 9.9 KB

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