Files
jiu/scripts/ci/fetch-windows-staged.sh
T
wangjia fcd8733679
Design Source Checks / design-source (push) Has been cancelled
fix(ci): fetch 用 browser_download_url 下载(assets API 返回元数据非二进制)+ 大小校验
测试发现 Gitea /releases/{id}/assets/{id} 端点返回附件元数据 JSON(260B)而非二进制。
改用 browser_download_url 直链下载,并加 <1MB 拒绝发版的完整性校验。
端到端验证:winstage-v9.9.9 → 拉到完整 25M PE32 安装器;版本不匹配硬失败。

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

54 lines
2.4 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> — 发版时从 NAS gitea 暂存 Release 拉 Windows 安装器。
#
# 用途:deploy-client.yml 的 build-windows-ci job(仅当 WINDOWS_SOURCE=github 时启用)
# 调用此脚本,按发版 tag(client-vX.Y.Z) 的**同一版本号**去找 `winstage-vX.Y.Z`
# 把 jiu-windows-x64-setup.exe 下到 dist/,供后续 upload-artifact → release/deploy 使用。
#
# **版本强匹配**:找不到对应版本的暂存包 → 硬失败并提示先在 GitHub 构建该版本,
# 绝不静默发出旧版/错版 Windows 包。
#
# 需要 envFORGEJO_URL、FORGEJO_TOKEN、GITEA_REPOSITORY。
set -euo pipefail
. "$(dirname "$0")/lib-forgejo.sh"
TAG="$1"
VER="$(ver_from_tag "$TAG")"
STAGE_TAG="winstage-v${VER}"
NAME="jiu-windows-x64-setup.exe"
echo "==> fetch-windows-staged: 发版版本=${VER},找暂存 ${STAGE_TAG}"
base="${FORGEJO_URL}/api/v1/repos/${GITEA_REPOSITORY}"
mkdir -p dist
if ! info=$(curl -kfsS -H "Authorization: token ${FORGEJO_TOKEN}" "${base}/releases/tags/${STAGE_TAG}" 2>/dev/null); then
cat >&2 <<MSG
ERROR: NAS 上找不到暂存 Release ${STAGE_TAG}。
WINDOWS_SOURCE=github 需要先在 GitHub 构建**版本 ${VER}** 的 Windows 包:
gh workflow run windows.yml -f ver=${VER} (仓库 bj-wangjia/jiu)
构建完成会把安装器暂存到 NAS,再重跑本次发版即可。
MSG
exit 1
fi
# 取同名资产的 browser_download_url(版本已由 STAGE_TAG 精确锁定)。JSON 经 stdin 传入避免转义。
# 注意:API 的 /assets/{id} 端点返回的是**元数据 JSON**(非二进制),必须用 browser_download_url。
dl=$(printf '%s' "$info" | python3 -c "import sys,json; print(next((a['browser_download_url'] for a in json.load(sys.stdin).get('assets',[]) if a['name']=='${NAME}'), ''))")
if [ -z "$dl" ]; then
echo "ERROR: ${STAGE_TAG} 存在但缺少 ${NAME} 资产(GitHub 构建可能失败)。" >&2
exit 1
fi
echo "==> fetch-windows-staged: 下载 ${dl} → dist/${NAME}"
curl -kfsSL -H "Authorization: token ${FORGEJO_TOKEN}" "$dl" -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} 匹配)"