From 819545db52e00d41dda9e4a25da18d8593f6ee9e Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Thu, 9 Jul 2026 08:21:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20auto-merge=E6=94=B9=E4=B8=BAhost?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F+python=20checkout=EF=BC=8C=E8=A7=A3=E5=86=B3?= =?UTF-8?q?github=E8=B6=85=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/auto-merge.yml | 57 +++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/.gitea/workflows/auto-merge.yml b/.gitea/workflows/auto-merge.yml index 97c85a970..e2e924cdb 100644 --- a/.gitea/workflows/auto-merge.yml +++ b/.gitea/workflows/auto-merge.yml @@ -7,7 +7,7 @@ on: jobs: auto-merge: - runs-on: ubuntu-latest + runs-on: saas timeout-minutes: 10 steps: - name: Checkout code @@ -16,22 +16,45 @@ jobs: GITHUB_TOKEN: ${{ github.token }} run: | set -eu - archive_url="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/archive/${GITHUB_SHA}.tar.gz" - for i in 1 2 3 4 5; do - if wget --header="Authorization: token ${GITHUB_TOKEN}" -O /tmp/repo.tar.gz "$archive_url" 2>&1; then - break - fi - if [ "$i" -lt 5 ]; then - wait=$((2 ** i)) - echo "Checkout failed (attempt $i/5), retrying in ${wait}s..." - sleep "$wait" - else - echo "Checkout failed after 5 attempts" - exit 1 - fi - done - tar -xzf /tmp/repo.tar.gz --strip-components=1 -C . - rm -f /tmp/repo.tar.gz + python3 - <<'PY' + import io, os, tarfile, time, urllib.request, urllib.error + url = f"{os.environ['GITHUB_API_URL']}/repos/{os.environ['GITHUB_REPOSITORY']}/{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: + top_prefix = tar.getmembers()[0].name.split('/', 1)[0] + '/' + for member in tar.getmembers(): + name = member.name + if name == top_prefix[:-1]: + continue + if name.startswith(top_prefix): + member.name = name[len(top_prefix):] + if member.name: + tar.extract(member, '.') + PY - name: Auto merge develop PRs run: |