002sync_code.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/bin/bash
  2. #set -x
  3. set -e
  4. source_path=/home/www/sync_code/sd_dsl/wms85std
  5. source_git=(
  6. "www@git.yvanui.com:jztd/wms85std.git"
  7. "www@git.yvanui.com:lizhiwei/yvan-framework.git"
  8. "www@git.yvanui.com:luoyifan/yvan-ui.git"
  9. )
  10. source_branch=(
  11. "sd_dsl2"
  12. "8.6"
  13. "master"
  14. )
  15. source_position=(
  16. "."
  17. "yvan-framework"
  18. "yvan-ui"
  19. )
  20. target_path=/home/www/sync_code/sd_dsl/wms85std-sd
  21. target_git=www@git.yvanui.com:lizhiwei/wms85std-sd.git
  22. target_branch=main
  23. target_position=.
  24. echoPrefix="\033[36m+"
  25. echoSuffix="\033[0m"
  26. # 强制覆盖本地的代码 git fetch --all && git reset --hard origin/master
  27. pullCode() {
  28. # Usage: pullCode "codePath" "gitUrl" "branch" "position"
  29. path=$1 # 代码保存路径
  30. gitUrl=$2 # git仓库地址
  31. branch=${3:-"master"} # git分支
  32. position=${4:-""} # 使用“.”clone到当前文件夹
  33. # 创建文件夹
  34. if [ ! -d "$path" ]; then
  35. echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix"
  36. exit
  37. fi
  38. # git clone
  39. echo -e "$echoPrefix cd $path $echoSuffix"
  40. cd $path
  41. if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then
  42. echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix"
  43. git clone $gitUrl $position
  44. fi
  45. # 进入文件夹,切换分支,git pull
  46. if [ "$position" != "" ]; then
  47. echo -e "$echoPrefix cd $position $echoSuffix"
  48. cd $position
  49. fi
  50. echo -e "$echoPrefix git checkout $branch $echoSuffix"
  51. git checkout $branch
  52. echo -e "$echoPrefix git checkout . $echoSuffix"
  53. git checkout .
  54. echo -e "$echoPrefix git pull $echoSuffix"
  55. if [ "`git pull`" == "Already up-to-date." ]; then
  56. echo ""
  57. fi
  58. echo ""
  59. }
  60. source_pull() {
  61. for ((idx=0; idx<${#source_git[@]}; idx++)); do
  62. pullCode $source_path ${source_git[idx]} ${source_branch[idx]} ${source_position[idx]}
  63. done
  64. }
  65. source_build() {
  66. # 构建 java
  67. echo -e "$echoPrefix cd $source_path $echoSuffix"
  68. cd $source_path
  69. echo -e "$echoPrefix gradle build -x test $echoSuffix"
  70. gradle build -x test
  71. echo ""
  72. # 构建 yvan-ui
  73. echo -e "$echoPrefix cd $source_path/yvan-ui $echoSuffix"
  74. cd $source_path/yvan-ui
  75. echo -e "$echoPrefix yarn install $echoSuffix"
  76. yarn install
  77. echo -e "$echoPrefix yarn run build_only $echoSuffix"
  78. yarn run build_only
  79. }
  80. target_pull() {
  81. pullCode $target_path ${target_git} ${target_branch} ${target_position}
  82. }
  83. target_build() {
  84. # 构建 java
  85. echo -e "$echoPrefix cd $target_path $echoSuffix"
  86. cd $target_path
  87. echo -e "$echoPrefix gradle build -x test $echoSuffix"
  88. gradle build -x test
  89. echo ""
  90. }
  91. sync_files() {
  92. echo -e "$echoPrefix 开始同步: $source_path $echoSuffix"
  93. rsync -azr --progress --delete \
  94. --exclude '.git/' \
  95. --exclude '.gradle/' \
  96. --exclude '.httpCache/' \
  97. --exclude '.idea/' \
  98. --exclude 'logs/' \
  99. --exclude 'build/' \
  100. --exclude 'out/' \
  101. --exclude 'libs/' \
  102. --exclude 'node_modules/' \
  103. --exclude 'yvan-framework/' \
  104. --exclude 'yvan-ui/' \
  105. --exclude 'yvan-ui-dist/' \
  106. --exclude 'build.gradle' \
  107. --exclude 'settings.gradle' \
  108. --exclude 'application*' \
  109. --exclude 'bootstrap*' \
  110. --exclude 'wms-print/' \
  111. --exclude 'generated/' \
  112. --exclude 'generated_tests/' \
  113. --exclude '*.bpmn' \
  114. --exclude 'wms-modules/yvan-studio/' \
  115. --exclude 'gradle.properties' \
  116. --exclude 'gradle-wrapper.properties' \
  117. --exclude 'Dockerfile*' \
  118. $source_path/ $target_path
  119. echo -e "$echoPrefix 同步完成 $echoSuffix"
  120. echo -e "$echoPrefix 开始同步 $source_path/yvan-framework/yvan-studio $echoSuffix"
  121. rsync -azr --progress --delete \
  122. --exclude '.git/' \
  123. --exclude '.gradle/' \
  124. --exclude '.httpCache/' \
  125. --exclude '.idea/' \
  126. --exclude 'logs/' \
  127. --exclude 'build/' \
  128. --exclude 'out/' \
  129. --exclude 'libs/' \
  130. --exclude 'node_modules/' \
  131. --exclude 'yvan-framework/' \
  132. --exclude 'src/main/java/' \
  133. --exclude 'src/main/resources/' \
  134. --exclude 'src/test/' \
  135. --exclude 'yvan-ui/' \
  136. --exclude 'build.gradle' \
  137. --exclude 'settings.gradle' \
  138. --exclude 'application*' \
  139. --exclude 'bootstrap*' \
  140. --exclude 'generated/' \
  141. --exclude 'generated_tests/' \
  142. --exclude '*.bpmn' \
  143. --exclude 'gradle.properties' \
  144. --exclude 'gradle-wrapper.properties' \
  145. --exclude 'Dockerfile*' \
  146. $source_path/yvan-framework/yvan-studio $target_path/wms-modules
  147. echo -e "$echoPrefix 同步完成 $echoSuffix"
  148. echo -e "$echoPrefix 开始同步 lib $echoSuffix"
  149. rsync -azr --progress \
  150. --include '/yvan-*' \
  151. --include '/wms-core-*' \
  152. --include '/wms-api-*' \
  153. --exclude='*' \
  154. $source_path/wms-modules/wms-system/build/libs/lib/ $target_path/libs
  155. echo -e "$echoPrefix 同步完成 $echoSuffix"
  156. echo -e "$echoPrefix 开始同步 yvan-ui $echoSuffix"
  157. rsync -azr --progress --delete $source_path/yvan-ui/dist/ $target_path/yvan-ui-dist/dist
  158. echo -e "$echoPrefix 同步完成 $echoSuffix"
  159. echo -e "$echoPrefix 处理前端资源缓存 $echoSuffix"
  160. version=$(date +_%Y_%m_%d_%H_%M_%S)
  161. echo -e "$echoPrefix sed -i 's/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g' $target_path/wms-ui/index.html $echoSuffix"
  162. sed -i "s/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g" $target_path/wms-ui/index.html
  163. echo -e "$echoPrefix sed -i 's|/yvan-ui.mjs|/yvan-ui.mjs?v=$version|g' $target_path/wms-ui/index.html $echoSuffix"
  164. sed -i "s|/yvan-ui.mjs|/yvan-ui.mjs?v=$version|g" $target_path/wms-ui/index.html
  165. echo -e "$echoPrefix sed -i 's|/yvan-ui.mjs|/yvan-ui.mjs?v=$version|g' $target_path/yvan-ui-dist/dist/js/*.js $echoSuffix"
  166. sed -i "s|/yvan-ui.mjs|/yvan-ui.mjs?v=$version|g" $target_path/yvan-ui-dist/dist/js/*.js
  167. echo -e "$echoPrefix 处理前端资源缓存-完成 $echoSuffix"
  168. }
  169. commit_target() {
  170. echo -e "$echoPrefix cd $target_path $echoSuffix"
  171. cd $target_path
  172. echo -e "$echoPrefix git add --all . $echoSuffix"
  173. git add --all .
  174. echo -e "$echoPrefix git commit -m '代码同步' $echoSuffix"
  175. git commit -m '代码同步'
  176. echo -e "$echoPrefix git push origin $target_branch $echoSuffix"
  177. git push origin $target_branch
  178. }
  179. #source_pull
  180. #target_pull
  181. #source_build
  182. #target_pull
  183. #sync_files
  184. #target_build
  185. #commit_target
  186. echo "已废弃!!!"
  187. # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/dsl/002sync_code.sh)