refactor(ci): 将复杂构建逻辑提取到独立脚本中
site-dist-deploy / build-and-deploy (push) Failing after 3s

重构 CI 构建流程,将原有的复杂构建逻辑提取到独立的 ci-build.sh 脚本中
简化 docker.yml 工作流文件,提高可维护性和复用性
This commit is contained in:
2026-01-04 03:01:23 -08:00
parent 69c037bf51
commit ae9f9063a9
3 changed files with 947 additions and 66 deletions
+5 -66
View File
@@ -37,73 +37,12 @@ jobs:
git fetch --tags
fi
- name: Build dist in Node container
- name: Build dist with Unified Script
env:
VITE_APP_BASE_URL: "https://h.hifast.biz"
run: |
set -e
install_pkgs() {
PKGS="$*"
if command -v apt-get >/dev/null 2>&1; then
apt-get update -y
DEBIAN_FRONTEND=noninteractive apt-get install -y $PKGS
elif command -v yum >/dev/null 2>&1; then
yum install -y $PKGS
elif command -v dnf >/dev/null 2>&1; then
dnf install -y $PKGS
elif command -v apk >/dev/null 2>&1; then
apk add --no-cache $PKGS
elif command -v zypper >/dev/null 2>&1; then
zypper install -y $PKGS
else
echo "No known package manager found to install: $PKGS"; exit 1
fi
}
if ! command -v curl >/dev/null 2>&1; then install_pkgs curl ca-certificates; fi
if ! command -v tar >/dev/null 2>&1; then install_pkgs tar; fi
if ! command -v xz >/dev/null 2>&1 && ! command -v unxz >/dev/null 2>&1; then install_pkgs xz-utils || install_pkgs xz; fi
# 预装编译依赖,避免 nvm 源码安装失败
install_pkgs python3 make gcc g++ || true
if ! command -v node >/dev/null 2>&1; then
NODE_VER="v20.19.6"
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) NODE_ARCH="linux-x64" ;;
aarch64) NODE_ARCH="linux-arm64" ;;
arm64) NODE_ARCH="linux-arm64" ;;
*) echo "Unsupported arch: $ARCH"; exit 1 ;;
esac
# 检测 libc 类型,musl 用 musl 包
LIBC_TYPE="glibc"
if command -v ldd >/dev/null 2>&1; then
if ldd --version 2>&1 | grep -qi musl; then LIBC_TYPE="musl"; fi
fi
if [ "$LIBC_TYPE" = "musl" ] && [ "$NODE_ARCH" = "linux-x64" ]; then
NODE_TARBALL="node-${NODE_VER}-linux-x64-musl.tar.xz"
else
NODE_TARBALL="node-${NODE_VER}-${NODE_ARCH}.tar.xz"
fi
URL="https://nodejs.org/dist/${NODE_VER}/${NODE_TARBALL}"
curl -fsSL "$URL" -o "/tmp/${NODE_TARBALL}"
mkdir -p "$HOME/node"
tar -xJf "/tmp/${NODE_TARBALL}" -C "$HOME/node"
# 解析实际解压目录名
NODE_DIR="$(find "$HOME/node" -maxdepth 1 -type d -name "node-${NODE_VER}-*" | head -n1)"
export PATH="$NODE_DIR/bin:$PATH"
fi
if ! node -v >/dev/null 2>&1; then
export NVM_DIR="$HOME/.nvm"
if [ ! -d "$NVM_DIR" ]; then
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
fi
. "$NVM_DIR/nvm.sh"
nvm install 20
nvm use 20
fi
node -v
npm -v
npm ci
echo "VITE_APP_BASE_URL=${VITE_APP_BASE_URL}" > .env.pord
npm run build:prod
tar -C dist -czf site_dist.tgz .
chmod +x scripts/ci-build.sh
./scripts/ci-build.sh
- name: Prepare target directory
uses: appleboy/ssh-action@v1.0.3