This commit is contained in:
wess09 2026-05-12 12:53:25 +08:00
parent e8658a3c4d
commit 2f7f43947f
3 changed files with 28 additions and 7 deletions

View File

@ -42,7 +42,7 @@ def build_pack(latest, old, output_dir):
def main():
parser = argparse.ArgumentParser(description="Build git-over-cdn update packs.")
parser.add_argument("--branch", default="master")
parser.add_argument("--history", type=int, default=50)
parser.add_argument("--history", type=int, default=1)
parser.add_argument("--output", default="dist/git-over-cdn")
args = parser.parse_args()

View File

@ -6,6 +6,7 @@ import time
from pathlib import Path
import requests
from requests import RequestException
API_BASE = "https://open-api.123pan.com"
@ -16,6 +17,21 @@ class Pan123Error(RuntimeError):
pass
def request_with_retry(method, url, attempts=5, timeout=(30, 600), **kwargs):
last_error = None
for attempt in range(1, attempts + 1):
try:
return requests.request(method, url, timeout=timeout, **kwargs)
except RequestException as e:
last_error = e
if attempt == attempts:
break
wait = min(2 ** attempt, 30)
print(f"request failed, retrying in {wait}s ({attempt}/{attempts}): {e}")
time.sleep(wait)
raise last_error
def md5_file(path):
digest = hashlib.md5()
with path.open("rb") as f:
@ -29,7 +45,7 @@ def api_json(method, url, token=None, **kwargs):
headers["Platform"] = PLATFORM
if token:
headers["Authorization"] = f"Bearer {token}"
response = requests.request(method, url, headers=headers, timeout=120, **kwargs)
response = request_with_retry(method, url, headers=headers, **kwargs)
response.raise_for_status()
data = response.json()
if data.get("code") == 20103:
@ -90,6 +106,7 @@ def upload_slices(token, create_data, path):
data=data,
files=files,
)
print(f"uploaded slice {slice_no}: {path}")
slice_no += 1
@ -144,6 +161,7 @@ def main():
path for path in source.rglob("*")
if path.is_file() and (path.name == "latest.json" or path.suffix == ".zip")
)
print(f"uploading {len(files)} file(s) from {source} to /{args.remote_prefix.strip('/')}")
for path in files:
upload_file(token, args.parent_file_id, source, path, args.remote_prefix)

View File

@ -6,7 +6,7 @@ on:
history:
description: "How many old commits to build packs for"
required: false
default: "50"
default: "1"
parent_file_id:
description: "123pan parent folder fileID, defaults to PAN123_PARENT_FILE_ID secret or azur folder"
required: false
@ -32,11 +32,14 @@ jobs:
fetch-depth: 0
ref: master
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Build git-over-cdn packs
run: |
python .github/scripts/build_git_over_cdn.py \
uv run python .github/scripts/build_git_over_cdn.py \
--branch master \
--history "${{ github.event.inputs.history || '50' }}" \
--history "${{ github.event.inputs.history || '1' }}" \
--output dist/git-over-cdn
- name: Upload to 123pan
@ -47,10 +50,10 @@ jobs:
PAN123_PARENT_FILE_ID_INPUT: ${{ github.event.inputs.parent_file_id }}
PAN123_REMOTE_PREFIX_INPUT: ${{ github.event.inputs.remote_prefix }}
run: |
python -m pip install requests
uv pip install --system requests
PAN123_PARENT_FILE_ID="${PAN123_PARENT_FILE_ID_INPUT:-${PAN123_PARENT_FILE_ID_SECRET:-31540282}}"
PAN123_REMOTE_PREFIX="${PAN123_REMOTE_PREFIX_INPUT:-AzurPilot_master}"
python .github/scripts/upload_123pan.py \
uv run python .github/scripts/upload_123pan.py \
--source dist/git-over-cdn \
--parent-file-id "$PAN123_PARENT_FILE_ID" \
--remote-prefix "$PAN123_REMOTE_PREFIX"