From 5e3188aab0f61515228107f655734b23564443cc Mon Sep 17 00:00:00 2001 From: xiaoxia-bot Date: Tue, 14 Jul 2026 11:51:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20=E4=BF=AE=E5=A4=8D=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E9=83=A8=E7=BD=B2SSH=E5=AF=86=E9=92=A5=E6=9F=A5=E6=89=BE=20+?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9Echeckout=E6=AD=A5=E9=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SSH密钥查找增加 id_ed25519 作为备选(Runner已有) - deploy-production job 增加checkout步骤,确保通知脚本能找到 - 修复部署失败时ci_notify_failure.py找不到的问题 --- .gitea/workflows/ci-cd.yml | 54 +++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/ci-cd.yml b/.gitea/workflows/ci-cd.yml index 50c56a4f7..02efd503b 100644 --- a/.gitea/workflows/ci-cd.yml +++ b/.gitea/workflows/ci-cd.yml @@ -1047,6 +1047,52 @@ jobs: needs: build-production-runtime-images steps: + - name: Checkout code + shell: sh + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + set -eu + python3 - <<'PY' + import io, os, tarfile, time, urllib.request, urllib.error + url = f"{os.environ['GITHUB_API_URL']}/repos/{os.environ['GITHUB_REPOSITORY']}/archive/{os.environ['GITHUB_SHA']}.tar.gz" + request = urllib.request.Request(url, headers={"Authorization": f"token {os.environ['GITHUB_TOKEN']}"}) + last_err = None + for attempt in range(5): + try: + with urllib.request.urlopen(request, timeout=120) as response: + archive = response.read() + break + except urllib.error.HTTPError as e: + last_err = e + if e.code >= 500 and attempt < 4: + wait = 2 ** attempt + print(f"Checkout HTTP {e.code}, retrying in {wait}s (attempt {attempt+1}/5)...") + time.sleep(wait) + continue + raise + except Exception as e: + last_err = e + if attempt < 4: + wait = 2 ** attempt + print(f"Checkout error: {e}, retrying in {wait}s (attempt {attempt+1}/5)...") + time.sleep(wait) + continue + raise + else: + raise last_err + with tarfile.open(fileobj=io.BytesIO(archive), mode='r:gz') as tar: + root_prefix = tar.getmembers()[0].name.split('/', 1)[0] + '/' + for member in tar.getmembers(): + name = member.name + if name == root_prefix[:-1]: + continue + if name.startswith(root_prefix): + member.name = name[len(root_prefix):] + if member.name: + tar.extract(member, '.') + PY + - name: Install SSH client shell: sh run: | @@ -1081,10 +1127,16 @@ jobs: key_path="$HOME/.ssh/xiaoxia_runtime_builder" echo "Using key: $key_path (home key)" elif [ -n "${PRODUCTION_SSH_KEY:-}" ]; then - key_path="$HOME/.ssh/id_ed25519" + key_path="$HOME/.ssh/production_deploy_key" printf '%s\n' "$PRODUCTION_SSH_KEY" > "$key_path" chmod 600 "$key_path" echo "Using key from PRODUCTION_SSH_KEY secret" + elif [ -f "$HOME/.ssh/id_ed25519" ]; then + key_path="$HOME/.ssh/id_ed25519" + echo "Using key: $key_path (default id_ed25519)" + elif [ -f /root/.ssh/id_ed25519 ]; then + key_path="/root/.ssh/id_ed25519" + echo "Using key: $key_path (root id_ed25519)" else echo "ERROR: No SSH key available" ls -la ~/.ssh/ 2>/dev/null || true -- 2.54.0