فهرست منبع

feat: 脚本优化

f-dev 3 روز پیش
والد
کامیت
3531b3bbdd
5فایلهای تغییر یافته به همراه54 افزوده شده و 76 حذف شده
  1. 1 25
      commit.sh
  2. 27 0
      common.sh
  3. 2 26
      pull.sh
  4. 1 25
      push.sh
  5. 23 0
      sync.sh

+ 1 - 25
commit.sh

@@ -1,10 +1,6 @@
 #!/bin/bash
 
-RED='\033[0;31m'
-GREEN='\033[0;32m'
-YELLOW='\033[0;33m'
-MAGENTA='\033[0;35m'
-RESET='\033[0m'
+source "$(dirname "$0")/common.sh"
 
 flag_add=false
 flag_commit=false
@@ -13,26 +9,6 @@ flag_mm=false
 flag_pm=false
 commit_message=""
 
-function execute_command() {
-    command="$1"
-    message="$2"
-    exit_on_failure=${3:-true}
-
-    echo "${GREEN}执行命令:${command}${RESET}"
-
-    eval "${command}"
-    status=$?
-
-    if [[ ${status} -ne 0 ]]; then
-        echo "${RED}错误:${message}${RESET}"
-        if [[ "$exit_on_failure" == "true" ]]; then
-            exit ${status}
-        else
-            return ${status}
-        fi
-    fi
-}
-
 function show_usage() {
     echo "用法:$0 [选项]"
     echo "选项:"

+ 27 - 0
common.sh

@@ -0,0 +1,27 @@
+#!/bin/bash
+
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+YELLOW='\033[0;33m'
+MAGENTA='\033[0;35m'
+RESET='\033[0m'
+
+function execute_command() {
+    command="$1"
+    message="$2"
+    exit_on_failure=${3:-true}
+
+    echo "${GREEN}执行命令:${command}${RESET}"
+
+    eval "${command}"
+    status=$?
+
+    if [[ ${status} -ne 0 ]]; then
+        echo "${RED}错误:${message}${RESET}"
+        if [[ "$exit_on_failure" == "true" ]]; then
+            exit ${status}
+        else
+            return ${status}
+        fi
+    fi
+}

+ 2 - 26
pull.sh

@@ -1,32 +1,8 @@
 #!/bin/bash
 
-product_code_list=("nomo")
-
-RED='\033[0;31m'
-GREEN='\033[0;32m'
-YELLOW='\033[0;33m'
-MAGENTA='\033[0;35m'
-RESET='\033[0m'
-
-function execute_command() {
-    command="$1"
-    message="$2"
-    exit_on_failure=${3:-true}
-
-    echo "${GREEN}执行命令:${command}${RESET}"
-
-    eval "${command}"
-    status=$?
+source "$(dirname "$0")/common.sh"
 
-    if [[ ${status} -ne 0 ]]; then
-        echo "${RED}错误:${message}${RESET}"
-        if [[ "$exit_on_failure" == "true" ]]; then
-            exit ${status}
-        else
-            return ${status}
-        fi
-    fi
-}
+product_code_list=("nomo")
 
 for product_code in "${product_code_list[@]}"; do
     echo "${MAGENTA}正在合并 ${product_code} 代码...${RESET}"

+ 1 - 25
push.sh

@@ -1,30 +1,6 @@
 #!/bin/bash
 
-RED='\033[0;31m'
-GREEN='\033[0;32m'
-YELLOW='\033[0;33m'
-MAGENTA='\033[0;35m'
-RESET='\033[0m'
-
-function execute_command() {
-    command="$1"
-    message="$2"
-    exit_on_failure=${3:-true}
-
-    echo "${GREEN}执行命令:${command}${RESET}"
-
-    eval "${command}"
-    status=$?
-
-    if [[ ${status} -ne 0 ]]; then
-        echo "${RED}错误:${message}${RESET}"
-        if [[ "$exit_on_failure" == "true" ]]; then
-            exit ${status}
-        else
-            return ${status}
-        fi
-    fi
-}
+source "$(dirname "$0")/common.sh"
 
 while getopts "p:e:" opt; do
     case $opt in

+ 23 - 0
sync.sh

@@ -0,0 +1,23 @@
+#!/bin/bash
+
+source "$(dirname "$0")/common.sh"
+
+product_code_list=("nomo")
+
+for product_code in "${product_code_list[@]}"; do
+    echo "${MAGENTA}正在同步 ${product_code} 相关分支...${RESET}"
+
+    execute_command "git checkout ${product_code}-prod" "切换至 ${product_code}-prod 分支失败"
+    execute_command "git pull" "拉取 ${product_code}-prod 分支失败"
+
+    execute_command "git checkout ${product_code}-test" "切换至 ${product_code}-test 分支失败"
+    execute_command "git pull" "拉取 ${product_code}-test 分支失败"
+
+    execute_command "git checkout main" "切换至 main 分支失败"
+    execute_command "git pull" "拉取 main 分支失败"
+
+    execute_command "git checkout nomo-dev" "切换至 nomo-dev 分支失败"
+    execute_command "git pull" "拉取 nomo-dev 分支失败"
+done
+
+execute_command "git checkout xiaom" "切换至 xiaom 分支失败"