Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions .github/workflows/track-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ name: Track plugin releases
# `lithe-plugin-docs`, and adds the versions and plugins not yet in the index.
# Plugin authors only need to publish a release that follows docs/publishing.md.
#
# The scan runs once per scope, and each scope keeps its own pull request:
# Full scans keep one pull request per scope. Filtered scans keep one per scope and plugin.
#
# - organization: plugins whose repository belongs to the Lithe-IDEA organization,
# including first listings. After the archives are verified, the workflow
# merges the pull request itself with a token of the Lithe Store Bot GitHub
# App, the only bot that the "Only owners merge main" ruleset lets through.
# including first listings. After verification, the Store Bot attempts a merge
# if configured. A maintainer merges when the bot cannot.
# - external: every other plugin. The pull request waits for a maintainer
# review, and this scope never receives the app token.
on:
Expand Down Expand Up @@ -47,21 +46,19 @@ jobs:
matrix:
include:
- scope: organization
branch: bot/track-organization-releases
title: "chore(index): 追踪 Lithe-IDEA 组织插件新版本"
- scope: external
branch: bot/track-releases
title: "chore(index): 追踪组织外插件新版本"
env:
SCOPE: ${{ matrix.scope }}
BRANCH: ${{ matrix.branch }}
HAS_STORE_BOT_APP: ${{ matrix.scope == 'organization' && vars.STORE_BOT_APP_CLIENT_ID != '' && secrets.STORE_BOT_APP_PRIVATE_KEY != '' }}
TITLE: ${{ matrix.title }}
steps:
# Only the organization scope may merge into main, so only it asks for the
# app token. Without the app, both scopes fall back to the tokens below.
- name: Create the Lithe Store Bot token
id: bot
if: matrix.scope == 'organization' && vars.STORE_BOT_APP_CLIENT_ID != ''
if: env.HAS_STORE_BOT_APP == 'true'
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.STORE_BOT_APP_CLIENT_ID }}
Expand Down Expand Up @@ -95,6 +92,7 @@ jobs:
- name: Close the obsolete pull request
if: steps.track.outputs.added == '0' && inputs.plugin == ''
env:
BRANCH: ${{ steps.track.outputs.branch }}
GH_TOKEN: ${{ steps.bot.outputs.token || secrets.STORE_BOT_TOKEN || github.token }}
run: |
number=$(gh pr list --head "$BRANCH" --state open --json number -q '.[0].number')
Expand All @@ -119,6 +117,8 @@ jobs:
id: pr
if: steps.track.outputs.added != '0'
env:
BRANCH: ${{ steps.track.outputs.branch }}
PLUGIN: ${{ inputs.plugin }}
GH_TOKEN: ${{ steps.bot.outputs.token || secrets.STORE_BOT_TOKEN || github.token }}
SUMMARY: ${{ steps.track.outputs.summary }}
NEW_PLUGINS: ${{ steps.track.outputs.new_plugins }}
Expand All @@ -135,8 +135,11 @@ jobs:

