Files
jiu/scripts/ci/fetch-windows-staged.sh
T
wangjia c8eabe0596
Design Source Checks / design-source (push) Failing after 5m2s
ci(windows): Windows 包发版改从 GitHub Release 拉取(免 frps)
mac-runner off-LAN 时,从 NAS 经 ali frps 下载 26MB 太慢/易断(实测 ~220KB/s 且中途断)。
改为:windows.yml 额外发布到 GitHub Release winstage-v<版本>;deploy-client 的
build-windows-ci 从 github.com 拉(不过 frps)+ 重试断点续传 + 完整性校验。
需 gitea 密钥 GH_TOKEN(已设)。NAS 暂存保留作记录。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P9G7E3wmAYL9KeYCVZVsqu
2026-07-18 09:13:50 +08:00

61 lines
2.9 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# fetch-windows-staged.sh <tag> — 发版时从 GitHub Release 拉 Windows 安装器。
#
# 用途:deploy-client.yml 的 build-windows-ci job(仅当 WINDOWS_SOURCE=github 时启用)
# 调用此脚本,按发版 tag(client-vX.Y.Z) 的**同一版本号**去 GitHub 找 `winstage-vX.Y.Z`
# 把 jiu-windows-x64-setup.exe 下到 dist/,供后续 upload-artifact → release/deploy 使用。
#
# **为什么从 GitHub 而不是 NAS**mac-runner 常在 off-LANNAS 只能经 ali frps(慢又易断)
# Windows 包本就是 GitHub 云构建的,直接从 github.com 拉最稳、不过 frps。
#
# **版本强匹配**:找不到对应版本的 GitHub Release → 硬失败并提示先构建该版本,
# 绝不静默发出旧版/错版 Windows 包。
#
# 需要 envGH_TOKEN(github PAT,私有库拉 release 需 auth)GH_REPO(默认 bj-wangjia/jiu)。
set -euo pipefail
TAG="$1"
VER="${TAG#client-v}"; VER="${VER#v}"
STAGE_TAG="winstage-v${VER}"
NAME="jiu-windows-x64-setup.exe"
GH_REPO="${GH_REPO:-bj-wangjia/jiu}"
: "${GH_TOKEN:?需要 GH_TOKEN(github PAT)}"
echo "==> fetch-windows-staged: 发版版本=${VER},从 GitHub 找 ${STAGE_TAG}repo ${GH_REPO}"
api="https://api.github.com/repos/${GH_REPO}"
mkdir -p dist
if ! info=$(curl -fsSL -H "Authorization: Bearer ${GH_TOKEN}" -H "Accept: application/vnd.github+json" "${api}/releases/tags/${STAGE_TAG}" 2>/dev/null); then
cat >&2 <<MSG
ERROR: GitHub 上找不到 Release ${STAGE_TAG}。
WINDOWS_SOURCE=github 需要先在 GitHub 构建**版本 ${VER}** 的 Windows 包:
gh workflow run windows.yml -f ver=${VER} (仓库 ${GH_REPO})
构建完成会发布 Windows Release,再重跑本次发版即可。
MSG
exit 1
fi
# 取同名资产的 GitHub API asset url(用 Accept: octet-stream 拉二进制,302 跳 codeload,走 github.com 不过 frps
aid=$(printf '%s' "$info" | python3 -c "import sys,json; print(next((a['id'] for a in json.load(sys.stdin).get('assets',[]) if a['name']=='${NAME}'), ''))")
if [ -z "$aid" ]; then
echo "ERROR: ${STAGE_TAG} 存在但缺少 ${NAME} 资产(GitHub 构建可能失败)。" >&2
exit 1
fi
echo "==> fetch-windows-staged: 下载 asset id=${aid}(GitHub)→ dist/${NAME}"
# 重试 + 断点续传(-C -)+ 低速/超时上限:断了自动续传重来,不会一次瞬断就整个失败。
curl -fSL \
--retry 30 --retry-delay 5 --retry-all-errors -C - \
--connect-timeout 15 --speed-time 60 --speed-limit 1024 --max-time 900 \
-H "Authorization: Bearer ${GH_TOKEN}" -H "Accept: application/octet-stream" \
"${api}/releases/assets/${aid}" -o "dist/${NAME}"
ls -lh "dist/${NAME}"
# 完整性校验:安装器至少应有 1MB,防重定向页/截断被当成有效包发出去。
sz=$(wc -c < "dist/${NAME}")
if [ "$sz" -lt 1000000 ]; then
echo "ERROR: 下载的 ${NAME}${sz} 字节,疑似损坏,拒绝发版。" >&2
exit 1
fi
echo "==> fetch-windows-staged: done(版本 ${VER} 匹配,源=GitHub"