Skip to content

Commit fabaaf8

Browse files
fix(track): 隔离按插件追踪的 PR 分支 (#88)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 2c9c709 commit fabaaf8

6 files changed

Lines changed: 62 additions & 31 deletions

File tree

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ name: Track plugin releases
55
# `lithe-plugin-docs`, and adds the versions and plugins not yet in the index.
66
# Plugin authors only need to publish a release that follows docs/publishing.md.
77
#
8-
# The scan runs once per scope, and each scope keeps its own pull request:
8+
# Full scans keep one pull request per scope. Filtered scans keep one per scope and plugin.
99
#
1010
# - organization: plugins whose repository belongs to the Lithe-IDEA organization,
11-
# including first listings. After the archives are verified, the workflow
12-
# merges the pull request itself with a token of the Lithe Store Bot GitHub
13-
# App, the only bot that the "Only owners merge main" ruleset lets through.
11+
# including first listings. After verification, the Store Bot attempts a merge
12+
# if configured. A maintainer merges when the bot cannot.
1413
# - external: every other plugin. The pull request waits for a maintainer
1514
# review, and this scope never receives the app token.
1615
on:
@@ -47,21 +46,19 @@ jobs:
4746
matrix:
4847
include:
4948
- scope: organization
50-
branch: bot/track-organization-releases
5149
title: "chore(index): 追踪 Lithe-IDEA 组织插件新版本"
5250
- scope: external
53-
branch: bot/track-releases
5451
title: "chore(index): 追踪组织外插件新版本"
5552
env:
5653
SCOPE: ${{ matrix.scope }}
57-
BRANCH: ${{ matrix.branch }}
54+
HAS_STORE_BOT_APP: ${{ matrix.scope == 'organization' && vars.STORE_BOT_APP_CLIENT_ID != '' && secrets.STORE_BOT_APP_PRIVATE_KEY != '' }}
5855
TITLE: ${{ matrix.title }}
5956
steps:
6057
# Only the organization scope may merge into main, so only it asks for the
6158
# app token. Without the app, both scopes fall back to the tokens below.
6259
- name: Create the Lithe Store Bot token
6360
id: bot
64-
if: matrix.scope == 'organization' && vars.STORE_BOT_APP_CLIENT_ID != ''
61+
if: env.HAS_STORE_BOT_APP == 'true'
6562
uses: actions/create-github-app-token@v3
6663
with:
6764
client-id: ${{ vars.STORE_BOT_APP_CLIENT_ID }}
@@ -95,6 +92,7 @@ jobs:
9592
- name: Close the obsolete pull request
9693
if: steps.track.outputs.added == '0' && inputs.plugin == ''
9794
env:
95+
BRANCH: ${{ steps.track.outputs.branch }}
9896
GH_TOKEN: ${{ steps.bot.outputs.token || secrets.STORE_BOT_TOKEN || github.token }}
9997
run: |
10098
number=$(gh pr list --head "$BRANCH" --state open --json number -q '.[0].number')
@@ -119,6 +117,8 @@ jobs:
119117
id: pr
120118
if: steps.track.outputs.added != '0'
121119
env:
120+
BRANCH: ${{ steps.track.outputs.branch }}
121+
PLUGIN: ${{ inputs.plugin }}
122122
GH_TOKEN: ${{ steps.bot.outputs.token || secrets.STORE_BOT_TOKEN || github.token }}
123123
SUMMARY: ${{ steps.track.outputs.summary }}
124124
NEW_PLUGINS: ${{ steps.track.outputs.new_plugins }}
@@ -135,8 +135,11 @@ jobs:
135135
136136
list=$(echo "$SUMMARY" | tr ',' '\n' | sed 's/^ */- /')
137137
checks="已校验 SHA-256 与包内 plugin.json(id、version、pluginAPIVersion、signatureRequirement),README 总览已一并重新生成。"
138-
if [ "$SCOPE" = organization ]; then
139-
review="这些插件的仓库属于 Lithe-IDEA 组织,工作流会在校验通过后直接合入 main。如果这个 PR 仍处于打开状态,说明自动合入没有成功(原因见工作流日志),请维护者按 docs/maintainers.md 的清单审查后合并。"
138+
if [ -n "$PLUGIN" ]; then TITLE="$TITLE ($PLUGIN)"; fi
139+
if [ "$HAS_STORE_BOT_APP" = true ]; then
140+
review="Store Bot 将尝试合并本次校验的提交。若工作流结束后 PR 仍打开,请维护者查看合并步骤的日志,按 docs/maintainers.md 的清单审查后合并。"
141+
elif [ "$SCOPE" = organization ]; then
142+
review="此仓库未配置完整的 Store Bot 凭据,请维护者按 docs/maintainers.md 的清单审查后合并。"
140143
else
141144
review="这些插件来自 Lithe-IDEA 组织以外的仓库,维护者请按 docs/maintainers.md 的清单审查后合并。"
142145
fi
@@ -159,6 +162,7 @@ jobs:
159162
- name: Merge the organization pull request
160163
if: matrix.scope == 'organization' && steps.track.outputs.added != '0'
161164
env:
165+
BRANCH: ${{ steps.track.outputs.branch }}
162166
# Only the app can pass the ruleset, so this step never falls back to another token.
163167
GH_TOKEN: ${{ steps.bot.outputs.token }}
164168
NUMBER: ${{ steps.pr.outputs.number }}

‎CONTRIBUTING.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
| 我想… | 怎么做 |
44
| --- | --- |
55
| 收录自己的插件 | 读 [docs/publishing.md](docs/publishing.md),提 PR 或开“插件收录申请” issue;Lithe-IDEA 组织的 `lithe-plugin-*` 仓库由 bot 自动收录(见 [首次收录](docs/publishing.md#3-首次收录)) |
6-
| 发布插件新版本 | 在自己仓库发布 Release 即可,bot 会自动开 PR;Lithe-IDEA 组织插件校验通过后自动合入(见 [发布新版本](docs/publishing.md#4-发布新版本)) |
6+
| 发布插件新版本 | 在自己仓库发布 Release 即可,bot 会自动开 PR(见 [发布新版本](docs/publishing.md#4-发布新版本)) |
77
| 修改插件信息 | 提 PR 修改 `lithe-plugin-index.json` 中自己的条目(含 `icon`) |
88
| 报告有问题的插件 | 开“报告插件问题” issue;安全问题请勾选“安全问题”,维护者会优先处理 |
99
| 改进脚本、CI 或文档 | 直接提 PR,并运行 `node --test scripts/store.test.mjs` |
@@ -47,7 +47,7 @@ Lithe 不再区分官方插件和普通插件:本仓库收录的每个插件
4747
| --- | --- | --- |
4848
| 范围 | Lithe-IDEA 组织下的公开 `lithe-plugin-*` 仓库(已退役的文档仓库 `lithe-plugin-docs` 除外) | 其他公开 GitHub 仓库 |
4949
| 首次收录 | bot 发现带插件包的正式 Release 后自动收录,不需要提交 PR | 提 PR 或开“插件收录申请” issue,维护者按[审查清单](docs/maintainers.md#审查清单)审核后合并 |
50-
| 新版本 | bot 开 PR,校验通过后自动合入 | bot 开 PR,维护者审核后合并 |
50+
| 新版本 | bot 开 PR,校验通过后由已配置的 Store Bot 尝试合并,仍打开的 PR 由维护者审核后合并 | bot 开 PR,维护者审核后合并 |
5151

5252
两种插件都**由各自的开发者维护**。本仓库的校验和审查只保证:索引格式正确、下载包与 SHA-256 一致、
5353
包内 `plugin.json` 与索引条目一致、来源仓库真实存在且公开。它不代表对插件代码的安全审计。
@@ -73,7 +73,7 @@ scripts/track-releases.mjs # 追踪已收录插件和 Lithe-IDEA 组织 lit
7373
scripts/render-readme.mjs # 根据索引生成 README 的插件总览
7474
scripts/store.test.mjs # 校验脚本的测试(fixtures 复制自 Core 的插件契约)
7575
assets/ # README 用到的图片(无图标插件的默认图标)
76-
.github/workflows/ # validate(PR/推送/每周)、track-releases(每 6 小时,组织插件自动合入、组织外插件开 PR 审查)、sync-readme(main 更新后开 PR 同步 README)
76+
.github/workflows/ # validate(PR/推送/每周)、track-releases(每 6 小时追踪插件版本)、sync-readme(main 更新后开 PR 同步 README)
7777
```
7878

7979
## 本地校验

‎docs/maintainers.md‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ CI(`Validate index`)已经自动保证:
1010
`version`、`pluginAPIVersion`、`requires` 与索引一致,
1111
`vendor.signatureRequirement` 为 `"none"`,没有不安全的路径。
1212

13-
维护者人工确认(Lithe-IDEA 组织插件的 bot PR 由工作流自动合入,不走这份清单,见[自动追踪新版本](#自动追踪新版本)):
13+
维护者手动合并 PR 时逐项确认(包括 Store Bot 未能合并的组织插件 PR,见[自动追踪新版本](#自动追踪新版本)):
1414

1515
- [ ] `repository` 是公开仓库,有 README、许可证,看得出是该作者在维护;
1616
- [ ] 首次收录:`author` 与仓库所有者对应,名称不冒充其他项目或 Lithe 官方;
@@ -21,7 +21,7 @@ CI(`Validate index`)已经自动保证:
2121
bot 首次收录的组织插件(组织 PR 描述里的“首次收录”)合入后,维护者补做两件事:
2222

2323
- 检查仓库简介是否适合作为 `description`,仓库 topics 是否适合作为 `tags`,不合适就另提 PR 修改;
24-
- 另提 PR 补充 `icon`、`localizedDescriptions`。不要直接改 `bot/track-organization-releases`,下一轮扫描会从 main 重建这个分支。
24+
- 另提 PR 补充 `icon`、`localizedDescriptions`。下一次相同范围的追踪会从 main 重建对应的 bot 分支。
2525

2626
## 自动追踪新版本
2727

@@ -31,17 +31,17 @@ bot 首次收录的组织插件(组织 PR 描述里的“首次收录”)合
3131
[发布插件的首次收录](publishing.md#3-首次收录)。手动运行时指定的插件 ID 可以是已收录插件,
3232
也可以是组织中尚未收录的插件。
3333

34-
扫描按插件仓库的所有者分两轮,先组织插件、后组织外插件,每轮维护一个 bot PR:
34+
扫描按插件仓库的所有者分两轮,先组织插件、后组织外插件:
3535

3636
| | Lithe-IDEA 组织插件 | 组织外插件 |
3737
| --- | --- | --- |
3838
| 范围 | `repository` 属于 Lithe-IDEA 组织的已收录插件,以及新发现的组织 `lithe-plugin-*` 仓库 | 其他已收录插件;不会被自动首次收录 |
39-
| 分支 | `bot/track-organization-releases` | `bot/track-releases` |
40-
| 合入 | 校验通过后由工作流直接合入 main,不经人工审查 | 维护者按[审查清单](#审查清单)审查后合并 |
39+
| 全量扫描分支 | `bot/track-organization-releases` | `bot/track-releases` |
40+
| 合入 | 已配置的 Store Bot 在校验通过后尝试合并;缺少凭据或分支规则阻止合并时,由维护者审查后合并 | 维护者按[审查清单](#审查清单)审查后合并 |
4141

42-
两个 PR 都同时包含索引和重新生成的 README 总览,合入后不需要再等 `Sync README`。每轮扫描从 main 重建
43-
对应分支并更新 PR;某一轮没有发现 main 尚未收录的版本时,这一轮遗留的 PR 会被自动关闭
44-
(只指定一个插件的手动运行不会关闭 PR)。
42+
指定插件 ID 时,分支名会追加该 ID 的 SHA-256,PR 标题会显示插件 ID。重复追踪同一插件会更新其原 PR。
43+
定向扫描和全量扫描都从 main 重建各自的分支,PR 包含索引和重新生成的 README 总览。
44+
全量扫描没有发现新版本时会关闭对应的全量 PR。如果某个版本已通过全量 PR 合入,可以关闭相应的定向 PR。
4545

4646
组织插件的自动合入分三步:
4747

@@ -50,11 +50,11 @@ bot 首次收录的组织插件(组织 PR 描述里的“首次收录”)合
5050
(`gh pr merge --match-head-commit`),分支在校验之后被改动过,GitHub 就拒绝合并;
5151
3. 合并后删除分支。
5252

53-
没有配置 Lithe Store Bot,或者合并失败(例如 main 在扫描期间被更新并与 PR 冲突)时,工作流只给出警告,
54-
PR 保持打开,由维护者按审查清单审查后合并,下一轮扫描也会基于新的 main 重建它。
53+
没有配置完整的 Store Bot 凭据,或者合并失败(例如 main 的分支规则拒绝了合并)时,工作流会在合并步骤给出警告。
54+
PR 保持打开,由维护者按审查清单审查后合并。
5555
删除仓库变量 `STORE_BOT_APP_CLIENT_ID`,或者卸载 Lithe Store Bot,即可停止自动合入。
5656

57-
信任边界:在任一 Lithe-IDEA 组织插件仓库能发布 Release 的人,以及能在组织里创建公开
57+
启用并允许自动合并时,在任一 Lithe-IDEA 组织插件仓库能发布 Release 的人,以及能在组织里创建公开
5858
`lithe-plugin-*` 仓库的人,都可以不经 Store 维护者审查把插件发布到 Lithe Store。组织允许成员创建公开仓库时
5959
(Organization settings → Member privileges → Repository creation),每个组织成员都在这个范围内。
6060
授予组织成员身份或插件仓库写权限时按这个标准判断。

‎docs/publishing.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ shasum -a 256 zig-support-2.0.0-darwin-arm64.zip
8282

8383
Lithe-IDEA 组织下名为 `lithe-plugin-*` 的公开仓库(已退役的文档仓库 `lithe-plugin-docs` 除外,它不发布插件)
8484
不需要手工提交首次收录 PR。`Track plugin releases` 发现这类仓库还没收录、并且已经有带插件包的
85-
正式 Release 时,会把它连同全部正式版本一起放进组织插件的 bot PR,校验通过后自动合入 main,
85+
正式 Release 时,会把它连同全部正式版本一起放进组织插件的 bot PR。Store Bot 可用且分支规则允许时会自动合入 main,其他情况由维护者合并。
8686
条目按以下来源生成:
8787

8888
| 字段 | 来源 |
@@ -95,7 +95,7 @@ Lithe-IDEA 组织下名为 `lithe-plugin-*` 的公开仓库(已退役的文档
9595

9696
仓库是私有、已归档或 fork,仓库没有简介,GitHub 识别不出许可证,包内 `plugin.json` 缺字段或 ID 不符合索引规则,
9797
或者 ID 已经被别的条目占用时,自动收录会跳过该仓库,并在工作流日志里写明原因。自动生成的条目
98-
没有 `icon` 和 `localizedDescriptions`,自动合入后由维护者另提 PR 补充。和版本追踪一样,只发布过
98+
没有 `icon` 和 `localizedDescriptions`,合入后由维护者另提 PR 补充。和版本追踪一样,只发布过
9999
pre-release 的仓库不会被收录。
100100

101101
其他仓库按下面的步骤收录:
@@ -169,7 +169,7 @@ pre-release 的仓库不会被收录。
169169
把新版本写进索引(版本号、`pluginAPIVersion`、`requires` 取自包内 `plugin.json`,
170170
能力表按键排序写入;发布日期取 Release 发布时间,SHA-256 由 CI 计算),
171171
然后按插件仓库的所有者开 PR:Lithe-IDEA 组织插件进 `chore(index): 追踪 Lithe-IDEA 组织插件新版本`,
172-
校验通过后由工作流直接合入;其他插件进 `chore(index): 追踪组织外插件新版本`。
172+
校验通过后由已配置的 Store Bot 尝试合并,PR 保持打开时由维护者审查后合并;其他插件进 `chore(index): 追踪组织外插件新版本`。
173173
3. 组织外插件的 PR 由维护者审查后合并。新版本进入 main 后,Lithe 用户刷新插件市场就能看到更新。
174174

175175
想更快上线,可以在 issue 里请维护者手动触发工作流,或者自己提 PR 在 `versions` 里加一项

‎scripts/store.test.mjs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { join } from "node:path";
77
import { test } from "node:test";
88
import { END, START, categoryOf, renderOverview, renderReadme, systemsOf, truncate } from "./render-readme.mjs";
99
import {
10-
addVersion, discoverPlugins, isOrganizationEntry, platformsForAsset, trackIndex, unlistedPluginRepositories,
10+
addVersion, discoverPlugins, isOrganizationEntry, platformsForAsset, trackIndex, trackingBranch, unlistedPluginRepositories,
1111
versionFromRelease,
1212
} from "./track-releases.mjs";
1313
import {
@@ -400,6 +400,22 @@ function scopedTracking() {
400400
return { index, archiveIO: { ...fixture, request }, requests };
401401
}
402402

403+
test("targeted scans keep separate PR heads across plugins, full scans and scopes", () => {
404+
const branches = new Set();
405+
for (const scope of ["organization", "external"]) {
406+
const full = trackingBranch(scope, "");
407+
assert.equal(full, scope === "organization" ? "bot/track-organization-releases" : "bot/track-releases");
408+
branches.add(full);
409+
for (const id of ["io.example.one", "io.example.two..lock"]) {
410+
const branch = trackingBranch(scope, id);
411+
assert.equal(trackingBranch(scope, id), branch);
412+
execFileSync("git", ["check-ref-format", "--branch", branch], { timeout: 5_000 });
413+
branches.add(branch);
414+
}
415+
}
416+
assert.equal(branches.size, 6);
417+
});
418+
403419
test("scoped tracking separates organization plugins from external plugins", { timeout: 5_000 }, async () => {
404420
const organization = scopedTracking();
405421
const organizationRun = await trackIndex(organization.index, { ...organization.archiveIO, scope: "organization" });

‎scripts/track-releases.mjs‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Finds GitHub Releases of listed plugins that are not in the index yet and
33
// adds them as new versions. The scheduled `track-releases` workflow runs this
44
// once per scope and opens one pull request per scope: `organization` covers
5-
// plugins whose repository belongs to the Lithe-IDEA organization and is merged
6-
// by the workflow after the archives are verified; `external` covers every other
5+
// plugins whose repository belongs to the Lithe-IDEA organization and may be merged
6+
// by the Store Bot after archive verification; `external` covers every other
77
// plugin and waits for a maintainer review.
88
//
99
// Public repositories of the Lithe-IDEA organization whose names start with
@@ -33,7 +33,17 @@ export const DISCOVERY_OWNER = "Lithe-IDEA";
3333
export const DISCOVERY_PREFIX = "lithe-plugin-";
3434
// Organization repositories that carry the prefix but do not publish a plugin.
3535
export const DISCOVERY_EXCLUDED = new Set(["lithe-plugin-docs"]);
36-
export const SCOPES = ["organization", "external"];
36+
const TRACKING_BRANCHES = {
37+
organization: "bot/track-organization-releases",
38+
external: "bot/track-releases",
39+
};
40+
export const SCOPES = Object.keys(TRACKING_BRANCHES);
41+
42+
export function trackingBranch(scope, plugin) {
43+
const base = TRACKING_BRANCHES[scope];
44+
// Even a valid marketplace ID can contain ".." or end in ".lock".
45+
return plugin ? `${base}-${createHash("sha256").update(plugin).digest("hex")}` : base;
46+
}
3747

3848
export const KNOWN_ARCHITECTURES = { darwin: ["arm64", "x64"], windows: ["x64", "arm64"], linux: ["x64", "arm64"] };
3949
const ASSET_PLATFORM = /-(darwin|windows|linux)(?:-(arm64|x64))?\.zip$/;
@@ -364,6 +374,7 @@ async function main(argv) {
364374
const summary = added.join(", ");
365375
const output = `added=${added.length}\nsummary=${summary}\nnew_plugins=${newPlugins.join(", ")}\n`;
366376
writeFileSync(process.env.GITHUB_OUTPUT, output, { flag: "a" });
377+
if (scope) writeFileSync(process.env.GITHUB_OUTPUT, `branch=${trackingBranch(scope, onlyPlugin)}\n`, { flag: "a" });
367378
}
368379
return 0;
369380
}

0 commit comments

Comments
 (0)