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)