Skip to content

Commit e9f0079

Browse files
authored
feat(track): 自动收录 Lithe-IDEA 组织的 lithe-plugin-* 仓库 (#49)
Track plugin releases 除了追踪已收录插件的新版本,还会扫描 Lithe-IDEA 组织下尚未收录的公开 lithe-plugin-* 仓库(排除 lithe-plugin-docs、私有、 已归档和 fork 仓库)。仓库有带插件包的正式 Release 时,按包内 plugin.json (id、displayName、vendor.displayName)和仓库简介、许可证、topics 草拟条目, 连同全部正式版本放进同一个 bot PR。pre-release 仍然不收录。 草拟条目和版本一起经过 validateIndex,不合格的仓库只记录跳过原因, 不会让整份索引校验失败、挡住其他插件的新版本。
1 parent 907e88b commit e9f0079

7 files changed

Lines changed: 407 additions & 32 deletions

File tree

‎.github/workflows/track-releases.yml‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
name: Track plugin releases
22

3-
# Scans the GitHub Releases of every listed plugin and opens one pull request
4-
# that adds versions not yet in the index. Plugin authors only need to publish
5-
# a release that follows docs/publishing.md.
3+
# Scans the GitHub Releases of every listed plugin, and of every unlisted
4+
# public `lithe-plugin-*` repository in the Lithe-IDEA organization except
5+
# `lithe-plugin-docs`, then opens one pull request that adds the versions and
6+
# plugins not yet in the index. Plugin authors only need to publish a release
7+
# that follows docs/publishing.md.
68
on:
79
schedule:
810
- cron: "41 */6 * * *"
911
workflow_dispatch:
1012
inputs:
1113
plugin:
12-
description: "Only track this plugin ID (empty = all)"
14+
description: "Only track this plugin ID, listed or a new organization plugin (empty = all)"
1315
required: false
1416
default: ""
1517

@@ -58,6 +60,7 @@ jobs:
5860
if: steps.track.outputs.added != '0'
5961
env:
6062
SUMMARY: ${{ steps.track.outputs.summary }}
63+
NEW_PLUGINS: ${{ steps.track.outputs.new_plugins }}
6164
run: |
6265
git config user.name "lithe-store-bot"
6366
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
@@ -69,6 +72,10 @@ jobs:
6972
git commit -m "chore(index): track new plugin releases" -m "$SUMMARY"
7073
git push --force origin "$BRANCH"
7174
body=$(printf '自动追踪到新的插件版本:\n\n%s\n\n已校验 SHA-256 与包内 plugin.json(id、version、pluginAPIVersion、signatureRequirement),README 总览已一并重新生成。维护者请按 docs/maintainers.md 的清单审查后合并。' "$(echo "$SUMMARY" | tr ',' '\n' | sed 's/^ */- /')")
75+
if [ -n "$NEW_PLUGINS" ]; then
76+
# The next scan rebuilds this branch from main, so metadata fixes belong in a follow-up PR.
77+
body="$body$(printf '\n\n首次收录:%s。条目由插件仓库的简介、许可证、topics 和包内 plugin.json 自动生成,没有图标和中文简介,description 沿用仓库简介的语言。请按 docs/maintainers.md 的首次收录清单审查;合并后另提 PR 补充 icon、localizedDescriptions 和 tags,不要直接改这个分支,下一轮扫描会覆盖它。' "$NEW_PLUGINS")"
78+
fi
7279
if gh pr view "$BRANCH" --json state -q .state 2>/dev/null | grep -q OPEN; then
7380
gh pr edit "$BRANCH" --body "$body"
7481
else

‎CONTRIBUTING.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
| 我想… | 怎么做 |
44
| --- | --- |
5-
| 收录自己的插件 | 读 [docs/publishing.md](docs/publishing.md),提 PR 或开“插件收录申请” issue |
5+
| 收录自己的插件 | 读 [docs/publishing.md](docs/publishing.md),提 PR 或开“插件收录申请” issue;Lithe-IDEA 组织的 `lithe-plugin-*` 仓库由 bot 自动收录(见 [首次收录](docs/publishing.md#3-首次收录)) |
66
| 发布插件新版本 | 在自己仓库发布 Release 即可,bot 会自动开 PR(见 [发布新版本](docs/publishing.md#4-发布新版本)) |
77
| 修改插件信息 | 提 PR 修改 `lithe-plugin-index.json` 中自己的条目(含 `icon`) |
88
| 报告有问题的插件 | 开“报告插件问题” issue;安全问题请勾选“安全问题”,维护者会优先处理 |
@@ -57,7 +57,7 @@ Lithe 会把仓库地址 `https://github.com/Lithe-IDEA/Lithe-store` 解析为
5757
```text
5858
lithe-plugin-index.json # 唯一的数据文件,Lithe 客户端读取它
5959
scripts/validate-index.mjs # 与 Lithe Rust Core 同规则的校验 + 下载包校验
60-
scripts/track-releases.mjs # 追踪已收录插件的新 Release 并生成版本条目
60+
scripts/track-releases.mjs # 追踪已收录插件和 Lithe-IDEA 组织 lithe-plugin-* 仓库的新 Release,生成索引条目
6161
scripts/render-readme.mjs # 根据索引生成 README 的插件总览
6262
scripts/store.test.mjs # 校验脚本的测试(fixtures 复制自插件契约)
6363
assets/ # README 用到的图片(无图标插件的默认图标)

‎docs/maintainers.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ CI(`Validate index`)已经自动保证:
1515
- [ ] 首次收录:`author` 与仓库所有者对应,名称不冒充其他项目或 Lithe 官方;
1616
- [ ] 插件声明要运行的程序与描述相符(看包内 `plugin.json` 的 `languageServers` 与 `executionProviders`);
1717
- [ ] 描述、标签、图标没有误导内容;
18-
- [ ] 新版本 PR(bot 或作者提交):版本号递增,没有删除旧版本。
18+
- [ ] 新版本 PR(bot 或作者提交):版本号递增,没有删除旧版本;
19+
- [ ] bot 首次收录的插件(PR 描述里的“首次收录”):仓库简介适合作为 `description`,仓库 topics 适合作为 `tags`。
20+
合并后另提 PR 补充 `icon`、`localizedDescriptions`,必要时修改 `description`、`tags`;
21+
不要直接改 `bot/track-releases`,下一轮扫描会从 main 重建这个分支。
1922

2023
## 自动追踪新版本
2124

2225
`Track plugin releases` 每 6 小时运行一次,也可在 Actions 中手动运行(可只指定一个插件 ID)。
26+
它扫描已收录插件的 Release,以及 Lithe-IDEA 组织下尚未收录的公开 `lithe-plugin-*` 仓库
27+
(`lithe-plugin-docs` 不发布插件,固定排除),只收录正式 Release;新插件的条目生成规则见
28+
[发布社区插件的首次收录](publishing.md#3-首次收录)。手动运行时指定的插件 ID 可以是已收录插件,
29+
也可以是组织中尚未收录的插件。
2330
它把结果统一提交到 `bot/track-releases` 分支并开一个 PR,PR 里同时包含索引和重新生成的 README 总览(合并后不需要再等 `Sync README`);新的扫描会覆盖这个分支并更新 PR 描述。
2431

2532
需要的仓库设置:

‎docs/publishing.md‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ shasum -a 256 zig-support-2.0.0-darwin-arm64.zip
7777

7878
## 3. 首次收录
7979

80+
Lithe-IDEA 组织下名为 `lithe-plugin-*` 的公开仓库(`lithe-plugin-docs` 除外,它不发布插件)
81+
不需要手工提交首次收录 PR。`Track plugin releases` 发现这类仓库还没收录、并且已经有带插件包的
82+
正式 Release 时,会把它连同全部正式版本一起放进 bot PR,条目按以下来源生成:
83+
84+
| 字段 | 来源 |
85+
| --- | --- |
86+
| `id`、`name`、`author` | 最新正式 Release 的包内 `plugin.json`:`id`、`displayName`、`vendor.displayName` |
87+
| `repository`、`homepage` | 仓库地址,`homepage` 为 `<仓库地址>#readme` |
88+
| `description` | GitHub 仓库简介,原样使用 |
89+
| `license` | GitHub 识别出的许可证(SPDX ID) |
90+
| `tags` | 仓库 topics;没有 topics 时省略 |
91+
92+
仓库是私有、已归档或 fork,仓库没有简介,GitHub 识别不出许可证,包内 `plugin.json` 缺字段或 ID 不符合索引规则,
93+
或者 ID 已经被别的条目占用时,自动收录会跳过该仓库,并在工作流日志里写明原因。自动生成的条目
94+
没有 `icon` 和 `localizedDescriptions`,bot PR 合并后另提 PR 补充。和版本追踪一样,只发布过
95+
pre-release 的仓库不会被收录。
96+
97+
其他仓库按下面的步骤收录:
98+
8099
1. Fork 本仓库,在 `lithe-plugin-index.json` 的 `plugins` 中**按 `id` 字母序**插入你的条目:
81100

82101
```json
@@ -145,7 +164,8 @@ shasum -a 256 zig-support-2.0.0-darwin-arm64.zip
145164
收录后,新版本**不需要你再提 PR**:
146165

147166
1. 在你的仓库递增 `plugin.json` 的 `version`,打包,发布新的正式 Release(资产命名同上)。
148-
2. `Track plugin releases` 工作流每 6 小时扫描一次已收录插件最近 20 个 Release,
167+
2. `Track plugin releases` 工作流每 6 小时扫描一次已收录插件最近 20 个 Release
168+
(Lithe-IDEA 组织尚未收录的 `lithe-plugin-*` 仓库也一起扫描,见 [首次收录](#3-首次收录)),
149169
把新版本写进索引(版本号、`pluginAPIVersion`、`requires` 取自包内 `plugin.json`,
150170
能力表按键排序写入;发布日期取 Release 发布时间,SHA-256 由 CI 计算),
151171
然后开一个 `chore(index): 追踪插件新版本` PR。
@@ -162,7 +182,8 @@ shasum -a 256 zig-support-2.0.0-darwin-arm64.zip
162182
稳定版用户安装;稳定版是否支持,以 Lithe 的发行说明为准。支持之前,把 GitHub Release 标为
163183
预发布,并手工提交索引条目(LLDB Debugger `0.1.0` 就是这样收录的)。稳定版 Lithe 遇到自己
164184
不支持的 API 等级只会显示“需要更新 Lithe”,不会安装,所以不会装出坏插件。稳定版支持之后,
165-
把 Release 转为正式发布(或发布新版本),自动追踪就会接手后续版本。调试适配器插件的写法见
185+
把 Release 转为正式发布(或发布新版本),自动追踪就会接手后续版本;还没收录的 Lithe-IDEA
186+
组织插件会在这时被自动首次收录。调试适配器插件的写法见
166187
[编写调试适配器插件](https://github.com/Lithe-IDEA/lithe-plugin-docs/blob/main/guides/debug-adapter-plugin.md)。
167188

168189
自动追踪会在日志中说明归档无法收录的原因:没有符合命名的 zip、包内 `plugin.json`

‎scripts/store.test.mjs‎

Lines changed: 182 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import { tmpdir } from "node:os";
66
import { join } from "node:path";
77
import { test } from "node:test";
88
import { END, START, categoryOf, renderOverview, renderReadme, systemsOf, truncate } from "./render-readme.mjs";
9-
import { addVersion, platformsForAsset, versionFromRelease } from "./track-releases.mjs";
10-
import { checkManifest, formatIndex, inspectArchive, validateEntry, validateIndex, verifyArchives } from "./validate-index.mjs";
9+
import {
10+
addVersion, discoverPlugins, platformsForAsset, unlistedPluginRepositories, versionFromRelease,
11+
} from "./track-releases.mjs";
12+
import {
13+
checkManifest, formatIndex, inspectArchive, readPackageManifests, validateEntry, validateIndex, verifyArchives,
14+
} from "./validate-index.mjs";
1115

1216
// Fixtures are copied from the plugin contract (lithe-plugin-docs contract/v1/fixtures/marketplace)
1317
// so this validator reports the same code as Lithe's Rust Core for each case.
@@ -207,6 +211,179 @@ test("release tracking preserves API 1/2 releases without adding requires", { ti
207211
}
208212
});
209213

214+
// Organization discovery fixtures: GitHub responses are plain objects, and each
215+
// archive's bytes are its plugin.json text, so no test touches the network or unzip.
216+
const REPOSITORIES_PATH = "orgs/Lithe-IDEA/repos?type=public&per_page=100&page=1";
217+
const ZIG_ID = "io.github.lithe-idea.zig-support";
218+
219+
function organizationRepository(name, overrides = {}) {
220+
return {
221+
name,
222+
full_name: `Lithe-IDEA/${name}`,
223+
html_url: `https://github.com/Lithe-IDEA/${name}`,
224+
private: false,
225+
archived: false,
226+
fork: false,
227+
description: "Zig language support for Lithe",
228+
license: { spdx_id: "Apache-2.0" },
229+
topics: ["language", "zig"],
230+
...overrides,
231+
};
232+
}
233+
234+
function organizationRelease(repository, version, overrides = {}) {
235+
const name = `zig-support-${version}-darwin.zip`;
236+
return {
237+
tag_name: `v${version}`,
238+
draft: false,
239+
prerelease: false,
240+
published_at: "2026-11-01T00:00:00Z",
241+
assets: [{ name, browser_download_url: `${repository.html_url}/releases/download/v${version}/${name}` }],
242+
...overrides,
243+
};
244+
}
245+
246+
function zigManifest(version) {
247+
return {
248+
schemaVersion: 2,
249+
id: ZIG_ID,
250+
displayName: "Zig Support",
251+
version,
252+
pluginAPIVersion: 2,
253+
vendor: { displayName: "Lithe Community", signatureRequirement: "none" },
254+
};
255+
}
256+
257+
function organizationFixture(responses, manifestsByURL) {
258+
const downloads = [];
259+
return {
260+
downloads,
261+
request: async (path) => {
262+
assert.ok(Object.hasOwn(responses, path), `unexpected GitHub request: ${path}`);
263+
return structuredClone(responses[path]);
264+
},
265+
downloadArchive: async (url) => {
266+
assert.ok(Object.hasOwn(manifestsByURL, url), `unexpected download: ${url}`);
267+
downloads.push(url);
268+
return Buffer.from(JSON.stringify(manifestsByURL[url]));
269+
},
270+
readManifests: (bytes, pluginID) => {
271+
const manifest = JSON.parse(bytes.toString());
272+
return { manifests: pluginID === undefined || manifest.id === pluginID ? [manifest] : [], unsafe: [] };
273+
},
274+
};
275+
}
276+
277+
function zigOrganization() {
278+
const repository = organizationRepository("lithe-plugin-zig");
279+
const releases = [
280+
organizationRelease(repository, "1.2.0", { prerelease: true }),
281+
organizationRelease(repository, "1.1.0"),
282+
organizationRelease(repository, "1.0.0"),
283+
];
284+
const manifestsByURL = Object.fromEntries(releases.map((release) =>
285+
[release.assets[0].browser_download_url, zigManifest(release.tag_name.slice(1))]));
286+
const fixture = organizationFixture({
287+
[REPOSITORIES_PATH]: [repository, organizationRepository("lithe-plugin-docs")],
288+
"repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=20": releases,
289+
}, manifestsByURL);
290+
return { releases, fixture };
291+
}
292+
293+
test("organization discovery considers only active, unlisted lithe-plugin- repositories", () => {
294+
const index = { schemaVersion: 1, plugins: [{ ...validEntry(), repository: "https://github.com/Lithe-IDEA/Lithe-Plugin-Listed" }] };
295+
const names = unlistedPluginRepositories([
296+
organizationRepository("lithe-plugin-zig"),
297+
organizationRepository("lithe-plugin-docs"),
298+
organizationRepository("lithe-plugin-listed"),
299+
organizationRepository("lithe-plugin-old", { archived: true }),
300+
organizationRepository("lithe-plugin-copy", { fork: true }),
301+
organizationRepository("lithe-plugin-secret", { private: true }),
302+
organizationRepository("Lithe-store"),
303+
], index).map((repository) => repository.name);
304+
assert.deepEqual(names, ["lithe-plugin-zig"]);
305+
});
306+
307+
test("organization discovery lists a new plugin with its stable releases", { timeout: 5_000 }, async () => {
308+
const { releases, fixture } = zigOrganization();
309+
const index = { schemaVersion: 1, plugins: [validEntry(), { ...validEntry(), id: "org.example.zig-tools" }] };
310+
const result = await discoverPlugins(index, fixture);
311+
312+
assert.deepEqual(result.skipped, []);
313+
assert.deepEqual(result.newPlugins, [ZIG_ID]);
314+
assert.deepEqual(result.added, [`${ZIG_ID}@1.1.0 (v1.1.0) [new plugin]`, `${ZIG_ID}@1.0.0 (v1.0.0) [new plugin]`]);
315+
assert.deepEqual(index.plugins.map((entry) => entry.id), ["io.example.zig-support", ZIG_ID, "org.example.zig-tools"]);
316+
const { versions, ...metadata } = index.plugins[1];
317+
assert.deepEqual(metadata, {
318+
id: ZIG_ID,
319+
name: "Zig Support",
320+
author: "Lithe Community",
321+
repository: "https://github.com/Lithe-IDEA/lithe-plugin-zig",
322+
homepage: "https://github.com/Lithe-IDEA/lithe-plugin-zig#readme",
323+
description: "Zig language support for Lithe",
324+
tags: ["language", "zig"],
325+
license: "Apache-2.0",
326+
});
327+
assert.deepEqual(versions.map((version) => version.version), ["1.1.0", "1.0.0"]);
328+
assert.deepEqual(validateIndex(index), []);
329+
// The draft and its first version share one download; the pre-release is never fetched.
330+
assert.deepEqual(fixture.downloads, [releases[1], releases[2]].map((release) => release.assets[0].browser_download_url));
331+
});
332+
333+
test("organization discovery keeps only the plugin named by --plugin", { timeout: 5_000 }, async () => {
334+
const other = zigOrganization();
335+
const otherIndex = { schemaVersion: 1, plugins: [validEntry()] };
336+
const skippedRun = await discoverPlugins(otherIndex, { ...other.fixture, onlyPlugin: "io.example.other" });
337+
assert.deepEqual(skippedRun.added, []);
338+
assert.equal(otherIndex.plugins.length, 1);
339+
340+
const named = zigOrganization();
341+
const namedIndex = { schemaVersion: 1, plugins: [validEntry()] };
342+
const namedRun = await discoverPlugins(namedIndex, { ...named.fixture, onlyPlugin: ZIG_ID });
343+
assert.deepEqual(namedRun.newPlugins, [ZIG_ID]);
344+
});
345+
346+
test("organization discovery skips repositories that cannot be listed yet", { timeout: 5_000 }, async () => {
347+
const preview = organizationRepository("lithe-plugin-preview");
348+
const unlicensed = organizationRepository("lithe-plugin-unlicensed", { license: { spdx_id: "NOASSERTION" } });
349+
const undescribed = organizationRepository("lithe-plugin-undescribed", { description: null });
350+
const copy = organizationRepository("lithe-plugin-copy");
351+
const copyRelease = organizationRelease(copy, "1.0.0");
352+
const anonymous = organizationRepository("lithe-plugin-anonymous");
353+
const anonymousRelease = organizationRelease(anonymous, "1.0.0");
354+
const official = organizationRepository("lithe-plugin-official");
355+
const officialRelease = organizationRelease(official, "1.0.0");
356+
const fixture = organizationFixture({
357+
[REPOSITORIES_PATH]: [preview, unlicensed, undescribed, copy, anonymous, official],
358+
"repos/Lithe-IDEA/lithe-plugin-preview/releases?per_page=20": [organizationRelease(preview, "0.1.0", { prerelease: true })],
359+
"repos/Lithe-IDEA/lithe-plugin-unlicensed/releases?per_page=20": [organizationRelease(unlicensed, "1.0.0")],
360+
"repos/Lithe-IDEA/lithe-plugin-undescribed/releases?per_page=20": [organizationRelease(undescribed, "1.0.0")],
361+
"repos/Lithe-IDEA/lithe-plugin-copy/releases?per_page=20": [copyRelease],
362+
"repos/Lithe-IDEA/lithe-plugin-anonymous/releases?per_page=20": [anonymousRelease],
363+
"repos/Lithe-IDEA/lithe-plugin-official/releases?per_page=20": [officialRelease],
364+
}, {
365+
[copyRelease.assets[0].browser_download_url]: { ...zigManifest("1.0.0"), id: "io.example.zig-support" },
366+
[anonymousRelease.assets[0].browser_download_url]: { ...zigManifest("1.0.0"), id: "io.github.lithe-idea.anonymous", vendor: { signatureRequirement: "none" } },
367+
[officialRelease.assets[0].browser_download_url]: { ...zigManifest("1.0.0"), id: "dev.lithe.official" },
368+
});
369+
const index = { schemaVersion: 1, plugins: [validEntry()] };
370+
const result = await discoverPlugins(index, fixture);
371+
372+
assert.deepEqual(result.added, []);
373+
assert.deepEqual(result.newPlugins, []);
374+
assert.equal(index.plugins.length, 1);
375+
const log = result.skipped.join("\n");
376+
assert.match(log, /lithe-plugin-preview: no stable release/);
377+
assert.match(log, /lithe-plugin-unlicensed: GitHub detects no license/);
378+
assert.match(log, /lithe-plugin-undescribed: the repository has no description/);
379+
assert.match(log, /lithe-plugin-copy: io\.example\.zig-support is already listed for https:\/\/github\.com\/example\/lithe-zig/);
380+
// A drafted entry that the index would reject never gains a version, so it is not listed.
381+
assert.match(log, /io\.github\.lithe-idea\.anonymous.*author/);
382+
assert.match(log, /dev\.lithe\.official.*officialNamespace/);
383+
// Metadata problems are found before any archive is downloaded.
384+
assert.deepEqual(fixture.downloads, [copyRelease, anonymousRelease, officialRelease].map((release) => release.assets[0].browser_download_url));
385+
});
386+
210387
test("archive verification rechecks changed manifest expectations for the same URL and hash", { timeout: 5_000 }, async () => {
211388
const entry = capabilityEntry();
212389
const manifest = manifestFor(entry);
@@ -322,6 +499,9 @@ test("archives must hold one matching community plugin.json", () => {
322499
/signatureRequirement/,
323500
);
324501
assert.match(inspectArchive(build({ ...manifest, id: "io.other" }), entry, version).join(), /exactly one plugin\.json/);
502+
// Without an ID (an unlisted plugin) every manifest that declares one is returned.
503+
assert.deepEqual(readPackageManifests(build({ ...manifest, id: "io.other" })).manifests.map((found) => found.id), ["io.other"]);
504+
assert.deepEqual(readPackageManifests(build({ version: "1.0.0" })).manifests, []);
325505
} finally {
326506
rmSync(workDir, { recursive: true, force: true });
327507
}

0 commit comments

Comments
 (0)