build.sh 9.5 KB

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