Files
sbnews/release.sh

70 lines
2.0 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 一键发布测试:
# 1) admin 目录 npm run build
# 2) uniapp 目录 npm run build:h5
# 3) 提交 server 代码到 git 并推送
#
# 用法:
# bash release.sh # 自动用时间戳作为提交信息
# bash release.sh "fix: short link" # 自定义提交信息
# ./release.sh "msg" # 已 chmod +x 后
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
MESSAGE="${1:-release: $(date '+%Y-%m-%d %H:%M:%S')}"
# ANSI 颜色(支持 git bash / wsl / linux / macOS
if [ -t 1 ]; then
CYAN=$'\033[36m'
YELLOW=$'\033[33m'
GREEN=$'\033[32m'
GRAY=$'\033[90m'
RESET=$'\033[0m'
else
CYAN=""; YELLOW=""; GREEN=""; GRAY=""; RESET=""
fi
step() { echo; echo "${CYAN}==> $1${RESET}"; }
run() {
local cwd="$1"; shift
echo "${GRAY}[$cwd] $*${RESET}"
(cd "$cwd" && "$@")
}
# 1. 构建 admin
step "构建 admin (npm run build)"
run "$ROOT_DIR/admin" npm run build
# 2. 构建 uniapp H5
step "构建 uniapp H5 (npm run build:h5)"
run "$ROOT_DIR/uniapp" npm run build:h5
# 3. 提交 serverserver 是独立 git 仓库,使用其自身的 .git)
SERVER_DIR="$ROOT_DIR/server"
if [ ! -d "$SERVER_DIR/.git" ]; then
echo "${YELLOW}server/.git 不存在,跳过 git 步骤${RESET}"
else
step "提交 server 代码"
if [ -z "$(git -C "$SERVER_DIR" status --porcelain)" ]; then
echo "${YELLOW}server 仓库无变更,跳过 commit${RESET}"
else
git -C "$SERVER_DIR" add -A
git -C "$SERVER_DIR" commit -m "$MESSAGE"
fi
step "推送到远端"
BRANCH="$(git -C "$SERVER_DIR" rev-parse --abbrev-ref HEAD)"
if git -C "$SERVER_DIR" rev-parse --abbrev-ref --symbolic-full-name "@{u}" >/dev/null 2>&1; then
git -C "$SERVER_DIR" push
else
# 尚未设置上游:默认推到 origin/<当前分支>
git -C "$SERVER_DIR" push -u origin "$BRANCH"
fi
fi
echo
echo "${GREEN}✓ 发布完成${RESET}"