001sync_code.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. }
  73. target_pull() {
  74. pullCode $target_path ${target_git} ${target_branch} ${target_position}
  75. }
  76. sync_files() {
  77. echo -e "$echoPrefix 开始同步: $source_path $echoSuffix"
  78. rsync -azr --progress --delete \
  79. --exclude '.git/' \
  80. --exclude '.gradle/' \
  81. --exclude '.httpCache/' \
  82. --exclude '.idea/' \
  83. --exclude 'logs/' \
  84. --exclude 'build/' \
  85. --exclude 'out/' \
  86. --exclude 'libs/' \
  87. --exclude 'node_modules/' \
  88. --exclude 'yvan-framework/' \
  89. --exclude 'yvan-ui/' \
  90. --exclude 'yvan-ui-dist/' \
  91. --exclude 'build.gradle' \
  92. --exclude 'settings.gradle' \
  93. --exclude 'application*' \
  94. --exclude 'bootstrap*' \
  95. --exclude 'wms-print/' \
  96. --exclude 'generated/' \
  97. --exclude 'generated_tests/' \
  98. --exclude '*.bpmn' \
  99. --exclude 'wms-modules/yvan-studio/' \
  100. --exclude 'gradle.properties' \
  101. --exclude 'gradle-wrapper.properties' \
  102. --exclude 'Dockerfile*' \
  103. $source_path/ $target_path
  104. echo -e "$echoPrefix 同步完成 $echoSuffix"
  105. echo -e "$echoPrefix 开始同步 $source_path/yvan-framework/yvan-studio $echoSuffix"
  106. rsync -azr --progress --delete \
  107. --exclude '.git/' \
  108. --exclude '.gradle/' \
  109. --exclude '.httpCache/' \
  110. --exclude '.idea/' \
  111. --exclude 'logs/' \
  112. --exclude 'build/' \
  113. --exclude 'out/' \
  114. --exclude 'libs/' \
  115. --exclude 'node_modules/' \
  116. --exclude 'yvan-framework/' \
  117. --exclude 'yvan-ui/' \
  118. --exclude 'build.gradle' \
  119. --exclude 'settings.gradle' \
  120. --exclude 'application*' \
  121. --exclude 'bootstrap*' \
  122. --exclude 'generated/' \
  123. --exclude 'generated_tests/' \
  124. --exclude '*.bpmn' \
  125. --exclude 'gradle.properties' \
  126. --exclude 'gradle-wrapper.properties' \
  127. --exclude 'Dockerfile*' \
  128. $source_path/yvan-framework/yvan-studio $target_path/wms-modules
  129. echo -e "$echoPrefix 同步完成 $echoSuffix"
  130. echo -e "$echoPrefix 开始同步 lib $echoSuffix"
  131. rsync -azr --progress --include '/yvan-*' --include '/wms-core-*' --include '/wms-api-*' --exclude='*' $source_path/wms-modules/wms-system/build/libs/lib/ $target_path/libs
  132. echo -e "$echoPrefix 同步完成 $echoSuffix"
  133. }
  134. source_pull
  135. #source_build
  136. target_pull
  137. sync_files
  138. # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/dsl/001sync_code.sh)