From 1c55937a9a31efce11279f5ca56965f890707fdd Mon Sep 17 00:00:00 2001 From: Seven Gao <799889633@qq.com> Date: Thu, 27 Aug 2026 22:45:44 +0800 Subject: [PATCH] ci: add SHA fallback when mirror checkout fails The self-hosted runner's local mirror (/opt/ScratchV) may be stale, causing 'reference is not a tree' errors when checking out GITHUB_SHA. Add a fallback that fetches the exact SHA from origin and retries checkout, ensuring CI works even with an outdated mirror. Signed-off-by: Seven Gao <799889633@qq.com> --- .github/workflows/ci.yml | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6859e7a..5d957ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,11 +58,17 @@ jobs: echo "Fetching origin main..." retry "git fetch origin main" git fetch origin main || exit 1 echo "Checking out $GITHUB_SHA..." - if git -c advice.detachedHead=false checkout -f "$GITHUB_SHA"; then - echo "::notice::Checkout successful: $(git log -1 --format='%h %ai %s')" + if ! git -c advice.detachedHead=false checkout -f "$GITHUB_SHA"; then + echo "::warning::Checkout failed, fetching SHA directly from origin..." + git fetch origin "$GITHUB_SHA" || true + if git -c advice.detachedHead=false checkout -f "$GITHUB_SHA"; then + echo "::notice::Checkout successful after direct fetch: $(git log -1 --format='%h %ai %s')" + else + echo "::error::GITHUB_SHA ($GITHUB_SHA) not found — checkout failed" + exit 1 + fi else - echo "::error::GITHUB_SHA ($GITHUB_SHA) not found in local repo — checkout failed" - exit 1 + echo "::notice::Checkout successful: $(git log -1 --format='%h %ai %s')" fi - name: Install dependencies @@ -152,11 +158,17 @@ jobs: echo "Fetching origin main..." retry "git fetch origin main" git fetch origin main || exit 1 echo "Checking out $GITHUB_SHA..." - if git -c advice.detachedHead=false checkout -f "$GITHUB_SHA"; then - echo "::notice::Checkout successful: $(git log -1 --format='%h %ai %s')" + if ! git -c advice.detachedHead=false checkout -f "$GITHUB_SHA"; then + echo "::warning::Checkout failed, fetching SHA directly from origin..." + git fetch origin "$GITHUB_SHA" || true + if git -c advice.detachedHead=false checkout -f "$GITHUB_SHA"; then + echo "::notice::Checkout successful after direct fetch: $(git log -1 --format='%h %ai %s')" + else + echo "::error::GITHUB_SHA ($GITHUB_SHA) not found — checkout failed" + exit 1 + fi else - echo "::error::GITHUB_SHA ($GITHUB_SHA) not found in local repo — checkout failed" - exit 1 + echo "::notice::Checkout successful: $(git log -1 --format='%h %ai %s')" fi - name: Install dependencies