Files
ssw-jnpf-lite-rust/scripts/fetch-platform.sh
T
admin dc54e8bd1d refactor(dep): 平台依赖改为 vendor 发布包,去掉 git 依赖
- Cargo.toml 的 sspf 由 git tag 改为 path 指向 vendor/sspf-v0.5.0/crates/sspf。
- 新增 scripts/fetch-platform.sh:解包平台发布包到 vendor/(含离线校验)。
- [workspace] exclude vendor/,避免包内 crate 被误并入职本仓 workspace。
- .gitignore 忽略 vendor/;SKILL/README/CLAUDE/HANDOFF/runbook 同步说明新模型。
2026-11-05 09:28:48 +08:00

63 lines
3.2 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-platform.sh —— 把平台「自包含发布包」解包到 vendor/,让本仓用 path 依赖吃 sspf
#
# 背景(2026-11-05 依赖模型变更):平台仓每个版本产出一个自包含包
# `dist/sspf-vX.Y.Z.tar.gz`(预编译 sspf-admin 二进制 + 平台 crate 源码 + Cargo.lock),
# 本仓**不再直接依赖 git 仓**,而是把它解包到 vendor/ 后用 path 依赖指进去。
#
# 用法:
# bash scripts/fetch-platform.sh 0.5.0 # 解包 sspf-v0.5.0 → vendor/sspf-v0.5.0/
# bash scripts/fetch-platform.sh # 默认从 Cargo.toml 推断 sspf 版本
#
# 包来源(按优先级):
# 1. 环境变量 SSPF_DIST_DIR 指向目录里的 sspf-vX.Y.Z.tar.gz
# 2. 默认:$HOME/Desktop/workspace/ssw-platform/dist/
# (未来可扩展为从内网 Gitea release 下载;此处先走本地 dist,单机开发够用)
#
set -euo pipefail
cd "$(dirname "$0")/.."
SKILL_ROOT="$(pwd)"
# ── 版本号 ──────────────────────────────────────────────────────
if [[ $# -ge 1 ]]; then
VERSION="$1"
else
VERSION="$(grep -oE 'sspf-v[0-9]+\.[0-9]+\.[0-9]+' Cargo.toml 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)"
if [[ -z "${VERSION}" ]]; then
VERSION="$(grep -oE 'tag = "v[0-9.]+"' Cargo.toml 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)"
fi
if [[ -z "${VERSION}" ]]; then
echo "!! 无法从 Cargo.toml 推断版本,请显式传版本:bash scripts/fetch-platform.sh 0.5.0" >&2
exit 1
fi
fi
# 🔴 目录/包名带 v 前缀,与 git tag(vX.Y.Z)对齐;crate 自身 version 是无 v 的 X.Y.Z
PKG="sspf-v${VERSION}"
TAR="${PKG}.tar.gz"
# ── 定位包 ──────────────────────────────────────────────────────
DIST_DIR="${SSPF_DIST_DIR:-$HOME/Desktop/workspace/ssw-platform/dist}"
if [[ ! -f "${DIST_DIR}/${TAR}" ]]; then
echo "!! 找不到包: ${DIST_DIR}/${TAR}" >&2
echo " 用环境变量 SSPF_DIST_DIR 指定平台仓 dist 目录,或先在平台仓跑过 bash scripts/release.sh" >&2
exit 1
fi
# ── 解包 ────────────────────────────────────────────────────────
echo "==> 解包 ${DIST_DIR}/${TAR} → ${SKILL_ROOT}/vendor/${PKG}/"
mkdir -p vendor
tar -xzf "${DIST_DIR}/${TAR}" -C vendor
echo "${VERSION}" > "vendor/VERSION"
# ── 校验 ────────────────────────────────────────────────────────
if [[ ! -f "vendor/${PKG}/crates/sspf/Cargo.toml" ]]; then
echo "!! 解包结果异常:vendor/${PKG}/crates/sspf/Cargo.toml 不存在" >&2
exit 1
fi
PKGVER="$(grep -m1 '^version' "vendor/${PKG}/crates/sspf/Cargo.toml" | sed -E 's/.*"([^"]+)".*/\1/')"
echo "==> 已就绪:vendor/${PKG}/crates/sspf(包内 sspf 版本 ${PKGVER})"
echo " Cargo.toml 里应写:"
echo " sspf = { path = \"vendor/${PKG}/crates/sspf\", version = \"${VERSION%.*}\" }"
echo " 并确认 .gitignore 含 vendor/"