docs(contributing): describe pointing main at dest
Promote no longer opens a merge PR. pnpm release waits for origin/main to match dest before tagging.
This commit is contained in:
2 files changed
+81
-97
No files matched your search
+31
-40
@@ -33,7 +33,7 @@ SnowLuma 处于开发早期,迭代速度很快,**接口与目录结构随时
|
|||||||
| `packages/websocket` | WebSocket 实现 |
|
| `packages/websocket` | WebSocket 实现 |
|
||||||
| `packages/webui` | 基于 Vite + React 的前端控制台 |
|
| `packages/webui` | 基于 Vite + React 的前端控制台 |
|
||||||
| `tools/` | 版本管理、发布脚本 |
|
| `tools/` | 版本管理、发布脚本 |
|
||||||
| `.github/workflows/` | CI / 发布 / 自动合并工作流 |
|
| `.github/workflows/` | CI / 发布 / Promote 工作流 |
|
||||||
|
|
||||||
入口在 `packages/core/src/index.ts`,整体架构在 `packages/core/src/bridge/` 下能看出大致脉络。
|
入口在 `packages/core/src/index.ts`,整体架构在 `packages/core/src/bridge/` 下能看出大致脉络。
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ pnpm dev:web # webui
|
|||||||
|
|
||||||
### 1. 创建分支
|
### 1. 创建分支
|
||||||
|
|
||||||
请基于 `dev` 创建分支,不是 `main`。`main` 是受保护的稳定分支,PR 也不要直接提到 `main`。
|
请基于 `dev` 创建分支,不是 `main`。`main` 是发布指针,只由维护者的 Promote 更新,PR 不要提到 `main`。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git checkout dev
|
git checkout dev
|
||||||
@@ -133,7 +133,7 @@ refactor(bridge): extract BridgeInterface as the OneBot-facing seam
|
|||||||
docs: clarify dev environment setup steps
|
docs: clarify dev environment setup steps
|
||||||
```
|
```
|
||||||
|
|
||||||
> ⚠️ **请不要**在你的提交信息里使用 `[merge]` 前缀或 `chore(release):` 前缀 —— 这两个前缀是维护者用来触发自动合并到 `main` 的,会让你的 PR 行为异常。详见后文 [维护者参考](#维护者参考release--自动合并流程)。
|
> ⚠️ **请不要**在你的提交信息里使用 `[merge]` 前缀或 `chore(release):` 前缀 —— 这两个前缀是维护者用来把 `main` 指到 `dev` 的,会让你的 PR 行为异常。详见后文 [维护者参考](#维护者参考release--promote)。
|
||||||
|
|
||||||
### 4. 推送并发起 PR
|
### 4. 推送并发起 PR
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ git push origin fix/onebot-mention-encoding
|
|||||||
|
|
||||||
- 维护者会在能腾出时间时来 review。如果一周内没有任何回应,欢迎在 PR 里 @ 一下,或者去社群里提醒。
|
- 维护者会在能腾出时间时来 review。如果一周内没有任何回应,欢迎在 PR 里 @ 一下,或者去社群里提醒。
|
||||||
- review 意见请尽量在同一个 PR 内修改,避免反复关闭重开。
|
- review 意见请尽量在同一个 PR 内修改,避免反复关闭重开。
|
||||||
- 合并方式由维护者决定,通常是 squash merge 到 `dev`。**`main` 由维护者通过自动化工作流统一从 `dev` 合入**,你不需要操心 `main`。
|
- 合并方式由维护者决定,通常是 squash merge 到 `dev`。**`main` 由维护者通过 Promote 指到当时的 `dev`**,你不需要操心 `main`。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -191,28 +191,30 @@ git push origin fix/onebot-mention-encoding
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 维护者参考:release & 自动合并流程
|
## 维护者参考:release & Promote
|
||||||
|
|
||||||
> 以下内容主要写给具备 `main` 推送 / 发版权限的维护者。普通贡献者只需要把 PR 提到 `dev`,不需要关心这一节。
|
> 以下内容主要写给具备发版权限的维护者。普通贡献者只需要把 PR 提到 `dev`,不需要关心这一节。
|
||||||
|
|
||||||
### 分支模型
|
### 分支模型
|
||||||
|
|
||||||
SnowLuma 使用 **`main` + `dev`** 双分支模型:
|
SnowLuma 使用 **`main` + `dev`** 双分支模型:
|
||||||
|
|
||||||
- **`main`** — 受保护的稳定分支,仅接收来自 `dev` 的合并 PR。**禁止直接 push**。
|
- **`dev`** — 日常开发分支。所有功能、修复、文档变更都先进入 `dev`。
|
||||||
- **`dev`** — 日常开发分支。所有功能、修复、文档变更都先合入 `dev`。
|
- **`main`** — 发布指针,应与某次 Promote 当时的 `dev` 尖端是**同一个提交**。不要直接 push,也不要往 `main` 开 PR(CI 会拒)。
|
||||||
- **`native/auto-update-*`** — 由 `SnowLuma Bot` 自动创建的原生产物更新分支(来自 `SnowLumaNative`,不需要手动维护)。
|
- **`native/auto-update-*`** — 由 `SnowLuma Bot` 自动创建的原生产物更新分支(来自 `SnowLumaNative`,不需要手动维护)。
|
||||||
|
|
||||||
### 把 `dev` 合并到 `main`
|
### 把 `main` 指到 `dev`
|
||||||
|
|
||||||
工作流 `.github/workflows/promote-dev-to-main.yml` 会以 `SnowLuma Bot` 身份开 / 更新一个 `dev → main` 的 PR,并可选地自动合并。无论用哪种触发方式,工作流都会调用 `gh pr merge --auto`:**只有 `main` 分支保护中所有 required status checks(typecheck + 各架构 build)都通过后,机器人才会真正合并**。失败的工作流会卡住合并。
|
工作流 `.github/workflows/promote-dev-to-main.yml` 以 `SnowLuma Bot` 身份把 `main` 指到当前 `dev` 尖端,**不再开 merge PR**。`main` 上若有 `dev` 还没有的独有改动,Promote 会失败,需要先把那些改动收回 `dev`。
|
||||||
|
|
||||||
|
推到 `dev` 仍会跑 `dev-build.yml`。Promote **不等**那组检查;发版请用下面的 `pnpm release`,它会在本地先跑完整 CI。
|
||||||
|
|
||||||
#### 1. 提交信息前缀(推荐日常使用)
|
#### 1. 提交信息前缀(推荐日常使用)
|
||||||
|
|
||||||
向 `dev` push 一个提交,提交信息**以**以下任一前缀**开头**即触发(不区分大小写):
|
向 `dev` push 一个提交,提交信息**以**以下任一前缀**开头**即触发(不区分大小写):
|
||||||
|
|
||||||
- `[merge]` — 例如 `[merge] fix: hotfix for OneBot mention`
|
- `[merge]` — 例如 `[merge] fix: hotfix for OneBot mention`
|
||||||
- `chore(release):` — 例如 `chore(release): v1.7.0`,符合 conventional commits 的发版习惯
|
- `chore(release):` — 例如 `chore(release): v1.7.0`,符合 conventional commits 的发版习惯。**只许用在真正的版本 bump**,不要写进普通 CI / 工具提交。
|
||||||
|
|
||||||
> 是**前缀**匹配,不是任意位置。`fix: something [merge]` 不会触发,必须把 `[merge]` 写在最前面。
|
> 是**前缀**匹配,不是任意位置。`fix: something [merge]` 不会触发,必须把 `[merge]` 写在最前面。
|
||||||
|
|
||||||
@@ -220,38 +222,22 @@ SnowLuma 使用 **`main` + `dev`** 双分支模型:
|
|||||||
|
|
||||||
任何符合 `chore.*` 的 tag(如 `chore.merge-20240509`、`chore.promote-v1.7.0`)被推送时也会触发:
|
任何符合 `chore.*` 的 tag(如 `chore.merge-20240509`、`chore.promote-v1.7.0`)被推送时也会触发:
|
||||||
|
|
||||||
- `chore.*` → 仅触发 `promote-dev-to-main.yml`(开 PR,自动合并)
|
- `chore.*` → 仅触发 `promote-dev-to-main.yml`(把 `main` 指到 `dev`)
|
||||||
- `v*` → 仅触发 `release.yml`(构建发布产物)
|
- `v*` → 仅触发 `release.yml`(构建发布产物)
|
||||||
|
|
||||||
推荐流程:先用 `chore.*` tag 把 `dev` 合入 `main`,待合并完成后再在 `main` 上打 `v*` tag 触发发布。这样 `release.yml` 始终基于已过完所有检查的 `main` HEAD 构建。
|
推荐流程:用 `pnpm release`(或先 Promote,再确认 `origin/main` 已等于 `dev` 尖端)之后,在 `main` 上打 `v*` tag。这样 `release.yml` 始终基于当时的 `main` HEAD 构建。
|
||||||
|
|
||||||
#### 3. 手动触发
|
#### 3. 手动触发
|
||||||
|
|
||||||
打开仓库 Actions 页面 → `Promote Dev to Main` → `Run workflow`。可选输入:
|
打开仓库 Actions 页面 → `Promote Dev to Main` → `Run workflow`。没有 merge 策略选项;跑起来就是一次指针更新。
|
||||||
|
|
||||||
- `auto_merge`:是否启用 auto-merge(默认 `true`)。
|
### 不要给 `main` 套「必须走 PR」
|
||||||
- `merge_method`:`merge` / `squash` / `rebase`(默认 `merge`)。
|
|
||||||
|
|
||||||
### 启用 `main` 分支保护(必做)
|
Promote 不通过 PR 更新 `main`。如果给 `main` 打开 **Require a pull request before merging** 或禁止更新引用,Promote 会失效。
|
||||||
|
|
||||||
仓库管理员需要在 GitHub 上为 `main` 配置规则集(Repository Rules)或经典分支保护,至少满足:
|
可以限制删除 `main`。外来 PR 必须打 `dev`;打到 `main` 的 PR 会被 `main-pr-target-guard.yml` 拒绝。
|
||||||
|
|
||||||
1. **Settings → Rules → Rulesets**(推荐)或 **Settings → Branches → Branch protection rules**。
|
本地若已经 checkout 过旧的 `main`,Promote 之后可能无法快进,对齐 `origin/main` 即可。
|
||||||
2. 选择 `main` 作为目标分支。
|
|
||||||
3. 勾选:
|
|
||||||
- **Restrict deletions** — 禁止删除 `main`。
|
|
||||||
- **Require a pull request before merging** — 所有合并必须走 PR。
|
|
||||||
- **Block force pushes** — 禁止强推。
|
|
||||||
- **Require status checks to pass before merging(必勾)** — 把以下来自 `dev-build.yml` 的 check 全部加为 required:
|
|
||||||
- `typecheck`
|
|
||||||
- `build (win-x64)`
|
|
||||||
- `build (linux-x64)`
|
|
||||||
- `build (linux-arm64)`
|
|
||||||
- **Require branches to be up to date before merging** — 保证 PR 合并前已 rebase 过最新 `main`。
|
|
||||||
4. 在 **Bypass list / Allow specified actors to bypass** 中加入 `SnowLuma Bot` GitHub App。这样 `gh pr merge --auto` 才能在所有 required check 通过后由机器人自动完成合并;否则 PR 会一直卡在 auto-merge 等待人工 review。
|
|
||||||
5. **不要**把任何用户加入 push 白名单,确保「禁止向 `main` 直接提交」的约束生效。第一次设置完后,连仓库管理员也只能通过 PR 改 `main`。
|
|
||||||
|
|
||||||
效果:任何对 `dev` 的推送都会先在 `dev-build.yml` 上跑 typecheck + 三个架构的 build;只有全部成功,promote 工作流的 `--auto` 合并才会真正发生。失败时 PR 会保留在 open 状态,修复后再次推到 `dev` 即可重新触发检查。
|
|
||||||
|
|
||||||
### 必需的 Secrets
|
### 必需的 Secrets
|
||||||
|
|
||||||
@@ -260,25 +246,30 @@ SnowLuma 使用 **`main` + `dev`** 双分支模型:
|
|||||||
- `SNOWLUMA_BOT_APP_ID` — 数字类型的 App ID。
|
- `SNOWLUMA_BOT_APP_ID` — 数字类型的 App ID。
|
||||||
- `SNOWLUMA_BOT_PRIVATE_KEY` — 该 App 的 PEM 私钥。
|
- `SNOWLUMA_BOT_PRIVATE_KEY` — 该 App 的 PEM 私钥。
|
||||||
|
|
||||||
App 必须在本仓库已安装,且授予 **Contents: Read+Write**、**Pull requests: Read+Write**。
|
App 必须在本仓库已安装,且授予 **Contents: Read+Write**。
|
||||||
|
|
||||||
### 本地工作流速查(维护者)
|
### 本地工作流速查(维护者)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 把 dev 合入 main(三选一)
|
# 推荐:一条命令走完 bump → Promote → 等 main 跟上 → 打 v* tag
|
||||||
|
pnpm release 1.7.0
|
||||||
|
|
||||||
|
# 只要把 main 指到 dev(三选一)
|
||||||
|
|
||||||
# 方式 A:commit-msg 前缀
|
# 方式 A:commit-msg 前缀
|
||||||
git commit -m "chore(release): v1.7.0" # 或 "[merge] fix: hotfix"
|
git commit -m "chore(release): v1.7.0" # 或 "[merge] fix: hotfix"
|
||||||
git push # → 触发 promote-dev-to-main
|
git push # → 触发 promote-dev-to-main
|
||||||
|
|
||||||
# 方式 B:chore.* 合并 tag(与发布 tag 解耦)
|
# 方式 B:chore.* tag(与发布 tag 解耦)
|
||||||
git tag chore.merge-20240509 # 或 chore.promote-v1.7.0 等
|
git tag chore.merge-20240509
|
||||||
git push origin chore.merge-20240509 # → 触发 promote-dev-to-main
|
git push origin chore.merge-20240509 # → 触发 promote-dev-to-main
|
||||||
|
|
||||||
# 方式 C:在 Actions 页面手动 Run workflow
|
# 方式 C:在 Actions 页面手动 Run workflow
|
||||||
|
|
||||||
# 合并完成后,发布版本(在 main 上打 v* tag)
|
# Promote 完成后,若要自己打发布 tag
|
||||||
git checkout main && git pull
|
git fetch origin
|
||||||
|
git switch main
|
||||||
|
git merge --ff-only origin/main # 对不齐就 reset 到 origin/main
|
||||||
git tag v1.7.0
|
git tag v1.7.0
|
||||||
git push origin v1.7.0 # → 仅触发 release.yml
|
git push origin v1.7.0 # → 仅触发 release.yml
|
||||||
```
|
```
|
||||||
|
|||||||
+50
-57
@@ -13,14 +13,13 @@
|
|||||||
// `.github/workflows/ci.yml`. Fail here instead of after the bump.
|
// `.github/workflows/ci.yml`. Fail here instead of after the bump.
|
||||||
// 3. `pnpm bump <version>` (writes every package.json).
|
// 3. `pnpm bump <version>` (writes every package.json).
|
||||||
// 4. Commit `chore(release): vX.Y.Z` — that prefix triggers the
|
// 4. Commit `chore(release): vX.Y.Z` — that prefix triggers the
|
||||||
// Promote workflow, which opens (or updates) the dev→main PR and
|
// Promote workflow, which points `main` at the dev tip. Skipped
|
||||||
// auto-merges if the GitHub setting allows. Skipped when HEAD is
|
// when HEAD is already that commit.
|
||||||
// already that commit.
|
|
||||||
// 5. Push to origin/dev (retries transient HTTPS / TLS failures).
|
// 5. Push to origin/dev (retries transient HTTPS / TLS failures).
|
||||||
// 6. (Unless `--no-wait`) poll the Promote PR via `gh` until it
|
// 6. (Unless `--no-wait`) poll until `origin/main` equals the dev
|
||||||
// merges, then fetch and fast-forward `main` to `origin/main`,
|
// tip we just pushed, then fetch and fast-forward `main` to
|
||||||
// create `vX.Y.Z` tag, push it — that triggers `release.yml`.
|
// `origin/main`, create `vX.Y.Z` tag, push it — that triggers
|
||||||
// Fetch / tag push also retry.
|
// `release.yml`. Fetch / tag push also retry.
|
||||||
// 7. Switch back to `dev` so the next `git log` view is back where
|
// 7. Switch back to `dev` so the next `git log` view is back where
|
||||||
// you were.
|
// you were.
|
||||||
//
|
//
|
||||||
@@ -133,7 +132,7 @@ function info(msg) { console.log(`\x1b[36mi\x1b[0m ${msg}`); }
|
|||||||
function warn(msg) { console.log(`\x1b[33m!\x1b[0m ${msg}`); }
|
function warn(msg) { console.log(`\x1b[33m!\x1b[0m ${msg}`); }
|
||||||
|
|
||||||
function printManualFinish() {
|
function printManualFinish() {
|
||||||
info('Once the Promote PR merges, finish with:');
|
info('Once origin/main equals the dev tip, finish with:');
|
||||||
info(` pnpm release ${version}`);
|
info(` pnpm release ${version}`);
|
||||||
info('or by hand:');
|
info('or by hand:');
|
||||||
info(' git fetch origin refs/heads/main:refs/remotes/origin/main');
|
info(' git fetch origin refs/heads/main:refs/remotes/origin/main');
|
||||||
@@ -237,63 +236,57 @@ function bumpAndPushDev() {
|
|||||||
ok(`pushed to origin/dev — Promote workflow should kick off shortly`);
|
ok(`pushed to origin/dev — Promote workflow should kick off shortly`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ───────────── step 5: wait for Promote PR + tag main ─────────────
|
// ───────────── step 5: wait for main to match dev, then tag ─────────────
|
||||||
|
|
||||||
|
function promoteRunFailed(expectedSha) {
|
||||||
|
if (!which('gh')) return null;
|
||||||
|
try {
|
||||||
|
const list = shCapture('gh run list --workflow=promote-dev-to-main.yml --limit 8 --json conclusion,headSha,url,status');
|
||||||
|
const runs = JSON.parse(list);
|
||||||
|
return runs.find((run) => run.headSha === expectedSha && run.conclusion === 'failure') ?? null;
|
||||||
|
} catch (error) {
|
||||||
|
warn(`gh run list failed: ${error.message}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function waitAndTag() {
|
async function waitAndTag() {
|
||||||
if (!which('gh')) {
|
const expectedSha = dryRun ? 'dry-run' : shCapture('git rev-parse dev');
|
||||||
warn('`gh` CLI not found — skipping auto-tag.');
|
|
||||||
printManualFinish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
info('waiting for the Promote PR (head: dev → base: main) to merge...');
|
if (dryRun) {
|
||||||
info('press Ctrl-C if you want to handle main / tag manually.');
|
info(`would wait until origin/main equals dev @ ${expectedSha.slice(0, 12)}`);
|
||||||
|
} else {
|
||||||
|
info(`waiting until origin/main equals dev @ ${expectedSha.slice(0, 12)}...`);
|
||||||
|
info('press Ctrl-C if you want to handle main / tag manually.');
|
||||||
|
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
const TIMEOUT_MS = 30 * 60 * 1000; // 30 min hard cap
|
const TIMEOUT_MS = 30 * 60 * 1000;
|
||||||
const POLL_MS = 15 * 1000;
|
const POLL_MS = 15 * 1000;
|
||||||
|
let promoted = false;
|
||||||
|
|
||||||
let prNumber = null;
|
while (Date.now() - startedAt < TIMEOUT_MS) {
|
||||||
while (Date.now() - startedAt < TIMEOUT_MS) {
|
const failed = promoteRunFailed(expectedSha);
|
||||||
if (!prNumber) {
|
if (failed) {
|
||||||
try {
|
console.error(`Promote failed for ${expectedSha.slice(0, 12)}: ${failed.url}`);
|
||||||
const list = shCapture(`gh pr list --base main --head dev --state all --json number,mergedAt,state --limit 5`);
|
process.exit(1);
|
||||||
const prs = JSON.parse(list);
|
|
||||||
// Pick the newest one that's open or merged after we pushed.
|
|
||||||
const fresh = prs.find(p => p.state === 'OPEN' || (p.mergedAt && Date.parse(p.mergedAt) > startedAt - 2 * POLL_MS));
|
|
||||||
if (fresh) {
|
|
||||||
prNumber = fresh.number;
|
|
||||||
info(`tracking PR #${prNumber}`);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
warn(`gh pr list failed: ${e.message}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shRetry('git fetch origin refs/heads/main:refs/remotes/origin/main --quiet');
|
||||||
|
const mainSha = shCapture('git rev-parse origin/main');
|
||||||
|
if (mainSha === expectedSha) {
|
||||||
|
ok(`origin/main is dev @ ${expectedSha.slice(0, 12)}`);
|
||||||
|
promoted = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prNumber) {
|
if (!promoted) {
|
||||||
try {
|
warn('30-minute timeout reached without origin/main matching dev.');
|
||||||
const view = shCapture(`gh pr view ${prNumber} --json state,mergedAt`);
|
printManualFinish();
|
||||||
const pr = JSON.parse(view);
|
return;
|
||||||
if (pr.state === 'MERGED') {
|
|
||||||
ok(`PR #${prNumber} merged at ${pr.mergedAt}`);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (pr.state === 'CLOSED') {
|
|
||||||
console.error(`PR #${prNumber} was closed without merging — aborting tag step.`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
warn(`gh pr view failed: ${e.message}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await new Promise(r => setTimeout(r, POLL_MS));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Date.now() - startedAt >= TIMEOUT_MS) {
|
|
||||||
warn('30-minute timeout reached without seeing the PR merge.');
|
|
||||||
printManualFinish();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
syncMain();
|
syncMain();
|
||||||
@@ -332,7 +325,7 @@ async function waitAndTag() {
|
|||||||
bumpAndPushDev();
|
bumpAndPushDev();
|
||||||
|
|
||||||
if (noWait) {
|
if (noWait) {
|
||||||
info('--no-wait set; not polling for PR merge.');
|
info('--no-wait set; not waiting for origin/main to match dev.');
|
||||||
printManualFinish();
|
printManualFinish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user