From 38b42a266286c36b5a856608208620623477b08c Mon Sep 17 00:00:00 2001 From: richblack Date: Mon, 20 Apr 2026 20:39:54 +0800 Subject: [PATCH] ci(deploy): fetch full history + fallback when base sha unreachable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fetch-depth: 2 is too shallow — a batch push of 10 commits (like Phase 1-6 commit chain) leaves github.event.before outside the fetched range, so git diff returns empty and nothing deploys. - Set fetch-depth: 0 (full history) so diff always has a reachable base. - Added git cat-file -e check: even with full history, force-pushes or orphan base SHAs trigger a "deploy all" fallback instead of silently skipping. Co-Authored-By: Claude Opus 4.7 --- .github/workflows/deploy.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a8bbeee..d7341f8 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -40,8 +40,9 @@ jobs: steps: - uses: actions/checkout@v5 with: - # diff 判斷需要前一個 commit - fetch-depth: 2 + # 抓全部 history 以確保 github.event.before 可及 + # (fetch-depth: 2 會在大批 commit push / force-push 時失效) + fetch-depth: 0 - name: Enumerate & filter id: emit @@ -95,10 +96,13 @@ jobs: # 也要連動 registry/components/{name}/ — 改 main.go 應該 redeploy .component-builds/{name}/ base_sha="${{ github.event.before }}" head_sha="${{ github.sha }}" - # 若 base 為 0000...(首次 push)或 base 不可及,fallback 為全部 + # 若 base 為 0000...(首次 push)或 base 在本地不可及,fallback 為全部 if [[ -z "$base_sha" || "$base_sha" == "0000000000000000000000000000000000000000" ]]; then echo "No base sha, deploy all" targets=("${all_dirs[@]}") + elif ! git cat-file -e "$base_sha" 2>/dev/null; then + echo "Base sha $base_sha unreachable locally, deploy all" + targets=("${all_dirs[@]}") else # 取得 diff 的檔案路徑 mapfile -t changed < <(git diff --name-only "$base_sha" "$head_sha" || true)