ci(deploy): fetch full history + fallback when base sha unreachable

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 <noreply@anthropic.com>
This commit is contained in:
2026-04-20 20:39:54 +08:00
parent 4516cdee4b
commit 38b42a2662
+7 -3
View File
@@ -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)