list=$(echo "$SUMMARY" | tr ',' '\n' | sed 's/^ */- /')
checks="已校验 SHA-256 与包内 plugin.json(id、version、pluginAPIVersion、signatureRequirement),README 总览已一并重新生成。"
if [ "$SCOPE" = organization ]; then
review="这些插件的仓库属于 Lithe-IDEA 组织,工作流会在校验通过后直接合入 main。如果这个 PR 仍处于打开状态,说明自动合入没有成功(原因见工作流日志),请维护者按 docs/maintainers.md 的清单审查后合并。"
if [ -n "$PLUGIN" ]; then TITLE="$TITLE ($PLUGIN)"; fi
if [ "$HAS_STORE_BOT_APP" = true ]; then
review="Store Bot 将尝试合并本次校验的提交。若工作流结束后 PR 仍打开,请维护者查看合并步骤的日志,按 docs/maintainers.md 的清单审查后合并。"
elif [ "$SCOPE" = organization ]; then
review="此仓库未配置完整的 Store Bot 凭据,请维护者按 docs/maintainers.md 的清单审查后合并。"
else
review="这些插件来自 Lithe-IDEA 组织以外的仓库,维护者请按 docs/maintainers.md 的清单审查后合并。"
fi
Expand All @@ -159,6 +162,7 @@ jobs:
- name: Merge the organization pull request
if: matrix.scope == 'organization' && steps.track.outputs.added != '0'
env:
BRANCH: ${{ steps.track.outputs.branch }}
# Only the app can pass the ruleset, so this step never falls back to another token.
GH_TOKEN: ${{ steps.bot.outputs.token }}
NUMBER: ${{ steps.pr.outputs.number }}
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
| 我想… | 怎么做 |
| --- | --- |
| 收录自己的插件 | 读 [docs/publishing.md](docs/publishing.md),提 PR 或开“插件收录申请” issue;Lithe-IDEA 组织的 `lithe-plugin-*` 仓库由 bot 自动收录(见 [首次收录](docs/publishing.md#3-首次收录)) |
| 发布插件新版本 | 在自己仓库发布 Release 即可,bot 会自动开 PR;Lithe-IDEA 组织插件校验通过后自动合入(见 [发布新版本](docs/publishing.md#4-发布新版本)) |
| 发布插件新版本 | 在自己仓库发布 Release 即可,bot 会自动开 PR(见 [发布新版本](docs/publishing.md#4-发布新版本)) |
| 修改插件信息 | 提 PR 修改 `lithe-plugin-index.json` 中自己的条目(含 `icon`) |
| 报告有问题的插件 | 开“报告插件问题” issue;安全问题请勾选“安全问题”,维护者会优先处理 |
| 改进脚本、CI 或文档 | 直接提 PR,并运行 `node --test scripts/store.test.mjs` |
Expand Down Expand Up @@ -47,7 +47,7 @@ Lithe 不再区分官方插件和普通插件:本仓库收录的每个插件
| --- | --- | --- |
| 范围 | Lithe-IDEA 组织下的公开 `lithe-plugin-*` 仓库(已退役的文档仓库 `lithe-plugin-docs` 除外) | 其他公开 GitHub 仓库 |
| 首次收录 | bot 发现带插件包的正式 Release 后自动收录,不需要提交 PR | 提 PR 或开“插件收录申请” issue,维护者按[审查清单](docs/maintainers.md#审查清单)审核后合并 |
| 新版本 | bot 开 PR,校验通过后自动合入 | bot 开 PR,维护者审核后合并 |
| 新版本 | bot 开 PR,校验通过后由已配置的 Store Bot 尝试合并,仍打开的 PR 由维护者审核后合并 | bot 开 PR,维护者审核后合并 |

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

## 本地校验
Expand Down
22 changes: 11 additions & 11 deletions docs/maintainers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CI(`Validate index`)已经自动保证:
`version`、`pluginAPIVersion`、`requires` 与索引一致,
`vendor.signatureRequirement` 为 `"none"`,没有不安全的路径。

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

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

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

## 自动追踪新版本

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

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

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

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

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

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

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

信任边界:在任一 Lithe-IDEA 组织插件仓库能发布 Release 的人,以及能在组织里创建公开
启用并允许自动合并时,在任一 Lithe-IDEA 组织插件仓库能发布 Release 的人,以及能在组织里创建公开
`lithe-plugin-*` 仓库的人,都可以不经 Store 维护者审查把插件发布到 Lithe Store。组织允许成员创建公开仓库时
(Organization settings → Member privileges → Repository creation),每个组织成员都在这个范围内。
授予组织成员身份或插件仓库写权限时按这个标准判断。
Expand Down
6 changes: 3 additions & 3 deletions docs/publishing.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ shasum -a 256 zig-support-2.0.0-darwin-arm64.zip

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

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

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

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

想更快上线,可以在 issue 里请维护者手动触发工作流,或者自己提 PR 在 `versions` 里加一项
Expand Down
18 changes: 17 additions & 1 deletion scripts/store.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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, unlistedPluginRepositories,
addVersion, discoverPlugins, isOrganizationEntry, platformsForAsset, trackIndex, trackingBranch, unlistedPluginRepositories,
versionFromRelease,
} from "./track-releases.mjs";
import {
Expand Down Expand Up @@ -400,6 +400,22 @@ function scopedTracking() {
return { index, archiveIO: { ...fixture, request }, requests };
}

test("targeted scans keep separate PR heads across plugins, full scans and scopes", () => {
const branches = new Set();
for (const scope of ["organization", "external"]) {
const full = trackingBranch(scope, "");
assert.equal(full, scope === "organization" ? "bot/track-organization-releases" : "bot/track-releases");
branches.add(full);
for (const id of ["io.example.one", "io.example.two..lock"]) {
const branch = trackingBranch(scope, id);
assert.equal(trackingBranch(scope, id), branch);
execFileSync("git", ["check-ref-format", "--branch", branch], { timeout: 5_000 });
branches.add(branch);
}
}
assert.equal(branches.size, 6);
});

test("scoped tracking separates organization plugins from external plugins", { timeout: 5_000 }, async () => {
const organization = scopedTracking();
const organizationRun = await trackIndex(organization.index, { ...organization.archiveIO, scope: "organization" });
Expand Down
17 changes: 14 additions & 3 deletions scripts/track-releases.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Finds GitHub Releases of listed plugins that are not in the index yet and
// adds them as new versions. The scheduled `track-releases` workflow runs this
// once per scope and opens one pull request per scope: `organization` covers
// plugins whose repository belongs to the Lithe-IDEA organization and is merged
// by the workflow after the archives are verified; `external` covers every other
// plugins whose repository belongs to the Lithe-IDEA organization and may be merged
// by the Store Bot after archive verification; `external` covers every other
// plugin and waits for a maintainer review.
//
// Public repositories of the Lithe-IDEA organization whose names start with
Expand Down Expand Up @@ -33,7 +33,17 @@ export const DISCOVERY_OWNER = "Lithe-IDEA";
export const DISCOVERY_PREFIX = "lithe-plugin-";
// Organization repositories that carry the prefix but do not publish a plugin.
export const DISCOVERY_EXCLUDED = new Set(["lithe-plugin-docs"]);
export const SCOPES = ["organization", "external"];
const TRACKING_BRANCHES = {
organization: "bot/track-organization-releases",
external: "bot/track-releases",
};
export const SCOPES = Object.keys(TRACKING_BRANCHES);

export function trackingBranch(scope, plugin) {
const base = TRACKING_BRANCHES[scope];
// Even a valid marketplace ID can contain ".." or end in ".lock".
return plugin ? `${base}-${createHash("sha256").update(plugin).digest("hex")}` : base;
}

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