chore: 按用途整理工程脚本与验证入口
将内部脚本归入 build、release、generate、dev 和 checks,保留公开安装脚本路径。 同步命令、CI、发布流程、脚本间调用及根目录定位,补齐脚本说明与完成报告。 验证:929 项测试、类型与版本检查通过;二进制及插件构建、冒烟与打包通过。 OpenAPI 产物不变;工作流 Schema 导出存在基线即可复现的 Zod transform 错误,单独记录。
This commit is contained in:
1 parent
b1e9c7eed3
commit
c71b20c25b
24 files changed
+133
-44
No files matched your search
@@ -0,0 +1,49 @@
|
||||
# 工程脚本(scripts)
|
||||
|
||||
本目录维护构建、发布校验、规范生成与本地开发维护脚本。优先从仓库根目录运行 `package.json` 中的命令;迁移子目录不改变这些命令、参数与产物位置。
|
||||
|
||||
## 目录职责
|
||||
|
||||
| 位置 | 职责与文件 |
|
||||
|---|---|
|
||||
| [build/](./build/) | 二进制、MCP bundle、插件归档构建,产物验证及插件冒烟测试 |
|
||||
| [release/](./release/) | 版本更新、一致性检查、发布 Tag 校验及发布流程测试 |
|
||||
| [generate/](./generate/) | 包装层 OpenAPI 打包、原生下游规范生成、工作流 Schema 导出 |
|
||||
| [dev/](./dev/) | 本地开发安装覆盖、环境检查与清理规划,及对应测试 |
|
||||
| [checks/](./checks/) | 文档等仓库级检查;目前为 SDK README 示例编译测试 |
|
||||
| [install.sh](./install.sh) | 公开安装入口,路径保持稳定;安装测试保留在同级 |
|
||||
|
||||
对应脚本的测试与脚本放在同一个目录,统一由 `bun test` 发现。生成文件写入 `specs/`,构建输出写入 Git 忽略的 `dist/`。
|
||||
|
||||
## 常用入口与副作用
|
||||
|
||||
| 命令 | 实现 | 行为 |
|
||||
|---|---|---|
|
||||
| `bun run build:binary` | [build-binary.mjs](./build/build-binary.mjs) | 编译当前平台二进制到 `dist/bin/`;支持 `--target=...`、`--all`、`--release` |
|
||||
| `bun run build:plugin` | [build-plugin.mjs](./build/build-plugin.mjs) | 生成 `dist/mcp/server.js`;支持 `--outfile=...` |
|
||||
| `bun run package:plugin` | [package-plugin.mjs](./build/package-plugin.mjs) | 从当前源码重建插件并生成 `dist/bin/hose-use-plugin-v*.tar.gz`;支持 `--out-dir=...` |
|
||||
| `bun run scripts/build/verify-binary.ts <产物>` | [verify-binary.ts](./build/verify-binary.ts) | 在临时目录验证 CLI/MCP;插件产物加 `--plugin` |
|
||||
| `bun run check:version` | [check-version-sync.ts](./release/check-version-sync.ts) | 只读检查版本一致性 |
|
||||
| `bun run bump <版本>` | [bump-version.ts](./release/bump-version.ts) | 要求干净的指定发布分支;修改版本源文件并重建规范与插件;`sync:release` 为同一入口 |
|
||||
| `bun run scripts/release/verify-release.ts <Tag>` | [verify-release.ts](./release/verify-release.ts) | 只读验证发布 Tag、当前提交、主分支祖先关系与版本 |
|
||||
| `bun run openapi:bundle` | [bundle-openapi.ts](./generate/bundle-openapi.ts) | `specs/hose-open-api/` YAML → `specs/openapi.json` |
|
||||
| `bun run openapi:generate-raw` | [generate-raw-openapi.ts](./generate/generate-raw-openapi.ts) | 生成 `specs/openapi.raw.json`;`openapi:all` 依次生成两份规范 |
|
||||
| `bun run export:workflow-schema` | [export-workflow-schema.ts](./generate/export-workflow-schema.ts) | 从 Zod 导出 `specs/workflow-schema.json` |
|
||||
| `bun run dev:status` / `dev:check` | [dev-hygiene.ts](./dev/dev-hygiene.ts) | 检查开发环境、安装与技能同步状态 |
|
||||
| `bun run dev:clean` | [dev-hygiene.ts](./dev/dev-hygiene.ts) | 默认给出清理计划;执行清理前检查参数与计划 |
|
||||
| `bun run dev:override` | [dev-override.ts](./dev/dev-override.ts) | 构建并覆盖本机全局命令,同步个人 `~/.agents/skills/hose-use`;`dev:link` 为同一入口 |
|
||||
| `bash scripts/install.sh` | [install.sh](./install.sh) | 下载并校验发布产物,安装到本机并安装产品技能 |
|
||||
|
||||
发布规则见根目录 [AGENTS.md](../AGENTS.md)。构建、升级版本和安装是不同步骤,发布 Tag 与推送由发布流程单独执行。
|
||||
|
||||
## 维护与验证
|
||||
|
||||
- 移动脚本时同步检查 `package.json`、`.github/workflows/`、脚本间调用与文档引用。
|
||||
- 子目录内脚本以自身路径定位仓库根目录时,需要上溯两级;规范生成入口沿用从仓库根目录执行的约定。
|
||||
- `scripts/install.sh` 被公开安装 URL 引用,不随内部脚本分组迁移。
|
||||
- 不在本目录保存业务工作流脚本、客户载荷或临时生成文件;产品 Skill 中的 `./scripts/*.mvel` 等是调用者工作目录示例。
|
||||
- 提交前执行 `bun test`、`bun run check`、`bun run check:version`;构建相关调整还需验证二进制和插件的实际产物。
|
||||
|
||||
## 已知限制
|
||||
|
||||
`export:workflow-schema` 当前会因业务 Zod Schema 包含 transform 而报 `Transforms cannot be represented in JSON Schema`。目录迁移前的脚本也能复现;本轮保留导出逻辑和既有生成文件,后续需明确导出输入或输出结构后单独修复。
|
||||
@@ -3,7 +3,7 @@ import { spawnSync } from "node:child_process";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
const bun = process.env.BUN_BIN || "bun";
|
||||
|
||||
const TARGET_MAP = {
|
||||
@@ -3,7 +3,7 @@ import { spawnSync } from "node:child_process";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
const bun = process.env.BUN_BIN || "bun";
|
||||
const args = process.argv.slice(2);
|
||||
if (args.some(arg => !arg.startsWith("--outfile="))) {
|
||||
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
const args = process.argv.slice(2);
|
||||
if (args.some(arg => !arg.startsWith("--out-dir="))) {
|
||||
throw new Error("Usage: package-plugin.mjs [--out-dir=<path>]");
|
||||
@@ -26,7 +26,7 @@ try {
|
||||
cpSync(join(root, path), join(stage, path), { recursive: true });
|
||||
}
|
||||
// Always build from current source; never package a stale local dist/ bundle.
|
||||
run(process.execPath, [join(root, "scripts/build-plugin.mjs"), `--outfile=${join(stage, "dist/mcp/server.js")}`]);
|
||||
run(process.execPath, [join(root, "scripts/build/build-plugin.mjs"), `--outfile=${join(stage, "dist/mcp/server.js")}`]);
|
||||
mkdirSync(outputDir, { recursive: true });
|
||||
run("tar", ["-czf", archive, "-C", stage, ".zcode-plugin", ".mcp.json", "skills", "dist"]);
|
||||
console.log(`✓ Packaged plugin: ${archive}`);
|
||||
@@ -4,11 +4,11 @@ import { tmpdir } from "node:os";
|
||||
import { join, resolve } from "node:path";
|
||||
|
||||
test("source and freshly packaged plugin preserve offline review and MCP contracts without a prebuilt dist", () => {
|
||||
const root = resolve(import.meta.dir, "..");
|
||||
const root = resolve(import.meta.dir, "../..");
|
||||
const temp = mkdtempSync(join(tmpdir(), "hose review plugin "));
|
||||
try {
|
||||
const packaged = Bun.spawnSync([
|
||||
process.execPath, join(root, "scripts/package-plugin.mjs"), `--out-dir=${join(temp, "artifacts")}`,
|
||||
process.execPath, join(root, "scripts/build/package-plugin.mjs"), `--out-dir=${join(temp, "artifacts")}`,
|
||||
], { cwd: temp, env: { ...process.env, BUN_BIN: process.execPath }, timeout: 30_000 });
|
||||
expect(packaged.exitCode, packaged.stderr.toString()).toBe(0);
|
||||
const version = JSON.parse(readFileSync(join(root, "package.json"), "utf8")).version;
|
||||
@@ -29,7 +29,7 @@ test("source and freshly packaged plugin preserve offline review and MCP contrac
|
||||
expect(existsSync(join(pluginRoot, "skills", file))).toBe(true);
|
||||
}
|
||||
const protocol = Bun.spawnSync([
|
||||
process.execPath, join(root, "scripts/verify-binary.ts"), bundle, "--plugin",
|
||||
process.execPath, join(root, "scripts/build/verify-binary.ts"), bundle, "--plugin",
|
||||
], { cwd: temp, timeout: 30_000 });
|
||||
expect(protocol.exitCode, protocol.stderr.toString()).toBe(0);
|
||||
const enterprises = join(temp, "enterprises");
|
||||
File renamed without changes.
@@ -4,7 +4,7 @@ import { resolve } from "node:path";
|
||||
import ts from "typescript";
|
||||
|
||||
test("DataLink 公共 SDK 的 README 示例与实际导出一同编译", () => {
|
||||
const root = resolve(import.meta.dir, "..");
|
||||
const root = resolve(import.meta.dir, "../..");
|
||||
const readme = readFileSync(resolve(root, "src/domains/datalink/README.datalink.md"), "utf8");
|
||||
const code = readme.split("## 公共 SDK")[1]?.match(/```typescript\n([\s\S]*?)\n```/)?.[1];
|
||||
expect(code).toBeDefined();
|
||||
File renamed without changes.
@@ -7,7 +7,7 @@ import { homedir } from "node:os";
|
||||
import { dirname, join, relative, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
const PACKAGE = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8")) as { version: string };
|
||||
const CANONICAL_SKILL_DIR = join(homedir(), ".agents", "skills", "hose-use");
|
||||
const NON_CANONICAL_SKILL_DIRS = [
|
||||
File renamed without changes.
@@ -6,7 +6,7 @@ import { homedir } from "node:os";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
|
||||
export interface DevOverrideOptions {
|
||||
dryRun: boolean;
|
||||
@@ -50,7 +50,7 @@ export function resolveTargetBinaryPath(commandName = "hose-use"): string {
|
||||
}
|
||||
|
||||
function runBuild(): string {
|
||||
const result = spawnSync("node", ["scripts/build-binary.mjs"], {
|
||||
const result = spawnSync("node", ["scripts/build/build-binary.mjs"], {
|
||||
cwd: ROOT,
|
||||
stdio: ["ignore", "inherit", "inherit"],
|
||||
});
|
||||
File renamed without changes.
@@ -4,7 +4,7 @@ import {
|
||||
WorkflowDetailSchema,
|
||||
WorkflowTaskSchema,
|
||||
WorkflowSchema,
|
||||
} from "../src/domains/platform/types.js";
|
||||
} from "../../src/domains/platform/types.js";
|
||||
|
||||
const OUTPUT_DIR = join(process.cwd(), "specs");
|
||||
const OUTPUT_FILE = join(OUTPUT_DIR, "workflow-schema.json");
|
||||
File renamed without changes.
@@ -113,7 +113,7 @@ export function isReleaseVersion(value: string): boolean {
|
||||
|
||||
if (import.meta.main) {
|
||||
try {
|
||||
bumpVersion(join(import.meta.dirname, ".."), process.argv[2]?.trim() || "");
|
||||
bumpVersion(join(import.meta.dirname, "../.."), process.argv[2]?.trim() || "");
|
||||
} catch (error) {
|
||||
console.error(error instanceof Error ? error.message : String(error));
|
||||
process.exitCode = 1;
|
||||
@@ -2,7 +2,7 @@
|
||||
import { readFileSync, existsSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
const root = join(import.meta.dirname, "..");
|
||||
const root = join(import.meta.dirname, "../..");
|
||||
const packageVersion = (JSON.parse(readFileSync(join(root, "package.json"), "utf8")) as { version: string }).version;
|
||||
const expected: Array<[string, string | undefined]> = [
|
||||
["package.json", packageVersion],
|
||||
@@ -71,7 +71,7 @@ case "$url" in
|
||||
*) exit 22 ;;
|
||||
esac
|
||||
`, { mode: 0o755 });
|
||||
const workflow = parse(readFileSync(join(import.meta.dir, "../.github/workflows/release.yml"), "utf8"));
|
||||
const workflow = parse(readFileSync(join(import.meta.dir, "../../.github/workflows/release.yml"), "utf8"));
|
||||
const step = workflow.jobs["build-and-publish"].steps.find((s: { name?: string }) => s.name === "Publish Gitea Release");
|
||||
return { ...f, files, run: () => spawnSync("bash", ["-eo", "pipefail", "-c", step.run], { cwd: f.root, env: { ...process.env, PATH: `${tools}:${process.env.PATH}`, GITEA_TOKEN: "fixture", GITEA_RETRY_DELAY: "0", GITEA_HOST: "https://example.test", GITEA_REPO: "test/repo", RELEASE_TAG: "v1.0.0", MIRROR_ONLY: String(mirrorOnly), GITHUB_REPOSITORY: "test/repo", MIRROR_FIXTURE: f.root, MIRROR_MODE: mode }, encoding: "utf8", timeout: 30_000 }) };
|
||||
}
|
||||
@@ -124,7 +124,7 @@ describe("release preparation and publication guards", () => {
|
||||
}, 60_000);
|
||||
|
||||
test("workflows validate committed versions before generation and ship the checksum manifest", () => {
|
||||
const root = join(import.meta.dir, "..");
|
||||
const root = join(import.meta.dir, "../..");
|
||||
const ci = parse(readFileSync(join(root, ".github/workflows/ci.yml"), "utf8"));
|
||||
const release = parse(readFileSync(join(root, ".github/workflows/release.yml"), "utf8"));
|
||||
expect(ci.on.pull_request.branches).toContain("main");
|
||||
@@ -147,7 +147,7 @@ describe("release preparation and publication guards", () => {
|
||||
|
||||
test("a failed background Gitea upload makes the Release step fail", () => {
|
||||
const f = repository();
|
||||
const workflow = parse(readFileSync(join(import.meta.dir, "../.github/workflows/release.yml"), "utf8"));
|
||||
const workflow = parse(readFileSync(join(import.meta.dir, "../../.github/workflows/release.yml"), "utf8"));
|
||||
const step = workflow.jobs["build-and-publish"].steps.find((s: { name?: string }) => s.name === "Publish Gitea Release");
|
||||
mkdirSync(join(f.root, "tools")); mkdirSync(join(f.root, "dist/bin"), { recursive: true });
|
||||
writeFileSync(join(f.root, "dist/bin/hose-use-linux-x64"), "fixture");
|
||||
@@ -19,6 +19,6 @@ export function verifyReleaseTag(root: string, tag: string): void {
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
verifyReleaseTag(resolve(import.meta.dir, ".."), process.argv[2] || "");
|
||||
verifyReleaseTag(resolve(import.meta.dir, "../.."), process.argv[2] || "");
|
||||
console.log("Release tag, HEAD, main ancestry and package version verified.");
|
||||
}
|
||||
Reference in new issue
Block a user