feat(ci): 试点规范 2(test → LAN → 手动 ubuntu2)
All checks were successful
CI-CD-2 / test (push) Successful in 2s
CI-CD-2 / deploy-lan (push) Successful in 3s
CI-CD-2 / deploy-cloud (push) Has been skipped

This commit is contained in:
2026-11-10 14:46:47 +08:00
parent 6d590673ae
commit adb1328b75
8 changed files with 271 additions and 0 deletions

48
deploy/cloud.sh Executable file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# 发布到 ubuntu2(101.133.145.181:/var/www/shashann-homepage)
# 注意:不切 DNS、不碰 ShannonProd;公网验证用 health-cloud.sh 的 --resolve。
set -euo pipefail
cd "$(dirname "$0")/.."
TARGET="${1:-}"
case "$TARGET" in
ubuntu2)
SSH_HOST="root@101.133.145.181"
DEPLOY_DIR="/var/www/shashann-homepage"
;;
*)
echo "不支持的目标: $TARGET"
exit 1
;;
esac
# 手动发布按 tag 注入版本;普通提交按短 SHA
VERSION="${TARGET_REF:-$GITEA_SHA}"
if printf '%s' "$VERSION" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
VERSION="${VERSION#v}"
else
VERSION="${GITEA_SHA:0:8}"
fi
python3 - "$VERSION" <<'PY'
import re
import sys
version = sys.argv[1]
path = "index.html"
html = open(path, encoding="utf-8").read()
html = re.sub(r'(assets/css/style\.css)\?v=[^"\']*', r"\1?v=" + version, html)
html = re.sub(r'(assets/js/main\.js)\?v=[^"\']*', r"\1?v=" + version, html)
open(path, "w", encoding="utf-8").write(html)
PY
mkdir -p ~/.ssh && chmod 700 ~/.ssh
printf '%s\n' "${DEPLOY_SSH_KEY:?DEPLOY_SSH_KEY 未配置}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H 101.133.145.181 >> ~/.ssh/known_hosts 2>/dev/null || true
ssh "$SSH_HOST" "mkdir -p ${DEPLOY_DIR} && find ${DEPLOY_DIR} -mindepth 1 -maxdepth 1 -exec rm -rf {} +"
tar czf - index.html assets robots.txt sitemap.xml llms.txt \
| ssh "$SSH_HOST" "tar xzf - -C ${DEPLOY_DIR}"
echo "ubuntu2 已发布 ${VERSION}"