From a0e4c344c0e26a468852c80678dc2e481ceb2e2c Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Sun, 29 Nov 2026 17:09:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(store):=20=E4=B8=80=E4=B8=AA=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=8F=91=E5=B8=83=E5=A4=9A=E4=B8=AA=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=E6=8C=89=E6=A0=87=E7=AD=BE=E5=89=8D=E7=BC=80=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E5=92=8C=E8=BF=BD=E8=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - validate-index:每个条目的 Release 标签必须是同一个前缀加上列出它的版本号, 同一个仓库(不区分大小写)的条目前缀互不相同 - track-releases:只认领带自己前缀的 Release,兄弟插件的 Release 直接忽略、不下载; 标签拆不出版本号或前缀不同时跳过并说明原因;每页读 100 个 Release - 文档:发布指南补标签约定和“一个仓库发布多个插件”,维护者审查清单补对应策略 --- docs/maintainers.md | 3 +- docs/publishing.md | 23 ++++- scripts/store.test.mjs | 168 +++++++++++++++++++++++++++++++++---- scripts/track-releases.mjs | 47 +++++++++-- scripts/validate-index.mjs | 62 +++++++++++++- 5 files changed, 278 insertions(+), 25 deletions(-) diff --git a/docs/maintainers.md b/docs/maintainers.md index 9476d3b..cb86c7e 100644 --- a/docs/maintainers.md +++ b/docs/maintainers.md @@ -4,7 +4,8 @@ CI(`Validate index`)已经自动保证: -- 索引符合 Lithe 插件契约 v0 与本仓库策略(按 `id` 排序、无重复 ID、无 `dev.lithe.*`); +- 索引符合 Lithe 插件契约 v0 与本仓库策略(按 `id` 排序、无重复 ID、无 `dev.lithe.*`;每个条目的 Release 标签都是同一个前缀加上版本号, + 同一个仓库的条目前缀互不相同,见[一个仓库发布多个插件](publishing.md#一个仓库发布多个插件)); - 每个新增或变更的下载包可下载、SHA-256 一致; - 包内恰好一个匹配的 `plugin.json`,`schemaVersion` 与 `pluginAPIVersion` 为 `0`, `version`、`pluginAPIVersion`、`requires` 与索引一致, diff --git a/docs/publishing.md b/docs/publishing.md index 1c1a506..c39be27 100644 --- a/docs/publishing.md +++ b/docs/publishing.md @@ -69,6 +69,24 @@ Release 资产名必须以平台结尾,自动追踪才能识别: 索引只接受 `https://github.com/<你的仓库>/releases/download//<资产>.zip`, 不能指向其他仓库、源码压缩包或其他网站。 +Release 标签必须是 `<前缀>MAJOR.MINOR.PATCH`,结尾的版本号与包内 `plugin.json` 的 `version` 相同: + +- 前缀可以为空(标签就是 `2.0.0`),常用的是 `v`(`v2.0.0`)。 +- 前缀不能以数字或 `.` 结尾,这样每个标签只有一种拆法。 +- 同一个插件的所有版本使用同一个前缀。 + +Lithe 按这个前缀筛选插件的更新日志,自动追踪按它认领新版本。标签不符合约定的 Release 不会被收录。 + +### 一个仓库发布多个插件 + +一个仓库可以发布多个插件,每个插件使用自己的标签前缀,例如同一个仓库里的 +`codex-v0.0.1` 和 `claude-code-v0.0.1`。同一个仓库的条目(仓库地址不区分大小写)不能使用相同的前缀, +否则校验失败。 + +- 第二个及以后的插件按下面的“其他仓库”步骤提 PR 首次收录:自动首次收录只看还没有条目的仓库。 +- 收录后,自动追踪只认领带自己前缀的 Release,其他插件的 Release 直接忽略,不会下载,也不会报错。 +- Lithe 的更新日志和“已安装”标记只显示这个插件自己的 Release。 + > Release 发布后**不要替换或删除资产**。索引固定了 SHA-256,替换后用户会安装失败, > 每周的校验也会把它标记为损坏。需要修复就发一个新的补丁版本。 @@ -164,7 +182,7 @@ pre-release 的仓库不会被收录。 收录后,新版本**不需要你再提 PR**: 1. 在你的仓库递增 `plugin.json` 的 `version`,打包,发布新的正式 Release(资产命名同上)。 -2. `Track plugin releases` 工作流每 6 小时扫描一次已收录插件最近 20 个 Release +2. `Track plugin releases` 工作流每 6 小时扫描一次已收录插件最近 100 个 Release (Lithe-IDEA 组织尚未收录的 `lithe-plugin-*` 仓库也一起扫描,见 [首次收录](#3-首次收录)), 把新版本写进索引(版本号、`pluginAPIVersion`、`requires` 取自包内 `plugin.json`, 能力表按键排序写入;发布日期取 Release 发布时间,SHA-256 由 CI 计算), @@ -185,7 +203,8 @@ pre-release 的仓库不会被收录。 还没收录的 Lithe-IDEA 组织插件会在这时被自动首次收录。调试适配器插件的写法见 [编写调试适配器插件](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/guides/debug-adapter-plugin.md)。 -自动追踪会在日志中说明归档无法收录的原因:没有符合命名的 zip、包内 `plugin.json` +自动追踪会在日志中说明归档无法收录的原因:标签不是 `<前缀>MAJOR.MINOR.PATCH`、 +标签前缀与已收录版本不同、没有符合命名的 zip、包内 `plugin.json` 不匹配或缺失/畸形的能力表、多个资产声明了不同的版本号、插件 API 版本或能力表、 版本号已被别的资产占用。单个发布存在分歧时拒绝整个版本,不只保留其中一个平台包。 diff --git a/scripts/store.test.mjs b/scripts/store.test.mjs index 8f154b8..950bbca 100644 --- a/scripts/store.test.mjs +++ b/scripts/store.test.mjs @@ -7,11 +7,12 @@ import { join } from "node:path"; import { test } from "node:test"; import { END, START, categoryOf, renderOverview, renderReadme, systemsOf, truncate } from "./render-readme.mjs"; import { - addVersion, discoverPlugins, isOrganizationEntry, platformsForAsset, trackIndex, trackingBranch, unlistedPluginRepositories, - versionFromRelease, + addVersion, discoverPlugins, isOrganizationEntry, platformsForAsset, trackEntry, trackIndex, trackingBranch, + unlistedPluginRepositories, versionFromRelease, } from "./track-releases.mjs"; import { - checkManifest, formatIndex, inspectArchive, readPackageManifests, validateEntry, validateIndex, verifyArchives, + checkManifest, formatIndex, inspectArchive, readPackageManifests, releaseTagConvention, splitReleaseTag, validateEntry, + validateIndex, verifyArchives, } from "./validate-index.mjs"; import { validateRecommendations } from "./validate-recommendations.mjs"; @@ -21,6 +22,17 @@ const fixtureIndex = JSON.parse(readFileSync(new URL("./fixtures/index.json", im const invalidCases = JSON.parse(readFileSync(new URL("./fixtures/invalid-index-entries.json", import.meta.url))).cases; const validEntry = () => structuredClone(fixtureIndex.plugins[0]); +// Another plugin of the fixture's repository, released under its own tag prefix. +function siblingEntry(id, prefix) { + const entry = { ...validEntry(), id }; + for (const version of entry.versions) { + for (const download of version.downloads) { + download.downloadURL = download.downloadURL.replace(`/download/v${version.version}/`, `/download/${prefix}${version.version}/`); + } + } + return entry; +} + function applyEdits(entry, edits) { for (const { op, path, value } of edits) { const keys = path.split("/").slice(1); @@ -264,7 +276,7 @@ function zigOrganization() { [release.assets[0].browser_download_url, zigManifest(release.tag_name.slice(1))])); const fixture = organizationFixture({ [REPOSITORIES_PATH]: [repository, organizationRepository("lithe-plugin-docs")], - "repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=20": releases, + "repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=100": releases, }, manifestsByURL); return { releases, fixture }; } @@ -285,7 +297,7 @@ test("organization discovery considers only active, unlisted lithe-plugin- repos test("organization discovery lists a new plugin with its stable releases", { timeout: 5_000 }, async () => { const { releases, fixture } = zigOrganization(); - const index = { schemaVersion: 0, plugins: [validEntry(), { ...validEntry(), id: "org.example.zig-tools" }] }; + const index = { schemaVersion: 0, plugins: [validEntry(), siblingEntry("org.example.zig-tools", "tools-v")] }; const result = await discoverPlugins(index, fixture); assert.deepEqual(result.skipped, []); @@ -334,12 +346,12 @@ test("organization discovery skips repositories that cannot be listed yet", { ti const officialRelease = organizationRelease(official, "1.0.0"); const fixture = organizationFixture({ [REPOSITORIES_PATH]: [preview, unlicensed, undescribed, copy, anonymous, official], - "repos/Lithe-IDEA/lithe-plugin-preview/releases?per_page=20": [organizationRelease(preview, "0.1.0", { prerelease: true })], - "repos/Lithe-IDEA/lithe-plugin-unlicensed/releases?per_page=20": [organizationRelease(unlicensed, "1.0.0")], - "repos/Lithe-IDEA/lithe-plugin-undescribed/releases?per_page=20": [organizationRelease(undescribed, "1.0.0")], - "repos/Lithe-IDEA/lithe-plugin-copy/releases?per_page=20": [copyRelease], - "repos/Lithe-IDEA/lithe-plugin-anonymous/releases?per_page=20": [anonymousRelease], - "repos/Lithe-IDEA/lithe-plugin-official/releases?per_page=20": [officialRelease], + "repos/Lithe-IDEA/lithe-plugin-preview/releases?per_page=100": [organizationRelease(preview, "0.1.0", { prerelease: true })], + "repos/Lithe-IDEA/lithe-plugin-unlicensed/releases?per_page=100": [organizationRelease(unlicensed, "1.0.0")], + "repos/Lithe-IDEA/lithe-plugin-undescribed/releases?per_page=100": [organizationRelease(undescribed, "1.0.0")], + "repos/Lithe-IDEA/lithe-plugin-copy/releases?per_page=100": [copyRelease], + "repos/Lithe-IDEA/lithe-plugin-anonymous/releases?per_page=100": [anonymousRelease], + "repos/Lithe-IDEA/lithe-plugin-official/releases?per_page=100": [officialRelease], }, { [copyRelease.assets[0].browser_download_url]: { ...zigManifest("1.0.0"), id: "io.example.zig-support" }, [anonymousRelease.assets[0].browser_download_url]: { ...zigManifest("1.0.0"), id: "io.github.lithe-idea.anonymous", vendor: { signatureRequirement: "none" } }, @@ -386,8 +398,8 @@ function scopedTracking() { const index = { schemaVersion: 0, plugins: [validEntry(), organizationEntry] }; const fixture = organizationFixture({ [REPOSITORIES_PATH]: [zigRepository], - "repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=20": [organizationPluginRelease], - "repos/example/lithe-zig/releases?per_page=20": [externalRelease], + "repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=100": [organizationPluginRelease], + "repos/example/lithe-zig/releases?per_page=100": [externalRelease], }, { [organizationPluginRelease.assets[0].browser_download_url]: zigManifest("1.1.0"), [externalRelease.assets[0].browser_download_url]: { ...zigManifest("9.0.0"), id: "io.example.zig-support" }, @@ -421,7 +433,7 @@ test("scoped tracking separates organization plugins from external plugins", { t const organizationRun = await trackIndex(organization.index, { ...organization.archiveIO, scope: "organization" }); assert.deepEqual(organizationRun.skipped, []); assert.deepEqual(organizationRun.added, [`${ZIG_ID}@1.1.0 (v1.1.0)`]); - assert.deepEqual(organization.requests, ["repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=20", REPOSITORIES_PATH]); + assert.deepEqual(organization.requests, ["repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=100", REPOSITORIES_PATH]); const external = scopedTracking(); const externalRun = await trackIndex(external.index, { ...external.archiveIO, scope: "external" }); @@ -429,13 +441,101 @@ test("scoped tracking separates organization plugins from external plugins", { t assert.deepEqual(externalRun.added, ["io.example.zig-support@9.0.0 (v9.0.0)"]); assert.deepEqual(externalRun.newPlugins, []); // The external pass never scans the organization, so it cannot list a plugin for the first time. - assert.deepEqual(external.requests, ["repos/example/lithe-zig/releases?per_page=20"]); + assert.deepEqual(external.requests, ["repos/example/lithe-zig/releases?per_page=100"]); const unscoped = scopedTracking(); const unscopedRun = await trackIndex(unscoped.index, unscoped.archiveIO); assert.deepEqual(unscopedRun.added, ["io.example.zig-support@9.0.0 (v9.0.0)", `${ZIG_ID}@1.1.0 (v1.1.0)`]); }); +// Two plugins published from one repository, each under its own tag prefix. +const SHARED_REPOSITORY = "https://github.com/Lithe-IDEA/lithe-ai-plugins"; +const CODEX_ID = "io.github.lithe-idea.codex"; +const CLAUDE_CODE_ID = "io.github.lithe-idea.claude-code"; + +function sharedRelease(prefix, name, version) { + const asset = `${name}-${version}-darwin.zip`; + return { + tag_name: `${prefix}${version}`, + draft: false, + prerelease: false, + published_at: "2026-11-02T00:00:00Z", + assets: [{ name: asset, browser_download_url: `${SHARED_REPOSITORY}/releases/download/${prefix}${version}/${asset}` }], + }; +} + +function sharedEntry(id, prefix, name) { + return { + id, + name, + author: "Lithe Community", + repository: SHARED_REPOSITORY, + description: `${name} for Lithe`, + license: "MIT", + versions: [{ + version: "0.1.0", + pluginAPIVersion: 0, + requires: { languageServers: 0, languages: 0 }, + releaseDate: "2026-11-01", + downloads: [{ + platforms: ["darwin-arm64", "darwin-x64"], + downloadURL: sharedRelease(prefix, name, "0.1.0").assets[0].browser_download_url, + sha256: "0".repeat(64), + }], + }], + }; +} + +test("plugins sharing a repository each track only the releases with their own tag prefix", { timeout: 5_000 }, async () => { + const releases = [ + sharedRelease("codex-v", "codex", "0.3.0"), + sharedRelease("codex-v", "codex", "0.2.0"), + sharedRelease("claude-code-v", "claude-code", "0.2.0"), + { ...sharedRelease("", "latest", "1.0.0"), tag_name: "latest" }, + sharedRelease("other-v", "other", "1.0.0"), + sharedRelease("claude-code-v", "claude-code", "0.1.0"), + sharedRelease("codex-v", "codex", "0.1.0"), + ]; + const url = (release) => release.assets[0].browser_download_url; + const index = { + schemaVersion: 0, + plugins: [sharedEntry(CLAUDE_CODE_ID, "claude-code-v", "claude-code"), sharedEntry(CODEX_ID, "codex-v", "codex")], + }; + const fixture = organizationFixture({ + [REPOSITORIES_PATH]: [], + "repos/Lithe-IDEA/lithe-ai-plugins/releases?per_page=100": releases, + }, { + // A plugin.json version that differs from the tag is refused, not listed under either. + [url(releases[0])]: { ...zigManifest("0.3.1"), id: CODEX_ID }, + [url(releases[1])]: { ...zigManifest("0.2.0"), id: CODEX_ID }, + [url(releases[2])]: { ...zigManifest("0.2.0"), id: CLAUDE_CODE_ID }, + }); + const result = await trackIndex(index, { ...fixture, scope: "organization" }); + + assert.deepEqual(result.added, [`${CLAUDE_CODE_ID}@0.2.0 (claude-code-v0.2.0)`, `${CODEX_ID}@0.2.0 (codex-v0.2.0)`]); + // The sibling's releases are neither downloaded nor reported. + assert.deepEqual(fixture.downloads, [url(releases[2]), url(releases[0]), url(releases[1])]); + assert.equal(result.skipped.length, 5); + const log = result.skipped.join("\n"); + assert.match(log, new RegExp(`${CODEX_ID} codex-v0\\.3\\.0: .*release tag \`codex-v0\\.3\\.0\` must be 0\\.3\\.1`)); + for (const id of [CLAUDE_CODE_ID, CODEX_ID]) { + assert.match(log, new RegExp(`${id} latest: the tag must be MAJOR\\.MINOR\\.PATCH`)); + assert.match(log, new RegExp(`${id} other-v1\\.0\\.0: the tag prefix \`other-v\``)); + } + assert.deepEqual(index.plugins.map((entry) => entry.versions.map((version) => version.version)), [["0.2.0", "0.1.0"], ["0.2.0", "0.1.0"]]); + assert.deepEqual(validateIndex(index), []); +}); + +test("an entry without versions keeps the tag prefix of the first release it adds", { timeout: 5_000 }, async () => { + const entry = { ...sharedEntry(CODEX_ID, "codex-v", "codex"), versions: [] }; + const releases = [sharedRelease("codex-v", "codex", "0.2.0"), sharedRelease("v", "codex", "0.1.0")]; + const fixture = organizationFixture({}, { [releases[0].assets[0].browser_download_url]: { ...zigManifest("0.2.0"), id: CODEX_ID } }); + const result = await trackEntry(entry, releases, fixture); + assert.deepEqual(result.added, [`${CODEX_ID}@0.2.0 (codex-v0.2.0)`]); + assert.deepEqual(result.skipped, [`${CODEX_ID} v0.1.0: the tag prefix \`v\` is not \`codex-v\` of the listed versions`]); + assert.deepEqual(releaseTagConvention(entry), { prefix: "codex-v" }); +}); + test("archive verification rechecks changed manifest expectations for the same URL and hash", { timeout: 5_000 }, async () => { const entry = capabilityEntry(); const manifest = manifestFor(entry); @@ -502,12 +602,48 @@ test("formatting keeps plain arrays inline and round-trips", () => { }); test("duplicate ids and unsorted plugins fail the store policy", () => { - const second = { ...validEntry(), id: "io.example.another" }; + const second = siblingEntry("io.example.another", "another-v"); assert.match(validateIndex({ schemaVersion: 0, plugins: [validEntry(), validEntry()] }).join("\n"), /plugin\.index\.duplicate/); assert.match(validateIndex({ schemaVersion: 0, plugins: [validEntry(), second] }).join("\n"), /sorted by id/); assert.deepEqual(validateIndex({ schemaVersion: 0, plugins: [second, validEntry()] }), []); }); +test("release tags split into one prefix and the version they end with, as Lithe's Core splits them", () => { + assert.deepEqual(splitReleaseTag("v1.2.0"), { prefix: "v", version: "1.2.0" }); + assert.deepEqual(splitReleaseTag("codex-v0.10.2"), { prefix: "codex-v", version: "0.10.2" }); + assert.deepEqual(splitReleaseTag("1.2.0"), { prefix: "", version: "1.2.0" }); + // The major number takes every digit, so a prefix never ends in a digit. + assert.deepEqual(splitReleaseTag("a12.3.4"), { prefix: "a", version: "12.3.4" }); + for (const tag of ["x1.2.3.4", "1.2.3.4", "v1.2.0-beta.1", "v9", "v1.2", "latest", "", undefined]) { + assert.equal(splitReleaseTag(tag), null, String(tag)); + } +}); + +test("every listing uses one release tag prefix of its own, ending in the listed version", () => { + const index = (...plugins) => ({ schemaVersion: 0, plugins }); + assert.deepEqual(releaseTagConvention(validEntry()), { prefix: "v" }); + + const mismatched = validEntry(); + mismatched.versions[0].downloads[0].downloadURL = mismatched.versions[0].downloads[0].downloadURL.replace("/v1.9.0/", "/v1.9.1/"); + assert.match(validateIndex(index(mismatched)).join(), /store policy: 1\.9\.0: release tag `v1\.9\.1` must be 1\.9\.0/); + + const mixed = validEntry(); + mixed.versions[0].downloads[0].downloadURL = mixed.versions[0].downloads[0].downloadURL.replace("/v1.9.0/", "/zig-v1.9.0/"); + assert.match(validateIndex(index(mixed)).join(), /store policy: 2\.0\.0: release tag `v2\.0\.0` does not use the prefix `zig-v`/); + + // Lithe derives no prefix from a percent-encoded tag, so the store refuses it. + const encoded = validEntry(); + encoded.versions[0].downloads[0].downloadURL = encoded.versions[0].downloads[0].downloadURL.replace("/v1.9.0/", "/v%31.9.0/"); + assert.match(validateIndex(index(encoded)).join(), /store policy: 1\.9\.0: release tag `v%31\.9\.0`/); + + // Repository names compare in any letter case, like download URLs. + const sameClaim = siblingEntry("io.example.another", "v"); + sameClaim.repository = "https://github.com/Example/Lithe-Zig"; + assert.match(validateIndex(index(sameClaim, validEntry())).join(), + /plugins\[1\] \(io\.example\.zig-support\): store policy: io\.example\.another already uses release tag prefix `v`/); + assert.deepEqual(validateIndex(index(siblingEntry("io.example.another", ""), validEntry())), []); +}); + test("a wrong schema version or extra root field is refused", () => { for (const schemaVersion of [1, 2, "0", undefined]) { assert.match(validateIndex({ schemaVersion, plugins: [] }).join(), /plugin\.index\.schemaUnsupported/); diff --git a/scripts/track-releases.mjs b/scripts/track-releases.mjs index f82a98c..f38421c 100644 --- a/scripts/track-releases.mjs +++ b/scripts/track-releases.mjs @@ -14,6 +14,10 @@ // // Release convention (see docs/publishing.md): // - a published, non-prerelease GitHub Release in the plugin's `repository`; +// - tagged `MAJOR.MINOR.PATCH` with the plugin.json version, one prefix +// per plugin. Plugins sharing a repository use different prefixes (for +// example `codex-v0.1.0` and `claude-code-v0.1.0`) and each entry tracks only +// the releases with its own; // - one `.zip` asset per platform named `--.zip` // (for example `zig-support-2.0.0-darwin-arm64.zip`), or `-.zip` // for one archive that serves every architecture of that OS; @@ -27,7 +31,10 @@ import { createHash } from "node:crypto"; import { readFileSync, writeFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; -import { checkManifest, formatIndex, readArchiveBytes, requirementsKey, validateIndex } from "./validate-index.mjs"; +import { + checkManifest, formatIndex, readArchiveBytes, releaseTagConvention, repositoryKey, requirementsKey, splitReleaseTag, + validateIndex, +} from "./validate-index.mjs"; export const DISCOVERY_OWNER = "Lithe-IDEA"; export const DISCOVERY_PREFIX = "lithe-plugin-"; @@ -38,6 +45,9 @@ const TRACKING_BRANCHES = { external: "bot/track-releases", }; export const SCOPES = Object.keys(TRACKING_BRANCHES); +// GitHub's largest page. Plugins sharing a repository read the same releases, +// so a busy sibling must not push a plugin's own new releases off the page. +const RELEASE_PAGE = "per_page=100"; export function trackingBranch(scope, plugin) { const base = TRACKING_BRANCHES[scope]; @@ -161,16 +171,31 @@ export async function versionFromRelease(entry, release, { /** * Adds every stable release that the entry does not list yet, newest first. + * Only releases tagged with the entry's prefix are downloaded. Releases tagged + * with a `siblingPrefixes` prefix belong to another plugin of the repository + * and are passed over silently; an entry without versions takes the prefix of + * the first release it adds. * Returns the added versions and, with their reasons, the releases it refused. */ -export async function trackEntry(entry, releases, archiveIO = {}) { +export async function trackEntry(entry, releases, { siblingPrefixes = new Set(), ...archiveIO } = {}) { const added = []; const skipped = []; const listed = new Set(entry.versions.map((version) => version.version)); const listedURLs = new Set(entry.versions.flatMap((version) => version.downloads.map((d) => d.downloadURL))); + let prefix = releaseTagConvention(entry).prefix ?? null; for (const release of releases) { if (release.draft || release.prerelease) continue; if ((release.assets ?? []).some((asset) => listedURLs.has(asset.browser_download_url))) continue; + const tag = splitReleaseTag(release.tag_name); + if (tag && siblingPrefixes.has(tag.prefix)) continue; + if (!tag) { + skipped.push(`${entry.id} ${release.tag_name}: the tag must be MAJOR.MINOR.PATCH`); + continue; + } + if (prefix !== null && tag.prefix !== prefix) { + skipped.push(`${entry.id} ${release.tag_name}: the tag prefix \`${tag.prefix}\` is not \`${prefix}\` of the listed versions`); + continue; + } const result = await versionFromRelease(entry, release, archiveIO); if (result.problems) { skipped.push(`${entry.id} ${release.tag_name}: ${result.problems.join("; ")}`); @@ -182,11 +207,21 @@ export async function trackEntry(entry, releases, archiveIO = {}) { } addVersion(entry, result.version); listed.add(result.version.version); + prefix = tag.prefix; added.push(`${entry.id}@${result.version.version} (${release.tag_name})`); } return { added, skipped }; } +/** Release-tag prefixes of the other listed plugins in the entry's repository. */ +export function siblingPrefixes(index, entry) { + const repository = repositoryKey(entry); + return new Set(index.plugins + .filter((other) => other !== entry && repositoryKey(other) === repository) + .map((other) => releaseTagConvention(other).prefix) + .filter((prefix) => prefix != null)); +} + /** Selects the organization repositories that should be listed but are not yet. */ export function unlistedPluginRepositories(repositories, index) { const listed = new Set(index.plugins.map((entry) => repositoryPath(entry.repository).toLowerCase())); @@ -285,7 +320,7 @@ export async function discoverPlugins(index, { for (const repository of unlistedPluginRepositories(repositories, index)) { let releases; try { - releases = await request(`repos/${repository.full_name}/releases?per_page=20`); + releases = await request(`repos/${repository.full_name}/releases?${RELEASE_PAGE}`); } catch (error) { skipped.push(`${repository.full_name}: ${error.message}`); continue; @@ -327,12 +362,14 @@ export async function trackIndex(index, { if (!inScope(entry, scope) || (onlyPlugin && entry.id !== onlyPlugin)) continue; let releases; try { - releases = await request(`repos/${repositoryPath(entry.repository)}/releases?per_page=20`); + releases = await request(`repos/${repositoryPath(entry.repository)}/releases?${RELEASE_PAGE}`); } catch (error) { skipped.push(`${entry.id}: ${error.message}`); continue; } - const result = await trackEntry(entry, releases, { downloadArchive, readManifests }); + const result = await trackEntry(entry, releases, { + downloadArchive, readManifests, siblingPrefixes: siblingPrefixes(index, entry), + }); added.push(...result.added); skipped.push(...result.skipped); } diff --git a/scripts/validate-index.mjs b/scripts/validate-index.mjs index 59513a7..92e612b 100644 --- a/scripts/validate-index.mjs +++ b/scripts/validate-index.mjs @@ -30,7 +30,8 @@ const ENTRY_FIELDS = new Set([ const VERSION_FIELDS = new Set(["version", "pluginAPIVersion", "requires", "releaseDate", "downloads"]); const DOWNLOAD_FIELDS = new Set(["platforms", "downloadURL", "sha256"]); const REPOSITORY = /^https:\/\/github\.com\/([A-Za-z0-9._-]+)\/([A-Za-z0-9._-]+)\/?$/; -const DOWNLOAD_URL = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/releases\/download\/[^/]+\/[^/]+\.zip$/; +const DOWNLOAD_URL = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/releases\/download\/([^/]+)\/[^/]+\.zip$/; +const RELEASE_TAG = /^(.*?)([0-9]+\.[0-9]+\.[0-9]+)$/; const ICON_URL = /^https:\/\/raw\.githubusercontent\.com\/([^/]+)\/([^/]+)\/.+/; const LANGUAGE_TAG = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/; @@ -194,6 +195,50 @@ export function validateEntry(entry) { } } +/** + * Splits a release tag into a prefix and the MAJOR.MINOR.PATCH version that + * ends it, as Lithe's Rust Core (`lithe_github::split_release_tag`) does. The + * major number takes every digit before it and a prefix may not end in ".", + * so a tag has at most one split. Returns null for any other tag. + */ +export function splitReleaseTag(tag) { + const match = typeof tag === "string" ? RELEASE_TAG.exec(tag) : null; + if (!match || /[0-9.]$/.test(match[1])) return null; + return { prefix: match[1], version: match[2] }; +} + +/** + * Reads the release-tag convention of an entry the way Lithe's Rust Core + * derives `releaseTagPrefix`: every download's tag splits into one shared + * prefix and the version that lists it. Lithe shows a plugin only the releases + * with its prefix, so plugins sharing a repository keep separate changelogs. + * Returns `{ prefix }` (null for an entry without versions) or `{ problem }`. + */ +export function releaseTagConvention(entry) { + let prefix = null; + for (const version of entry.versions) { + for (const download of version.downloads) { + const tag = DOWNLOAD_URL.exec(download.downloadURL)?.[3] ?? ""; + // Lithe derives no prefix from a percent-encoded tag. + const split = tag.includes("%") ? null : splitReleaseTag(tag); + if (split?.version !== version.version) { + return { problem: `${version.version}: release tag \`${tag}\` must be ${version.version}` }; + } + if (prefix !== null && split.prefix !== prefix) { + return { problem: `${version.version}: release tag \`${tag}\` does not use the prefix \`${prefix}\` of the other versions` }; + } + prefix = split.prefix; + } + } + return { prefix }; +} + +/** The lowercase `owner/repo` of an entry, which groups the plugins sharing a repository. */ +export function repositoryKey(entry) { + const [, owner, repo] = REPOSITORY.exec(entry.repository); + return `${owner}/${repo}`.toLowerCase(); +} + /** * Canonical index text: two-space indentation, arrays of plain values kept on * one line. The tracker writes this form and CI requires it, so bot and @@ -231,6 +276,7 @@ export function validateIndex(index) { if (!Array.isArray(index.plugins)) return [...problems, "`plugins` must be an array"]; const seen = new Set(); + const prefixOwners = new Map(); index.plugins.forEach((entry, position) => { const label = `plugins[${position}]${typeof entry?.id === "string" ? ` (${entry.id})` : ""}`; try { @@ -242,6 +288,20 @@ export function validateIndex(index) { } if (seen.has(entry.id)) problems.push(`${label}: plugin.index.duplicate: id is already listed`); seen.add(entry.id); + + // Store policy, stricter than Lithe: every listing has a release-tag + // prefix of its own, so its changelog never shows another plugin's releases. + const { prefix, problem } = releaseTagConvention(entry); + if (problem) { + problems.push(`${label}: store policy: ${problem}`); + return; + } + const claim = JSON.stringify([repositoryKey(entry), prefix]); + if (prefixOwners.has(claim)) { + problems.push(`${label}: store policy: ${prefixOwners.get(claim)} already uses release tag prefix \`${prefix}\` in ${entry.repository}`); + } else { + prefixOwners.set(claim, entry.id); + } }); // Store policy, stricter than Lithe: keep diffs reviewable and deterministic.