Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ jobs:

- name: Schema façade check
run: pnpm run check:facade

# Preparation never uploads and is permitted on detached PR checkouts.
# The publish mode rejects CI and requires an interactive confirmation.
- name: SDK release preparation (no publication)
run: pnpm run release
15 changes: 14 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pnpm typecheck # pnpm -r typecheck
pnpm test # pnpm -r test
pnpm lint # biome check .
pnpm run check:facade # scripts/check-facade.mjs
pnpm run release # validate, build and pack; never uploads by default
```

Prefer `pnpm exec` over `npx` for one-off CLI invocations in this workspace.
Expand Down Expand Up @@ -83,12 +84,24 @@ Prefer `pnpm exec` over `npx` for one-off CLI invocations in this workspace.

## Publish order

`pnpm publish` per package, human-run only — never executed by an agent:
`pnpm run release` is the canonical SDK preparation entrypoint. It installs
locked dependencies, validates, builds, tests and packs all four packages.
Agents may run this default/dry-run mode.

`pnpm run release -- --publish` is human-run only — never executed by an
agent. It requires a clean, current `main`, an interactive terminal outside CI,
and explicit confirmation after the package plan is displayed. It invokes
`pnpm publish` for verified tarballs in this order:

```
plugin-manifest-schema → plugin-api → plugin-cli → create-motrix-plugin
```

See [the release guide](docs/releasing.md) and its
[Chinese counterpart](docs/releasing.zh-CN.md) for requirements, artifacts and
partial-release recovery. The script does not create tags, merge PRs or sign
plugin bundles.

## Conventions

- Conversation language is Chinese; code, commits, identifiers, and file
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public commands — ask for the minimum you need; broad host patterns and
pnpm install
pnpm build # tsup, all packages
pnpm typecheck
pnpm test # vitest, all packages
pnpm test # release-tool tests + package suites
pnpm lint # biome
pnpm run check:facade # façade-purity guard
```
Expand All @@ -302,6 +302,13 @@ in `packages/plugin-manifest-schema` only (`plugin-cli`'s
always ships together with a matching CLI release, because the CLI embeds
the schema at build time.

## SDK releases

`pnpm run release` validates, builds and packs all four SDK packages without
uploading. Publication is a separate, human-confirmed mode; CI only prepares
artifacts. See the [release guide](docs/releasing.md) for requirements, the
fixed package order and recovery from a partial release.

## License

[MIT](./LICENSE)
6 changes: 5 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ Plugins 页安装(**Install from .moext**)。安装时 Motrix 会弹出 consent
pnpm install
pnpm build # tsup, all packages
pnpm typecheck
pnpm test # vitest, all packages
pnpm test # release-tool tests + package suites
pnpm lint # biome
pnpm run check:facade # façade-purity guard
```
Expand All @@ -283,6 +283,10 @@ pnpm run check:facade # façade-purity guard
是受守护的纯 re-export);schema 发新版时必须同批发布配套的 CLI 版本,
因为 CLI 在构建时内嵌了 schema。

## SDK 发布

`pnpm run release` 统一校验、构建和打包四个 SDK 包,默认不上传。正式发布使用需要人工确认的独立模式,CI 只准备产物。前置条件、固定发布顺序和部分发布恢复方式见[发布指南](docs/releasing.zh-CN.md)。

## License

[MIT](./LICENSE)
134 changes: 134 additions & 0 deletions docs/releasing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Releasing the SDK

English | [简体中文](releasing.zh-CN.md)

The repository's release entrypoint is `pnpm run release`. Its default mode
validates, builds and packs the four npm packages without publishing. Uploading
requires an explicit maintainer action in an interactive terminal. CI and agents
may run preparation; agents must not run the publish mode.

This workflow releases the SDK npm packages. It does not change versions, merge
PRs, create Git tags, publish Motrix, sign `.moext` plugins or update the registry.

## Requirements

- Node.js 20 or later, Git, `tar` with gzip support, and the exact pnpm version
specified by the root `package.json`. On Windows, use standalone `pnpm.exe`
(as CI does) or a pnpm launcher that supplies its JavaScript `npm_execpath`.
- Install the versions intended for release in the four package manifests through
a reviewed PR first. The script accepts stable `x.y.z` versions only and uses
the public npm registry with the `latest` tag. Schema and CLI versions must
match because the CLI embeds the schema. API and create-wrapper versions may
differ; all four packages are checked together.
- For publication, a clean `main` checkout, including no untracked files, whose
HEAD equals the current `origin/main`. Keep the checkout and artifacts unchanged
for the whole run. Publishing requires network access to GitHub and npm and an
npm account authorized to publish these packages. Authentication and any OTP
prompts remain with pnpm; the script does not read or store credentials.

## Prepare without publishing

From the SDK repository root:

```bash
pnpm run release
# Explicit equivalent:
pnpm run release -- --dry-run
```

Preparation supports feature branches, detached CI checkouts and local changes.
The report records the source commit and whether the checkout was dirty. A dirty
preparation is useful for development, but cannot authorize a publication.

The script runs these gates in order, stopping at the first failure:

1. Validate package identities, stable versions, publication configuration, the
schema/CLI version pair, and the pinned package manager.
2. `pnpm install --frozen-lockfile`.
3. `pnpm run lint` and `pnpm run check:facade`.
4. `pnpm run build`, then `pnpm run typecheck`, then `pnpm run test`.
5. Pack each of the four packages with pnpm and inspect the actual tarballs.

Packing must finish for the entire batch before any upload is considered. The
archive checks verify package identities, required entrypoints/files and rewritten
workspace dependencies. Published dependencies cannot contain `workspace:`,
`link:` or `file:` references, and the CLI cannot retain runtime `@motrix/`
dependencies instead of embedding its SDK code.

Each run creates a fresh ignored `dist/release/sdk-*/` directory containing the
four `.tgz` archives and `release.json`. The report includes source Git state,
pnpm version, package versions, sizes, SHA-256 digests, npm SHA-512 integrity
strings, progress and any failure. Earlier runs are retained for investigation.
Preparation performs no npm metadata lookup or upload; installing locked
build dependencies can still access the package registry.

## Publish manually

After the version/tooling PRs are merged, use a clean, current `main` checkout and
run this command yourself:

```bash
pnpm run release -- --publish
```

This reruns the complete preparation pipeline. Publish mode rejects CI and
non-interactive terminals before running the pipeline. There is no `--yes`,
`--force` or validation-skip option.

Before uploading, the script checks all four exact versions on npm. A 404 means
that a version is available for publication; an authentication, rate-limit,
network or other registry error stops the run. An existing version is skipped
only if its SHA-512 integrity matches the newly prepared archive. A conflicting
version stops the whole batch before the first upload.

The terminal displays the package versions, integrity values, destination and
which packages are pending or already published. Type exactly
`publish SDK packages to npm` to authorize the pending uploads. Declining leaves
the packages unpublished. An entirely identical, already-published batch finishes
without asking for confirmation or sending uploads.

Publication order is fixed:

```text
@motrix/plugin-manifest-schema
@motrix/plugin-api
@motrix/plugin-cli
create-motrix-plugin
```

The script rechecks Git state and archive integrity after confirmation and before
each upload. It invokes pnpm with the verified tarball, explicit public registry,
public access and `latest` tag, preserving Git checks and interactive OTP support.
Each package must become visible with the matching integrity before the next is
published. Missing metadata is polled up to 15 times at two-second intervals;
each HTTP request has a 15-second timeout. Other registry errors stop immediately.

## Failure and partial-release recovery

npm publication across four packages is not atomic. If upload or verification
fails, later packages are not attempted, and nothing is unpublished or retried
automatically. Preserve the run directory and inspect `release.json` and npm.
A `publishing` status is uncertain: the server may have accepted an upload even
if the client failed or metadata was not yet visible.

Once the cause is resolved, rerun from the same reviewed source with the pinned
build tools. The script rebuilds and compares exact published integrity values;
matching packages are skipped, and only the missing packages are submitted after
confirmation. It never overwrites an immutable version. If rebuilding changes the
bytes of a published version, stop and investigate; do not force the upload or
silently skip the mismatch. Any version correction belongs in a new reviewed PR,
keeping schema/CLI versions aligned.

Keep consumers blocked until the coordinated SDK batch is verified. Only then
update Motrix and official-plugin dependencies and lockfiles and rerun their clean
CI. Publishing an SDK version does not prove that a compatible host or plugin
release is available; verify those separately.

## Tests and CI

`pnpm test` runs the release script's Node tests and the existing SDK suites.
Publication tests inject command and registry substitutes; they never upload to
npm. Tests cover ordering, failed gates, archive inspection, registry conflicts,
confirmation, changed artifacts, partial release and uncertain upload results.
CI also runs the actual default preparation command on each supported OS/Node
combination. No workflow automatically publishes packages.
74 changes: 74 additions & 0 deletions docs/releasing.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# 发布 SDK

[English](releasing.md) | 简体中文

仓库统一入口为 `pnpm run release`,默认仅校验、构建和打包四个 npm 包,不执行发布。上传必须由维护者在交互式终端明确触发。CI 和代理可以运行准备模式;代理不得执行发布模式。

这套流程只发布 SDK npm 包,不修改版本号、不合并 PR、不创建 Git tag、不发布 Motrix、不签名 `.moext` 插件,也不更新插件注册表。

## 前置条件

- Node.js 20 或更高版本、Git、支持 gzip 的 `tar`,以及根 `package.json` 指定的精确 pnpm 版本。Windows 使用独立的 `pnpm.exe`(与 CI 一致),或能够提供 JavaScript `npm_execpath` 的 pnpm 启动器。
- 先通过评审的 PR 在四个 package manifest 中设置目标版本。脚本首版只接受稳定的 `x.y.z` 版本,目标固定为公共 npm registry 和 `latest` tag。CLI 内嵌 schema,因此两者版本必须一致;API 和 create wrapper 可以使用不同版本,但每次均核对四个包。
- 正式发布要求干净的 `main`,包括没有未跟踪文件,且 HEAD 与当前 `origin/main` 完全一致。运行期间保持源码和产物不变。需要能访问 GitHub 和 npm,并使用有权发布这些包的 npm 账号。登录和 OTP 交互由 pnpm 处理;脚本不读取或保存凭据。

## 仅准备,不发布

在 SDK 仓库根目录执行:

```bash
pnpm run release
# 显式等价命令:
pnpm run release -- --dry-run
```

准备模式允许功能分支、CI detached checkout 和本地修改。报告记录源码提交及工作树是否有修改;带修改的准备结果可以用于开发验证,但不能作为发布授权。

脚本按以下顺序执行,任一步失败立即停止:

1. 核对包身份、稳定版本、发布配置、schema/CLI 版本配对及固定 pnpm 版本。
2. 执行 `pnpm install --frozen-lockfile`。
3. 执行 `pnpm run lint` 和 `pnpm run check:facade`。
4. 依次执行 `pnpm run build`、`pnpm run typecheck`、`pnpm run test`。
5. 使用 pnpm 打包四个包,并检查实际 tarball。

四个包全部打包完成后才会考虑上传。归档检查覆盖包身份、必需入口和文件、workspace 依赖重写。发布依赖中不能残留 `workspace:`、`link:` 或 `file:`;CLI 必须内嵌 SDK 代码,不能残留运行时 `@motrix/` 依赖。

每次运行都会创建新的 ignored 目录 `dist/release/sdk-*/`,包含四个 `.tgz` 和 `release.json`。报告记录 Git 状态、pnpm 版本、包版本、大小、SHA-256、npm SHA-512 integrity、进度和失败信息。历史运行目录保留,便于排查。准备模式不查询 npm 发布元数据,也不上传;安装锁定的构建依赖仍可能访问包 registry。

## 人工发布

版本和工具 PR 合并后,在干净且已同步的 `main` 上,由维护者本人执行:

```bash
pnpm run release -- --publish
```

该命令会重新完成整个准备流程。发布模式会在运行流程前拒绝 CI 和非交互式终端,没有 `--yes`、`--force` 或跳过校验选项。

上传前先核对 npm 上四个精确版本。404 表示尚未发布;认证、限流、网络或其他 registry 错误都会使流程停止。仅当已有版本的 SHA-512 integrity 与本次归档一致时才会跳过。任一版本冲突都会在首次上传前阻止整个批次。

终端会展示包版本、integrity、目标 registry,以及哪些包待发布、哪些包已存在。必须准确输入 `publish SDK packages to npm` 才能授权待发布项。拒绝确认不会上传。如果整个批次都已发布且摘要一致,则直接结束,不要求确认,也不重复上传。

发布顺序固定为:

```text
@motrix/plugin-manifest-schema
@motrix/plugin-api
@motrix/plugin-cli
create-motrix-plugin
```

确认后及每次上传前,脚本都会重新核对 Git 状态和归档摘要。发布时向 pnpm 传入已验证 tarball、明确的公共 registry、public access 和 `latest` tag,保留 Git 检查及交互式 OTP 支持。每个包必须在 npm 上可查询且摘要一致,才会继续下一个。元数据缺失时最多查询 15 次,间隔两秒;单次 HTTP 请求超时为 15 秒。其他 registry 错误立即停止。

## 失败与部分发布恢复

四个 npm 包的发布不具备原子性。上传或发布后校验失败时,后续包不再尝试,不自动撤销已发布包,也不自动重试上传。请保留运行目录,检查 `release.json` 和 npm 实际状态。报告中的 `publishing` 属于不确定状态:即使客户端失败或元数据尚不可见,服务端也可能已接收包。

解决原因后,使用同一份经过评审的源码和固定构建工具重新运行。脚本重新构建并核对已发布包的精确 integrity;完全一致的包会跳过,只对缺少的包请求确认并上传。不会覆盖不可变版本。如果重建结果与已发布版本不同,应停止并查明原因,不能强制上传或静默忽略冲突。需要调整版本时,提交新的评审 PR,并保持 schema/CLI 版本一致。

在整个 SDK 批次核验完成前,消费者仍保持阻塞。完成后再更新 Motrix 和官方插件的依赖及锁文件,并复跑干净 CI。SDK 发布不代表兼容的宿主或插件也已发布,二者仍需独立核验。

## 测试与 CI

`pnpm test` 会运行发布脚本的 Node 测试及原有 SDK 测试。发布测试注入命令和 registry 替身,不向 npm 上传,覆盖顺序、检查失败、归档验证、版本冲突、确认、产物变化、部分发布及上传结果不确定等情况。CI 还会在各操作系统与 Node 组合上运行真实的默认准备命令,没有任何 workflow 会自动发布包。
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"scripts": {
"build": "pnpm -r build",
"typecheck": "pnpm -r typecheck",
"test": "pnpm -r test",
"test": "node --test scripts/release.test.mjs && pnpm -r test",
"lint": "biome check .",
"check:facade": "node scripts/check-facade.mjs"
"check:facade": "node scripts/check-facade.mjs",
"release": "node scripts/release.mjs"
},
"devDependencies": {
"@biomejs/biome": "^2.5.11"
Expand Down
Loading
Loading