forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease-check.ts
More file actions
executable file
·362 lines (326 loc) · 11.5 KB
/
Copy pathrelease-check.ts
File metadata and controls
executable file
·362 lines (326 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#!/usr/bin/env -S node --import tsx
import { execSync } from "node:child_process";
import { readdirSync, readFileSync } from "node:fs";
import { join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
import { sparkleBuildFloorsFromShortVersion, type SparkleBuildFloors } from "./sparkle-build.ts";
type PackFile = { path: string };
type PackResult = { files?: PackFile[] };
const requiredPathGroups = [
["dist/index.js", "dist/index.mjs"],
["dist/entry.js", "dist/entry.mjs"],
"dist/plugin-sdk/index.js",
"dist/plugin-sdk/index.d.ts",
"dist/plugin-sdk/core.js",
"dist/plugin-sdk/core.d.ts",
"dist/plugin-sdk/root-alias.cjs",
"dist/plugin-sdk/compat.js",
"dist/plugin-sdk/compat.d.ts",
"dist/plugin-sdk/telegram.js",
"dist/plugin-sdk/telegram.d.ts",
"dist/plugin-sdk/discord.js",
"dist/plugin-sdk/discord.d.ts",
"dist/plugin-sdk/slack.js",
"dist/plugin-sdk/slack.d.ts",
"dist/plugin-sdk/signal.js",
"dist/plugin-sdk/signal.d.ts",
"dist/plugin-sdk/imessage.js",
"dist/plugin-sdk/imessage.d.ts",
"dist/plugin-sdk/whatsapp.js",
"dist/plugin-sdk/whatsapp.d.ts",
"dist/plugin-sdk/line.js",
"dist/plugin-sdk/line.d.ts",
"dist/plugin-sdk/msteams.js",
"dist/plugin-sdk/msteams.d.ts",
"dist/plugin-sdk/acpx.js",
"dist/plugin-sdk/acpx.d.ts",
"dist/plugin-sdk/bluebubbles.js",
"dist/plugin-sdk/bluebubbles.d.ts",
"dist/plugin-sdk/copilot-proxy.js",
"dist/plugin-sdk/copilot-proxy.d.ts",
"dist/plugin-sdk/device-pair.js",
"dist/plugin-sdk/device-pair.d.ts",
"dist/plugin-sdk/diagnostics-otel.js",
"dist/plugin-sdk/diagnostics-otel.d.ts",
"dist/plugin-sdk/diffs.js",
"dist/plugin-sdk/diffs.d.ts",
"dist/plugin-sdk/feishu.js",
"dist/plugin-sdk/feishu.d.ts",
"dist/plugin-sdk/google-gemini-cli-auth.js",
"dist/plugin-sdk/google-gemini-cli-auth.d.ts",
"dist/plugin-sdk/googlechat.js",
"dist/plugin-sdk/googlechat.d.ts",
"dist/plugin-sdk/irc.js",
"dist/plugin-sdk/irc.d.ts",
"dist/plugin-sdk/llm-task.js",
"dist/plugin-sdk/llm-task.d.ts",
"dist/plugin-sdk/lobster.js",
"dist/plugin-sdk/lobster.d.ts",
"dist/plugin-sdk/matrix.js",
"dist/plugin-sdk/matrix.d.ts",
"dist/plugin-sdk/mattermost.js",
"dist/plugin-sdk/mattermost.d.ts",
"dist/plugin-sdk/memory-core.js",
"dist/plugin-sdk/memory-core.d.ts",
"dist/plugin-sdk/memory-lancedb.js",
"dist/plugin-sdk/memory-lancedb.d.ts",
"dist/plugin-sdk/minimax-portal-auth.js",
"dist/plugin-sdk/minimax-portal-auth.d.ts",
"dist/plugin-sdk/nextcloud-talk.js",
"dist/plugin-sdk/nextcloud-talk.d.ts",
"dist/plugin-sdk/nostr.js",
"dist/plugin-sdk/nostr.d.ts",
"dist/plugin-sdk/open-prose.js",
"dist/plugin-sdk/open-prose.d.ts",
"dist/plugin-sdk/phone-control.js",
"dist/plugin-sdk/phone-control.d.ts",
"dist/plugin-sdk/qwen-portal-auth.js",
"dist/plugin-sdk/qwen-portal-auth.d.ts",
"dist/plugin-sdk/synology-chat.js",
"dist/plugin-sdk/synology-chat.d.ts",
"dist/plugin-sdk/talk-voice.js",
"dist/plugin-sdk/talk-voice.d.ts",
"dist/plugin-sdk/test-utils.js",
"dist/plugin-sdk/test-utils.d.ts",
"dist/plugin-sdk/thread-ownership.js",
"dist/plugin-sdk/thread-ownership.d.ts",
"dist/plugin-sdk/tlon.js",
"dist/plugin-sdk/tlon.d.ts",
"dist/plugin-sdk/twitch.js",
"dist/plugin-sdk/twitch.d.ts",
"dist/plugin-sdk/voice-call.js",
"dist/plugin-sdk/voice-call.d.ts",
"dist/plugin-sdk/zalo.js",
"dist/plugin-sdk/zalo.d.ts",
"dist/plugin-sdk/zalouser.js",
"dist/plugin-sdk/zalouser.d.ts",
"dist/plugin-sdk/account-id.js",
"dist/plugin-sdk/account-id.d.ts",
"dist/plugin-sdk/keyed-async-queue.js",
"dist/plugin-sdk/keyed-async-queue.d.ts",
"dist/build-info.json",
];
const forbiddenPrefixes = ["dist/OpenClaw.app/"];
const appcastPath = resolve("appcast.xml");
const laneBuildMin = 1_000_000_000;
const laneFloorAdoptionDateKey = 20260227;
type PackageJson = {
name?: string;
version?: string;
};
function normalizePluginSyncVersion(version: string): string {
const normalized = version.trim().replace(/^v/, "");
const base = /^([0-9]+\.[0-9]+\.[0-9]+)/.exec(normalized)?.[1];
if (base) {
return base;
}
return normalized.replace(/[-+].*$/, "");
}
function runPackDry(): PackResult[] {
const raw = execSync("npm pack --dry-run --json --ignore-scripts", {
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
maxBuffer: 1024 * 1024 * 100,
});
return JSON.parse(raw) as PackResult[];
}
function checkPluginVersions() {
const rootPackagePath = resolve("package.json");
const rootPackage = JSON.parse(readFileSync(rootPackagePath, "utf8")) as PackageJson;
const targetVersion = rootPackage.version;
const targetBaseVersion = targetVersion ? normalizePluginSyncVersion(targetVersion) : null;
if (!targetVersion || !targetBaseVersion) {
console.error("release-check: root package.json missing version.");
process.exit(1);
}
const extensionsDir = resolve("extensions");
const entries = readdirSync(extensionsDir, { withFileTypes: true }).filter((entry) =>
entry.isDirectory(),
);
const mismatches: string[] = [];
for (const entry of entries) {
const packagePath = join(extensionsDir, entry.name, "package.json");
let pkg: PackageJson;
try {
pkg = JSON.parse(readFileSync(packagePath, "utf8")) as PackageJson;
} catch {
continue;
}
if (!pkg.name || !pkg.version) {
continue;
}
if (normalizePluginSyncVersion(pkg.version) !== targetBaseVersion) {
mismatches.push(`${pkg.name} (${pkg.version})`);
}
}
if (mismatches.length > 0) {
console.error(
`release-check: plugin versions must match release base ${targetBaseVersion} (root ${targetVersion}):`,
);
for (const item of mismatches) {
console.error(` - ${item}`);
}
console.error("release-check: run `pnpm plugins:sync` to align plugin versions.");
process.exit(1);
}
}
function extractTag(item: string, tag: string): string | null {
const escapedTag = tag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const regex = new RegExp(`<${escapedTag}>([^<]+)</${escapedTag}>`);
return regex.exec(item)?.[1]?.trim() ?? null;
}
export function collectAppcastSparkleVersionErrors(xml: string): string[] {
const itemMatches = [...xml.matchAll(/<item>([\s\S]*?)<\/item>/g)];
const errors: string[] = [];
const calverItems: Array<{ title: string; sparkleBuild: number; floors: SparkleBuildFloors }> =
[];
if (itemMatches.length === 0) {
errors.push("appcast.xml contains no <item> entries.");
}
for (const [, item] of itemMatches) {
const title = extractTag(item, "title") ?? "unknown";
const shortVersion = extractTag(item, "sparkle:shortVersionString");
const sparkleVersion = extractTag(item, "sparkle:version");
if (!sparkleVersion) {
errors.push(`appcast item '${title}' is missing sparkle:version.`);
continue;
}
if (!/^[0-9]+$/.test(sparkleVersion)) {
errors.push(`appcast item '${title}' has non-numeric sparkle:version '${sparkleVersion}'.`);
continue;
}
if (!shortVersion) {
continue;
}
const floors = sparkleBuildFloorsFromShortVersion(shortVersion);
if (floors === null) {
continue;
}
calverItems.push({ title, sparkleBuild: Number(sparkleVersion), floors });
}
const observedLaneAdoptionDateKey = calverItems
.filter((item) => item.sparkleBuild >= laneBuildMin)
.map((item) => item.floors.dateKey)
.toSorted((a, b) => a - b)[0];
const effectiveLaneAdoptionDateKey =
typeof observedLaneAdoptionDateKey === "number"
? Math.min(observedLaneAdoptionDateKey, laneFloorAdoptionDateKey)
: laneFloorAdoptionDateKey;
for (const item of calverItems) {
const expectLaneFloor =
item.sparkleBuild >= laneBuildMin || item.floors.dateKey >= effectiveLaneAdoptionDateKey;
const floor = expectLaneFloor ? item.floors.laneFloor : item.floors.legacyFloor;
if (item.sparkleBuild < floor) {
const floorLabel = expectLaneFloor ? "lane floor" : "legacy floor";
errors.push(
`appcast item '${item.title}' has sparkle:version ${item.sparkleBuild} below ${floorLabel} ${floor}.`,
);
}
}
return errors;
}
function checkAppcastSparkleVersions() {
const xml = readFileSync(appcastPath, "utf8");
const errors = collectAppcastSparkleVersionErrors(xml);
if (errors.length > 0) {
console.error("release-check: appcast sparkle version validation failed:");
for (const error of errors) {
console.error(` - ${error}`);
}
process.exit(1);
}
}
// Critical functions that channel extension plugins import from openclaw/plugin-sdk.
// If any are missing from the compiled output, plugins crash at runtime (#27569).
const requiredPluginSdkExports = [
"isDangerousNameMatchingEnabled",
"createAccountListHelpers",
"buildAgentMediaPayload",
"createReplyPrefixOptions",
"createTypingCallbacks",
"logInboundDrop",
"logTypingFailure",
"buildPendingHistoryContextFromMap",
"clearHistoryEntriesIfEnabled",
"recordPendingHistoryEntryIfEnabled",
"resolveControlCommandGate",
"resolveDmGroupAccessWithLists",
"resolveAllowlistProviderRuntimeGroupPolicy",
"resolveDefaultGroupPolicy",
"resolveChannelMediaMaxBytes",
"warnMissingProviderGroupPolicyFallbackOnce",
"emptyPluginConfigSchema",
"normalizePluginHttpPath",
"registerPluginHttpRoute",
"DEFAULT_ACCOUNT_ID",
"DEFAULT_GROUP_HISTORY_LIMIT",
];
function checkPluginSdkExports() {
const distPath = resolve("dist", "plugin-sdk", "index.js");
let content: string;
try {
content = readFileSync(distPath, "utf8");
} catch {
console.error("release-check: dist/plugin-sdk/index.js not found (build missing?).");
process.exit(1);
return;
}
const exportMatch = content.match(/export\s*\{([^}]+)\}\s*;?\s*$/);
if (!exportMatch) {
console.error("release-check: could not find export statement in dist/plugin-sdk/index.js.");
process.exit(1);
return;
}
const exportedNames = new Set(
exportMatch[1].split(",").map((s) => {
const parts = s.trim().split(/\s+as\s+/);
return (parts[parts.length - 1] || "").trim();
}),
);
const missingExports = requiredPluginSdkExports.filter((name) => !exportedNames.has(name));
if (missingExports.length > 0) {
console.error("release-check: missing critical plugin-sdk exports (#27569):");
for (const name of missingExports) {
console.error(` - ${name}`);
}
process.exit(1);
}
}
function main() {
checkPluginVersions();
checkAppcastSparkleVersions();
checkPluginSdkExports();
const results = runPackDry();
const files = results.flatMap((entry) => entry.files ?? []);
const paths = new Set(files.map((file) => file.path));
const missing = requiredPathGroups
.flatMap((group) => {
if (Array.isArray(group)) {
return group.some((path) => paths.has(path)) ? [] : [group.join(" or ")];
}
return paths.has(group) ? [] : [group];
})
.toSorted();
const forbidden = [...paths].filter((path) =>
forbiddenPrefixes.some((prefix) => path.startsWith(prefix)),
);
if (missing.length > 0 || forbidden.length > 0) {
if (missing.length > 0) {
console.error("release-check: missing files in npm pack:");
for (const path of missing) {
console.error(` - ${path}`);
}
}
if (forbidden.length > 0) {
console.error("release-check: forbidden files in npm pack:");
for (const path of forbidden) {
console.error(` - ${path}`);
}
}
process.exit(1);
}
console.log("release-check: npm pack contents look OK.");
}
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
main();
}