build.sh 6.2 KB

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