From e5004cbc851183024b50bd9122c373280ba3e342 Mon Sep 17 00:00:00 2001 From: liboze2026 Date: Fri, 15 May 2026 15:36:23 +0800 Subject: [PATCH] fix(release): gh-pages bootstrap on first run (closes #5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit issue #5 / PR #2 dogfood 后第 3 个 gap:本仓库从未建过 gh-pages 分支, release-branch.yml 的 step 14 直接 `git clone --branch=gh-pages` 在 那种情况下报 'fatal: Remote branch gh-pages not found',整个 publish job 挂在最后一步。 修复(12 行 bash): - try clone --branch=gh-pages → 命中走原路径 - 失败(分支不存在)→ rm 临时目录、clone default、checkout --orphan gh-pages、git rm 清 index → 后续 git add + commit + push 会把 latest.json 作为 orphan 首 commit 推上去,GitHub 自动建 gh-pages 下次 publish run 应: - 早退守门看 latest.json(此时 gh-pages 已建好) → 若 SHA 一致 skip - 否则正常 publish 更新 latest.json 完整 release pipeline 至此应真端到端可用。验证留给 PR 合后下一次 push main / 6h cron / workflow_dispatch 触发 release-branch.yml。 Co-Authored-By: Claude Opus 4.7 (1M context) --- .github/workflows/release-branch.yml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release-branch.yml b/.github/workflows/release-branch.yml index 8968e0c..8a25995 100644 --- a/.github/workflows/release-branch.yml +++ b/.github/workflows/release-branch.yml @@ -234,11 +234,25 @@ jobs: TAG="${{ steps.version.outputs.tag }}" VERSION="${TAG#v}" REPO_DIR=$(mktemp -d) + REPO_URL="https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git" - git clone --depth=1 --branch=gh-pages \ - "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git" \ - "$REPO_DIR" - cd "$REPO_DIR" + # Bootstrap-safe gh-pages 拉取(issue #5):仓库首次发 release 时 + # gh-pages 分支可能尚未建过;原 `git clone --branch=gh-pages` 在那种情况 + # 下报 "fatal: Remote branch gh-pages not found",整个 publish job 挂。 + # 修复:try clone 指定分支;失败则 clone default、checkout --orphan、 + # 清空 index,后续 git add + git commit + git push 会把 latest.json + # 作为 orphan 的首个 commit 推上去,自动建分支。 + if git clone --depth=1 --branch=gh-pages "$REPO_URL" "$REPO_DIR" 2>/dev/null; then + echo "gh-pages 已存在 → 在其上 update latest.json" + cd "$REPO_DIR" + else + echo "gh-pages 不存在(首次)→ 初始化为 orphan branch" + rm -rf "$REPO_DIR" + git clone --depth=1 "$REPO_URL" "$REPO_DIR" + cd "$REPO_DIR" + git checkout --orphan gh-pages + git rm -rf . >/dev/null 2>&1 || true + fi # Build the JSON with jq (avoids manual string concatenation + # double-escaping pitfalls; validation guard in the prior step