build.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. if [ -n "$(git config user.name)" ]; then
  123. echo -e "$echoPrefix git config user.name 'bot' $echoSuffix"
  124. git config user.name 'bot'
  125. echo -e "$echoPrefix git config user.name 'bot@git.com' $echoSuffix"
  126. git config user.name 'bot@git.com'
  127. fi
  128. echo -e "$echoPrefix git add -A $echoSuffix"
  129. git add -A
  130. if [ -n "$(git status -s)" ]; then
  131. echo -e "$echoPrefix git commit -am 自动deploy提交 $echoSuffix"
  132. git commit -am "自动deploy提交"
  133. echo -e "$echoPrefix git push origin master $echoSuffix"
  134. git push origin master
  135. else
  136. echo "文件未变化不需要push"
  137. fi
  138. echo ""
  139. }
  140. isChange="1" # 仓库是否发生变化,0未:变化;非0:变化
  141. pullCode() {
  142. # Usage: pullCode "codePath" "gitUrl" "branch" "position"
  143. path=$1 # 代码保存路径
  144. gitUrl=$2 # git仓库地址
  145. branch=${3:-"master"} # git分支
  146. position=${4:-""} # 使用“.”clone到当前文件夹
  147. isChange="1"
  148. # 创建文件夹
  149. if [ ! -d "$path" ]; then
  150. echo -e "$echoPrefix mkdir -p $path $echoSuffix"
  151. mkdir -p $path
  152. fi
  153. # git clone
  154. echo -e "$echoPrefix cd $path $echoSuffix"
  155. cd $path
  156. if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then
  157. echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix"
  158. git clone $gitUrl $position
  159. isChange="2"
  160. fi
  161. # 进入文件夹,切换分支,git pull
  162. if [ "$position" != "" ]; then
  163. echo -e "$echoPrefix cd $position $echoSuffix"
  164. cd $position
  165. fi
  166. echo -e "$echoPrefix git checkout $branch $echoSuffix"
  167. git checkout $branch
  168. echo -e "$echoPrefix git pull $echoSuffix"
  169. if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == 1 ]; then
  170. isChange="0"
  171. fi
  172. echo ""
  173. }
  174. for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
  175. pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
  176. if [ "${needBuild[idx]}" == "-1" ]; then
  177. needBuild[idx]=$isChange
  178. fi
  179. done
  180. echo "###--代码更新完成--------------------------------------------------------------------------###"
  181. echo ""
  182. buildCode
  183. echo "###--代码构建完成--------------------------------------------------------------------------###"
  184. echo ""
  185. deployPush
  186. echo "###--文件推送完成--------------------------------------------------------------------------###"
  187. echo ""