001sync_code.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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=master
  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. fi
  57. echo ""
  58. }
  59. source_pull() {
  60. for ((idx=0; idx<${#source_git[@]}; idx++)); do
  61. pullCode $source_path ${source_git[idx]} ${source_branch[idx]} ${source_position[idx]}
  62. done
  63. }
  64. source_build() {
  65. # 构建 java
  66. echo -e "$echoPrefix cd $source_path $echoSuffix"
  67. cd $source_path
  68. chmod +x gradlew
  69. echo -e "$echoPrefix gradlew build -x test $echoSuffix"
  70. ./gradlew 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)