001sync_code.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 开始同步 $echoSuffix"
  78. rsync -azvr --progress \
  79. --exclude '*\.git\' \
  80. --exclude '*\.gradle\' \
  81. --exclude '*\.httpCache\' \
  82. --exclude '*\.idea\' \
  83. --exclude '*\logs\' \
  84. --exclude '*\build\' \
  85. --exclude '*\out\' \
  86. --exclude '*\node_modules\' \
  87. --exclude '*\yvan-framework\' \
  88. --exclude '*\yvan-ui\' \
  89. --exclude '*\build.gradle' \
  90. --exclude '*\settings.gradle' \
  91. --exclude '*\application*' \
  92. --exclude '*\bootstrap*' \
  93. --exclude '*\wms-print\' \
  94. --exclude '*\generated\' \
  95. --exclude '*\generated_tests\' \
  96. --exclude '*\*.bpmn' \
  97. --exclude '*\wms-modules\yvan-studio\*' \
  98. --exclude '*\gradle.properties' \
  99. --exclude '*\gradle-wrapper.properties' \
  100. --exclude '*\Dockerfile-wms-config-center' \
  101. --exclude '*\Dockerfile-wms-print' \
  102. --exclude '*\Dockerfile-wms-ui-config-center' \
  103. --exclude '*\Dockerfile-wms-ui-mobile' \
  104. --exclude '*\Dockerfile-wms-ui-pc' \
  105. --exclude '*\Dockerfile-wms-system' \
  106. $source_path/ /home/www/sync_code/sd_dsl/wms85std_copy
  107. echo -e "$echoPrefix 同步完成 $echoSuffix"
  108. }
  109. source_pull
  110. #source_build
  111. target_pull
  112. sync_files
  113. # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/dsl/001sync_code.sh)