build.sh 8.7 KB

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