Files
blog/infra/deploy/build.sh
T
wait4xandGLM-5.3 f8add5ad15 feat(deploy): 裸 clone 构建改造与 en/archives 补页(T1/T4)
- build.sh:构建源改 ~/docker_apps/blog/build-repo(fetch+reset 硬跟
  origin/main,匿名 fetch)——线上=远端 main 确定性闭环,Sveltia 保存
  即自动上线生效;stamp 记录构建 commit;node_modules 留仓内做增量
  (loader 逻辑变更时须清 node_modules/.astro——EXIF 教训已注)
- en/archives/index.astro 补缺(此前 404):PostList locale 复用 +
  译题映射;三级目录 import 深度坑再犯一次(已修)

验证: bash infra/deploy/build.sh → staging 29 html @0e792a7(裸 clone
      实测);build 本地 28+1 页;E2E 30/30 PASS

Spec: 2026-10-25_add-blog-5c

Co-authored-by: GLM-5.3
2026-10-25 19:23:40 +08:00

34 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# 构建管线(Phase 5c 裸 clone 改造):构建源 = origin/main 硬跟,非本地工作树。
#
# 为什么:此前直接构建 ~/Code/Github/my-blog 工作树——分支/未提交状态会
# 意外上线(Sveltia 冒烟期实测发生过);且 Sveltia 的 main 提交无法自动
# 发布。改为独立构建仓 fetch+reset 硬跟 main:线上=远端 main,确定性闭环。
# blog 仓已公开,匿名 fetch 无需凭据。
set -e
BUILD_REPO="$HOME/docker_apps/blog/build-repo"
STAGING="$HOME/docker_apps/blog/www-staging"
if [ ! -d "$BUILD_REPO/.git" ]; then
echo "[build] 首次克隆构建仓"
git clone https://git.wait4x.online/wait4x/blog.git "$BUILD_REPO"
fi
cd "$BUILD_REPO"
git fetch origin main
git reset --hard origin/main
git clean -fd --exclude node_modules
SHA=$(git rev-parse --short HEAD)
echo "[build] 构建源: origin/main @ $SHA"
pnpm install --frozen-lockfile >/dev/null
pnpm astro build
echo "[build] rsync -> $STAGING"
mkdir -p "$STAGING"
rsync -a --delete "$BUILD_REPO/dist/" "$STAGING/"
ORIG="$HOME/docker_apps/blog/photos-originals"
if [ -d "$ORIG" ]; then rsync -a "$ORIG/" "$STAGING/photos-originals/"; fi
printf 'built %s at %s\n' "$SHA" "$(date -Is)" > "$STAGING/.build-stamp"
echo "[build] done: $(find "$STAGING" -name '*.html' | wc -l) html files @ $SHA"