001sync_code.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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=develop
  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. source_pull
  77. source_build
  78. target_pull
  79. # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/dsl/001sync_code.sh)