From 8d24327ac30cd71d07502aced5fac22d79c46ba8 Mon Sep 17 00:00:00 2001 From: lizw <1183409807@qq.com> Date: Thu, 3 Apr 2025 11:24:05 +0800 Subject: [PATCH] 002sync_code.sh --- dsl/002sync_code.sh | 233 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 dsl/002sync_code.sh diff --git a/dsl/002sync_code.sh b/dsl/002sync_code.sh new file mode 100644 index 0000000..f0fc7e2 --- /dev/null +++ b/dsl/002sync_code.sh @@ -0,0 +1,233 @@ +#!/bin/bash +#set -x +set -e + +source_path=/home/www/sync_code/sd_dsl/wms85std +source_git=( + "www@git.yvanui.com:jztd/wms85std.git" + "www@git.yvanui.com:lizhiwei/yvan-framework.git" + "www@git.yvanui.com:luoyifan/yvan-ui.git" +) +source_branch=( + "sd_dsl2" + "8.6" + "master" +) +source_position=( + "." + "yvan-framework" + "yvan-ui" +) + +target_path=/home/www/sync_code/sd_dsl/wms85std-sd +target_git=www@git.yvanui.com:lizhiwei/wms85std-sd.git +target_branch=main +target_position=. + +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + +# 强制覆盖本地的代码 git fetch --all && git reset --hard origin/master +pullCode() { + # Usage: pullCode "codePath" "gitUrl" "branch" "position" + path=$1 # 代码保存路径 + gitUrl=$2 # git仓库地址 + branch=${3:-"master"} # git分支 + position=${4:-""} # 使用“.”clone到当前文件夹 + # 创建文件夹 + if [ ! -d "$path" ]; then + echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix" + exit + 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 + 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 checkout . $echoSuffix" + git checkout . + echo -e "$echoPrefix git pull $echoSuffix" + if [ "`git pull`" == "Already up-to-date." ]; then + echo "" + fi + echo "" +} + +source_pull() { + for ((idx=0; idx<${#source_git[@]}; idx++)); do + pullCode $source_path ${source_git[idx]} ${source_branch[idx]} ${source_position[idx]} + done +} + +source_build() { + # 构建 java + echo -e "$echoPrefix cd $source_path $echoSuffix" + cd $source_path + echo -e "$echoPrefix gradle build -x test $echoSuffix" + gradle build -x test + echo "" + + # 构建 yvan-ui + echo -e "$echoPrefix cd $source_path/yvan-ui $echoSuffix" + cd $source_path/yvan-ui + echo -e "$echoPrefix yarn install $echoSuffix" + yarn install + echo -e "$echoPrefix yarn run build_only $echoSuffix" + yarn run build_only +} + +target_pull() { + pullCode $target_path ${target_git} ${target_branch} ${target_position} +} + +target_build() { + # 构建 java + echo -e "$echoPrefix cd $target_path $echoSuffix" + cd $target_path + echo -e "$echoPrefix gradle build -x test $echoSuffix" + gradle build -x test + echo "" +} + +sync_files() { + echo -e "$echoPrefix 开始同步: $source_path $echoSuffix" + rsync -azr --progress --delete \ + --exclude '.git/' \ + --exclude '.gradle/' \ + --exclude '.httpCache/' \ + --exclude '.idea/' \ + --exclude 'logs/' \ + --exclude 'build/' \ + --exclude 'out/' \ + --exclude 'libs/' \ + --exclude 'node_modules/' \ + --exclude 'yvan-framework/' \ + --exclude 'yvan-ui/' \ + --exclude 'yvan-ui-dist/' \ + --exclude 'build.gradle' \ + --exclude 'settings.gradle' \ + --exclude 'application*' \ + --exclude 'bootstrap*' \ + --exclude 'wms-print/' \ + --exclude 'generated/' \ + --exclude 'generated_tests/' \ + --exclude '*.bpmn' \ + --exclude 'wms-modules/yvan-studio/' \ + --exclude 'gradle.properties' \ + --exclude 'gradle-wrapper.properties' \ + --exclude 'Dockerfile*' \ + $source_path/ $target_path + echo -e "$echoPrefix 同步完成 $echoSuffix" + + echo -e "$echoPrefix 开始同步 $source_path/yvan-framework/yvan-studio $echoSuffix" + rsync -azr --progress --delete \ + --exclude '.git/' \ + --exclude '.gradle/' \ + --exclude '.httpCache/' \ + --exclude '.idea/' \ + --exclude 'logs/' \ + --exclude 'build/' \ + --exclude 'out/' \ + --exclude 'libs/' \ + --exclude 'node_modules/' \ + --exclude 'yvan-framework/' \ + --exclude 'src/main/java/' \ + --exclude 'src/main/resources/' \ + --exclude 'src/test/' \ + --exclude 'yvan-ui/' \ + --exclude 'build.gradle' \ + --exclude 'settings.gradle' \ + --exclude 'application*' \ + --exclude 'bootstrap*' \ + --exclude 'generated/' \ + --exclude 'generated_tests/' \ + --exclude '*.bpmn' \ + --exclude 'gradle.properties' \ + --exclude 'gradle-wrapper.properties' \ + --exclude 'Dockerfile*' \ + $source_path/yvan-framework/yvan-studio $target_path/wms-modules + echo -e "$echoPrefix 同步完成 $echoSuffix" + + echo -e "$echoPrefix 开始同步 lib $echoSuffix" + rsync -azr --progress \ + --include '/yvan-*' \ + --include '/wms-core-*' \ + --include '/wms-api-*' \ + --exclude='*' \ + $source_path/wms-modules/wms-system/build/libs/lib/ $target_path/libs + echo -e "$echoPrefix 同步完成 $echoSuffix" + + echo -e "$echoPrefix 开始同步 yvan-ui $echoSuffix" + rsync -azr --progress --delete $source_path/yvan-ui/dist/ $target_path/yvan-ui-dist/dist + echo -e "$echoPrefix 同步完成 $echoSuffix" + + echo -e "$echoPrefix 处理前端资源缓存 $echoSuffix" + version=$(date +_%Y_%m_%d_%H_%M_%S) + echo -e "$echoPrefix sed -i 's/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g' $target_path/wms-ui/index.html $echoSuffix" + sed -i "s/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g" $target_path/wms-ui/index.html + echo -e "$echoPrefix sed -i 's|/yvan-ui.mjs|/yvan-ui.mjs?v=$version|g' $target_path/wms-ui/index.html $echoSuffix" + sed -i "s|/yvan-ui.mjs|/yvan-ui.mjs?v=$version|g" $target_path/wms-ui/index.html + echo -e "$echoPrefix sed -i 's|/yvan-ui.mjs|/yvan-ui.mjs?v=$version|g' $target_path/yvan-ui-dist/dist/js/*.js $echoSuffix" + sed -i "s|/yvan-ui.mjs|/yvan-ui.mjs?v=$version|g" $target_path/yvan-ui-dist/dist/js/*.js + echo -e "$echoPrefix 处理前端资源缓存-完成 $echoSuffix" +} + +commit_target() { + echo -e "$echoPrefix cd $target_path $echoSuffix" + cd $target_path + echo -e "$echoPrefix git add --all . $echoSuffix" + git add --all . + echo -e "$echoPrefix git commit -m '代码同步' $echoSuffix" + git commit -m '代码同步' + echo -e "$echoPrefix git push origin $target_branch $echoSuffix" + git push origin $target_branch +} + +source_pull +target_pull +source_build +target_pull +sync_files +target_build +commit_target + +cmd=$1 +kls_source_path=/home/www/sync_code/sd_dsl/wms85std-sd-dsl + +echo -e "$echoPrefix cd $kls_source_path $echoSuffix" +cd $kls_source_path +git checkout -b main kls/main +echo -e "$echoPrefix git checkout -b main kls/main $echoSuffix" +git checkout main +echo -e "$echoPrefix git checkout main $echoSuffix" +git pull kls main:main -f +echo -e "$echoPrefix git pull kls main:main -f $echoSuffix" + +if [ "$cmd" == "test" ];then + echo -e "$echoPrefix git push dsl main:release/test -f $echoSuffix" + git push dsl main:release/test -f + echo "等待大参林能笑平台构建部署,约15分钟" +elif [ "$cmd" == "prod" ];then + echo -e "$echoPrefix git push dsl main:release/prod -f $echoSuffix" + git push dsl main:release/prod -f + echo "等待大参林能笑平台构建部署,约15分钟" +elif [ "$cmd" == "deploy" ];then + echo -e "$echoPrefix git push dsl main:develop -f $echoSuffix" + git push dsl main:develop -f + echo "等待大参林能笑平台构建部署,约15分钟" +else + echo "输入需要发版环境: test prod develop" +fi + +# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/dsl/002sync_code.sh)