You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

267 lines
9.5 KiB

#!/bin/bash
#set -x
set -e
codePath=~/ws/yxt_lmis_hen
pushPath=~/build/yxt_lmis_hen
pushGitUrl=ssh://www@122.9.140.63:3022/bot_yxt/yxt_lmis_hen.git
pushPath_2=~/build/yxt_lmis_report_hen
pushGitUrl_2=ssh://www@122.9.140.63:3022/bot_yxt/yxt_lmis_report_hen.git
gitUrlArr=(
"www@git.yvanui.com:yvan-private/yvan-framework.git"
"www@git.yvanui.com:jztd/wms-core.git"
"www@git.yvanui.com:jztd/yvan-ext.git"
"www@git.yvanui.com:jztd/wms8.git"
"www@git.yvanui.com:jztd/yvan-studio.git"
"www@git.yvanui.com:jztd/lmis-report-system.git"
)
branchArr=(
"master"
"branch-2022-3-30"
"master"
"master"
"master"
"hen_2022_04_18"
)
positionArr=(
"."
"lmis"
"yvan-ext"
"wms8"
"yvan-studio"
"lmis-report-system"
)
# 是否需要构建,-1:自动;0:不需要;1:需要
needBuild=(
"1"
"1"
"1"
"1"
"1"
"1"
)
echoPrefix="\033[36m+"
echoSuffix="\033[0m"
buildCode() {
# 构建 yvan-ext
if [ "${needBuild[3]}" != "0" ]; then
echo -e "$echoPrefix cd $codePath/yvan-ext $echoSuffix"
cd "$codePath/yvan-ext"
echo -e "$echoPrefix yarn $echoSuffix"
yarn
echo -e "$echoPrefix yarn link $echoSuffix"
yarn link
echo -e "$echoPrefix yarn build $echoSuffix"
yarn build
echo ""
else
echo "yvan-ext 文件未变化"
fi
# 构建 lmis/client
if [ "${needBuild[2]}" != "0" ]; then
echo -e "$echoPrefix cd lmis/client $echoSuffix"
cd "$codePath/lmis/client"
echo -e "$echoPrefix yarn $echoSuffix"
yarn
echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
yarn link yvan-ext
echo -e "$echoPrefix yarn build $echoSuffix"
yarn build
echo ""
else
echo "lmis 文件未变化"
fi
# 构建 lmis-report-system/client
if [ "${needBuild[6]}" != "0" ]; then
echo -e "$echoPrefix cd lmis-report-system/client $echoSuffix"
cd "$codePath/lmis-report-system/client"
echo -e "$echoPrefix yarn $echoSuffix"
yarn
echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
yarn link yvan-ext
echo -e "$echoPrefix yarn build $echoSuffix"
yarn build
echo ""
else
echo "lmis-report-system 文件未变化"
fi
# 构建 java
echo -e "$echoPrefix cd $codePath $echoSuffix"
cd $codePath
echo -e "$echoPrefix gradle build -x test $echoSuffix"
gradle build -x test
echo ""
}
deployPush() {
# 更新push git
pullCode $pushPath $pushGitUrl "master" "."
# 同步 lmis/ent/build/libs
echo -e "$echoPrefix rsync -av --delete --exclude '.git/' --exclude 'client/' --exclude 'dist/' --exclude '*-javadoc.jar' --exclude '*-sources.jar' $codePath/lmis/ent/build/libs/ $pushPath/ $echoSuffix"
rsync -av --delete --exclude '.git/' --exclude 'client/' --exclude 'dist/' --exclude '*-javadoc.jar' --exclude '*-sources.jar' "$codePath/lmis/ent/build/libs/" "$pushPath/"
echo ""
# 同步 lmis/client/tsconfig.json
echo -e "$echoPrefix rsync -av --delete --include 'tsconfig.json' --exclude '/*' $codePath/lmis/client/ $pushPath/client/ $echoSuffix"
rsync -av --delete --include 'tsconfig.json' --exclude '/*' "$codePath/lmis/client/" "$pushPath/client/"
echo ""
# 同步 lmis/client/node_modules
echo -e "$echoPrefix rsync -av --delete --exclude 'yvan-ext/' $codePath/lmis/client/node_modules/ $pushPath/client/node_modules/ $echoSuffix"
rsync -av --delete --exclude 'yvan-ext' "$codePath/lmis/client/node_modules/" "$pushPath/client/node_modules/"
echo ""
# 同步 lmis/client/public
echo -e "$echoPrefix rsync -av --delete $codePath/lmis/client/public/ $pushPath/client/public/ $echoSuffix"
rsync -av --delete "$codePath/lmis/client/public/" "$pushPath/client/public/"
echo ""
# 同步 yvan-ext
echo -e "$echoPrefix rsync -av --delete --include 'assets/' --include 'build/' --include 'dist/' --exclude '/*' $codePath/yvan-ext/ $pushPath/client/node_modules/yvan-ext/ $echoSuffix"
rsync -av --delete --include 'assets/' --include 'build/' --include 'dist/' --exclude '/*' "$codePath/yvan-ext/" "$pushPath/client/node_modules/yvan-ext/"
echo ""
# 同步 lmis/dist
echo -e "$echoPrefix rsync -av --delete $codePath/lmis/dist/ $pushPath/dist/ $echoSuffix"
rsync -av --delete "$codePath/lmis/dist/" "$pushPath/dist/"
echo ""
# 提交文件
echo -e "$echoPrefix cd $pushPath $echoSuffix"
cd "$pushPath"
if [ -n "$(git config user.name)" ]; then
echo -e "$echoPrefix git config user.name 'bot' $echoSuffix"
git config user.name 'bot'
echo -e "$echoPrefix git config user.email 'bot@git.com' $echoSuffix"
git config user.email 'bot@git.com'
fi
echo -e "$echoPrefix git add -A $echoSuffix"
git add -A
if [ -n "$(git status -s)" ]; then
echo -e "$echoPrefix git commit -am 自动deploy提交 $echoSuffix"
git commit -am "自动deploy提交"
echo -e "$echoPrefix git push origin master $echoSuffix"
git push origin master
else
echo "文件未变化不需要push"
fi
echo ""
#---------------------------------------------------------------------------------------------------------------------
# 更新push git
pullCode $pushPath_2 $pushGitUrl_2 "master" "."
# 同步 lmis-report-system/app/build/libs
echo -e "$echoPrefix rsync -av --delete --exclude '.git/' --exclude 'client/' --exclude 'dist/' --exclude '*-javadoc.jar' --exclude '*-sources.jar' $codePath/lmis-report-system/app/build/libs/ $pushPath_2/ $echoSuffix"
rsync -av --delete --exclude '.git/' --exclude 'client/' --exclude 'dist/' --exclude '*-javadoc.jar' --exclude '*-sources.jar' "$codePath/lmis-report-system/app/build/libs/" "$pushPath_2/"
echo ""
# 同步 lmis-report-system/client/tsconfig.json
echo -e "$echoPrefix rsync -av --delete --include 'tsconfig.json' --exclude '/*' $codePath/lmis-report-system/client/ $pushPath_2/client/ $echoSuffix"
rsync -av --delete --include 'tsconfig.json' --exclude '/*' "$codePath/lmis-report-system/client/" "$pushPath_2/client/"
echo ""
# 同步 lmis-report-system/client/node_modules
echo -e "$echoPrefix rsync -av --delete --exclude 'yvan-ext/' $codePath/lmis-report-system/client/node_modules/ $pushPath_2/client/node_modules/ $echoSuffix"
rsync -av --delete --exclude 'yvan-ext' "$codePath/lmis-report-system/client/node_modules/" "$pushPath_2/client/node_modules/"
echo ""
# 同步 lmis-report-system/client/public
echo -e "$echoPrefix rsync -av --delete $codePath/lmis-report-system/client/public/ $pushPath_2/client/public/ $echoSuffix"
rsync -av --delete "$codePath/lmis-report-system/client/public/" "$pushPath_2/client/public/"
echo ""
# 同步 yvan-ext
echo -e "$echoPrefix rsync -av --delete --include 'assets/' --include 'build/' --include 'dist/' --exclude '/*' $codePath/yvan-ext/ $pushPath_2/client/node_modules/yvan-ext/ $echoSuffix"
rsync -av --delete --include 'assets/' --include 'build/' --include 'dist/' --exclude '/*' "$codePath/yvan-ext/" "$pushPath_2/client/node_modules/yvan-ext/"
echo ""
# 同步 lmis-report-system/dist
echo -e "$echoPrefix rsync -av --delete $codePath/lmis-report-system/dist/ $pushPath_2/dist/ $echoSuffix"
rsync -av --delete "$codePath/lmis-report-system/dist/" "$pushPath_2/dist/"
echo ""
# 提交文件
echo -e "$echoPrefix cd $pushPath_2 $echoSuffix"
cd "$pushPath_2"
if [ -n "$(git config user.name)" ]; then
echo -e "$echoPrefix git config user.name 'bot' $echoSuffix"
git config user.name 'bot'
echo -e "$echoPrefix git config user.email 'bot@git.com' $echoSuffix"
git config user.email 'bot@git.com'
fi
echo -e "$echoPrefix git add -A $echoSuffix"
git add -A
if [ -n "$(git status -s)" ]; then
echo -e "$echoPrefix git commit -am 自动deploy提交 $echoSuffix"
git commit -am "自动deploy提交"
echo -e "$echoPrefix git push origin master $echoSuffix"
git push origin master
else
echo "文件未变化不需要push"
fi
echo ""
}
isChange="1" # 仓库是否发生变化,0未:变化;非0:变化
pullCode() {
# Usage: pullCode "codePath" "gitUrl" "branch" "position"
path=$1 # 代码保存路径
gitUrl=$2 # git仓库地址
branch=${3:-"master"} # git分支
position=${4:-""} # 使用“.”clone到当前文件夹
isChange="1"
# 创建文件夹
if [ ! -d "$path" ]; then
echo -e "$echoPrefix mkdir -p $path $echoSuffix"
mkdir -p $path
fi
# git clone
echo -e "$echoPrefix cd $path $echoSuffix"
cd $path
if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then
echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix"
git clone $gitUrl $position
isChange="2"
fi
# 进入文件夹,切换分支,git pull
if [ "$position" != "" ]; then
echo -e "$echoPrefix cd $position $echoSuffix"
cd $position
fi
echo -e "$echoPrefix git checkout $branch $echoSuffix"
git checkout $branch
echo -e "$echoPrefix git pull $echoSuffix"
if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == 1 ]; then
isChange="0"
fi
echo ""
}
for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
if [ "${needBuild[idx]}" == "-1" ]; then
needBuild[idx]=$isChange
fi
done
echo "###--代码更新完成--------------------------------------------------------------------------###"
echo ""
buildCode
echo "###--代码构建完成--------------------------------------------------------------------------###"
echo ""
deployPush
echo "###--文件推送完成--------------------------------------------------------------------------###"
echo ""
# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/yxt-hen/build.sh)