From 3b05d5a73a390497edc98fe5aa951ab7b7f1690c Mon Sep 17 00:00:00 2001 From: MiFaZhan Date: Fri, 30 Oct 2026 13:19:53 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E9=95=9C=E5=83=8F=E5=88=B0=20Gitee=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=80=E9=81=BF=E9=87=8D=E8=AF=95=E4=B8=8E?= =?UTF-8?q?=E6=AF=8F=E6=97=A5=E5=85=9C=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gitee 在推送密集时返回 429 Pending queue overflowed / 408 Authorization server timeout,属服务端限流,原实现一次失败即终止。 - 推送改为最多 5 次退避重试(30s/60s/90s/120s) - 增加每日定时兜底(18:30 UTC = 次日 02:30 北京时间), 避免某次推送失败后长期不同步 --- .gitea/workflows/mirror-to-gitee.yml | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/mirror-to-gitee.yml b/.gitea/workflows/mirror-to-gitee.yml index 49562d3..b8f8b52 100644 --- a/.gitea/workflows/mirror-to-gitee.yml +++ b/.gitea/workflows/mirror-to-gitee.yml @@ -1,13 +1,16 @@ name: mirror-to-gitee # 把本仓同步到 Gitee 企业仓 snowgoat/<同名仓库>。 -# 触发:main 分支推送、v* tag 推送,也可手动。 +# 触发:main 分支推送、v* tag 推送、手动;另有每日兜底重试。 on: push: branches: - main tags: - 'v*' + schedule: + # Gitea Actions 的 cron 用 UTC:18:30 UTC = 次日 02:30 北京时间 + - cron: '30 18 * * *' workflow_dispatch: concurrency: @@ -26,7 +29,7 @@ jobs: DST_USER: ${{ secrets.GITEE_USER }} REPO_NAME: ${{ github.event.repository.name }} run: | - set -eu + set -u if [ -z "${REPO_NAME:-}" ]; then echo "未取到仓库名,退出"; exit 1 @@ -39,10 +42,23 @@ jobs: echo "目标:gitee.com/$DST_OWNER/$REPO_NAME" git clone --mirror "https://jenkins:${SRC_TOKEN}@git.5iot.com/iotlcm-public/${REPO_NAME}.git" "$WORK/repo.git" - cd "$WORK/repo.git" echo "本地 ref:$(git for-each-ref --format='%(refname:short)' | tr '\n' ' ')" - git push --mirror "https://${DST_USER}:${DST_TOKEN}@gitee.com/${DST_OWNER}/${REPO_NAME}.git" + # Gitee 在推送密集时会返回 429 Pending queue overflowed / 408 Authorization server timeout, + # 属服务端限流,退避重试即可。 + attempt=0 + while [ "$attempt" -lt 5 ]; do + attempt=$((attempt + 1)) + echo "----- 推送尝试 $attempt/5" + if git push --mirror "https://${DST_USER}:${DST_TOKEN}@gitee.com/${DST_OWNER}/${REPO_NAME}.git" 2>&1; then + echo "✅ 已同步到 Gitee" + exit 0 + fi + wait_s=$((attempt * 30)) + echo "推送失败,${wait_s}s 后重试" + sleep "$wait_s" + done - echo "✅ 已同步到 Gitee" + echo "❌ 连续 5 次推送失败,请检查 Gitee 状态或令牌" + exit 1