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
13 changes: 8 additions & 5 deletions docs/branch-lines.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 功能

源仓当前以 `main` 为默认分支,另有 `legacy` 和 `releases/v0.3.0.beta`。CI、E2E、Coverage 三页在页首提供“分支线”切换,每次只显示一条分支线的数据,各线互不混合:
默认分支(通常是 `main`)和已有配置分支保持独立;展示窗口内观测到的 `release/*`、`releases/*` 分支自动增加独立分支线,无需逐版本修改配置。CI、E2E、Coverage 三页在页首提供“分支线”切换,每次只显示一条分支线的数据,各线互不混合:

- 每个 run 归入它的工作所针对的分支:PR 运行归入 PR 的目标分支,push、手动、定时运行归入运行所在分支。
- 目标分支不是任何已配置分支线的 run(版本 tag、其他分支的 push、无法匹配 PR 的运行)归入默认分支线,因此每个 run 只计一次。Nightly 按运行所在分支归线,手动在 release 分支执行也归 release 线。
Expand All @@ -26,7 +26,9 @@

- `key` 用于页面状态,只能是小写字母、数字和连字符;`ref` 是分支名。切换按钮、CI 层名和各处文案都显示完整分支名,不做缩写。
- `historical_refs` 只重归类早于 `before` 的已采集运行,不改 GitHub 原始记录:旧 `main` 归 `legacy`,旧 `feat/jiuwenswarm` 归现在的 `main`。切换点选在 2026-09-26 20:27 UTC 的最后一次旧 `main` 运行与 2026-09-27 13:19 UTC 的首次新 `main` 运行之间。运行和覆盖率摘要按新分支名展示;缺少原始产物的旧标签目录不能凭分支重命名补造。
- 默认分支总是第一条线,即使未列出;重复的 key 或分支会被忽略。未配置 `branch_lines` 时不显示切换控件。
- 默认分支在配置与数据中保持第一条线,即使未列出;重复的 key 或分支会被忽略。自动发现的 release 分支按完整名称排序,使用稳定键,已配置的同名分支沿用原 key。
- 页面入口只显示 CI 日期窗口(近 30 天、UTC+8)内有实际可展示 run 的分支;只有旧覆盖率、空目录、窗口外历史或被排除类别时不显示。失败、取消、运行中的 run 也算有数据,不要求构建成功。默认分支同样适用,空 main 不会留下空入口;全部为空时不显示切换条。
- 刷新后当前分支不再有窗口内数据时,切换到第一个仍有数据的分支并更新本机选择。CI、E2E、Coverage 的入口与选择保持一致。
- 页面选择保存在本浏览器,三页共用;切换时重置“最近 run”的分支筛选与覆盖率周次。

各页在非默认分支线上的内容:
Expand All @@ -41,17 +43,18 @@

## 主要实现

- `gsb/lines.py`:`configured_lines` 读取配置,`target_of` 求 run 的目标分支,`line_of` 映射到分支线。
- `gsb/lines.py`:`configured_lines` 读取配置并从窗口内已保存 run 的运行分支/PR 目标分支发现 release 分支,`target_of` 求 run 的目标分支,`line_of` 映射到分支线。
- run 记录新增 `base_branch`(同仓 PR 的目标分支,来自 run 的 `pull_requests`)。fork PR 的 run 没有关联 PR,沿用 [CI 分层历史](ci-history-lanes.md)的按 head 分支匹配 PR,再取 PR 的 `base`。
- 历史索引新增 run 的 `pull_requests`、`base_branch`、`head_repo` 与 PR 的 `head`、`base`、`head_sha`、`head_repo`。早期索引行缺少这些字段时,快照从记录重建一次索引行,不改记录与计数。
- `incremental_project.build_snapshot` 按分支线分别计算 CI、分层历史、测试补充数据和覆盖率:`sections.ci` / `sections.tests` 是默认分支线,`line_sections.<key>` 是其他分支线,`lines` 列出全部分支线。Actions 产物列表每次构建只读取一次;覆盖率产物按所属 run 归线,run 不在历史中时按其分支。
- `incremental_project.build_snapshot` 按分支线分别计算 CI、分层历史、测试补充数据和覆盖率:`sections.ci` / `sections.tests` 是默认分支线,`line_sections.<key>` 是其他分支线,`lines` 保留配置及自动发现的分支线,前端根据对应 CI 日期格内实际 run 过滤可见入口。Actions 产物列表每次构建只读取一次;覆盖率产物按所属 run 归线,run 不在历史中时按其分支。
- `.sync/supplements.json` 的 `lines.<key>` 缓存各分支线的测试补充数据,随该线 run 集合变化刷新。
- `.sync/tagged.json` 版本 2 按分支保存标签化测试的组合与目录;版本 1(只有默认分支)自动迁移。
- 覆盖率基线接受 `*-coverage-summary-push-*` 与 `*-coverage-summary-workflow_dispatch-*`,前提是该分支、且各层均完整成功。
- 分支线配置变化或旧快照缺少完整分层时,下一轮构建从已采集历史重建快照,不需要重下产物或回扫历史页。

## 边界

- 自动发现与隐藏入口不列远端分支、不回扫 Actions 历史,不改变采集查询、预算、E2E 记录版本或产物保留规则。
- 分支线只影响 CI、E2E、Coverage 三页的展示与归类,不改变采集范围、历史记录和 Bot 触发策略。
- `legacy` 和 `releases/v0.3.0.beta` 的标签化目录和完整覆盖率基线需要来自各自分支的 push 或手动运行;目标为它们的 PR 可能修改规则,不作为基线依据。
- 已归档到默认分支、后来才配置分支线的历史 run 会在重建快照时按目标分支重新归类;标签化目录只从配置后的新运行读取。
Expand All @@ -63,4 +66,4 @@ PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests -p 'test_lines.p
node .e2e/node_modules/playwright/cli.js test --config test/playwright.config.cjs -g "CI, tests and coverage"
```

单元测试覆盖配置校验、同仓 / fork / 手动 / tag 运行的归线、release 手动 Nightly 与 legacy Daily 可见、合并队列优先归类、工作流调用和其他工作流不展示但保留记录、旧分层快照重建、各线成功率、覆盖率产物归线、标签化目录分线与迁移。浏览器用例在桌面和窄屏验证切换、跨页与刷新后保持、Daily 与合并队列链接、空合并队列、各线数据不混合,以及总览列出其他分支线的失败。
单元测试覆盖配置校验、同仓 / fork / 手动 / tag 运行的归线、release 手动 Nightly 与 legacy Daily 可见、合并队列优先归类、工作流调用和其他工作流不展示但保留记录、旧分层快照重建、各线成功率、覆盖率产物归线、标签化目录分线与迁移。另外覆盖自动发现 `release/*`/`releases/*`、PR 目标分支、键名稳定与窗口外 run 不生成自动分支。浏览器用例在桌面和窄屏验证空入口隐藏、当前入口失效后回退、运行中仍可见、全部为空,以及切换、跨页与刷新后保持、Daily 与合并队列链接、空合并队列、各线数据不混合,以及总览列出其他分支线的失败。
2 changes: 1 addition & 1 deletion docs/ci-history-lanes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CI 页的「CI 分层历史」按触发方式展示该分支线窗口内的 PR
| Daily | 名称匹配 daily 规则(Nightly)的 run,包括 `schedule` 和手动 `workflow_dispatch` |
| 版本 | 名称匹配 release 规则(Release)的 run,包括版本 tag 推送或手动运行 |

[分支线](branch-lines.md)的每条线都有上述完整分层。非默认分支的 push / 手动门禁层使用完整分支名;例如在 `releases/v0.3.0.beta` 手动运行 Nightly,会出现在该分支线的 Daily 层。
[分支线](branch-lines.md)的每条线都有上述完整分层;窗口内有数据的 `release/*`、`releases/*` 自动列为独立分支,窗口内没有可展示 run 的分支入口隐藏。非默认分支的 push / 手动门禁层使用完整分支名;例如在 `releases/v0.3.0.beta` 手动运行 Nightly,会出现在该分支线的 Daily 层。

`merge_group` 优先归入合并队列;其余名称规则取 `board-config.json` 的 `workflows.gate` / `daily` / `release`,缺省时使用相同默认值。`workflow_call` 子 run、其他工作流、缺少事件且没有关联 PR 的门禁 run,以及不属于该线门禁层的分支事件,不在分层图或最近 run 表中展示,也不追加脚注计数。采集仍保存所有 run,不过滤 Actions 查询;同一 run 的重试只展示最后一次尝试。没有事件但有关联 PR 的门禁 run 仍归 PR。

Expand Down
2 changes: 1 addition & 1 deletion docs/dashboard-pages.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 页面与交互

看板只展示已采集的稳定状态,不运行测试。页面依次为:总览、Issue、PR、CI、E2E、Coverage、GitCode 同步(见 [GitCode 同步记录](gitcode-sync.md))。配置了[分支线](branch-lines.md)时,CI、E2E、Coverage 页首可在 main、legacy 与 release 分支之间切换,每次只显示一条分支线。旧的“看板”“构建报告”“历史数据”页已移除;看板形式并入 Issue 与 PR 页,历史分片仍作为采集器的存储保留。
看板只展示已采集的稳定状态,不运行测试。页面依次为:总览、Issue、PR、CI、E2E、Coverage、GitCode 同步(见 [GitCode 同步记录](gitcode-sync.md))。[分支线](branch-lines.md)自动包含已观测到的 `release/*` 与 `releases/*`,CI、E2E、Coverage 页首只显示近 30 天 CI 日期格内有可展示运行的分支入口,每次查看一条分支线;刷新后失效的选择自动回到仍有数据的分支。旧的“看板”“构建报告”“历史数据”页已移除;看板形式并入 Issue 与 PR 页,历史分片仍作为采集器的存储保留。

页首显示快照时间。没有数据变化的采集不改快照时间,新的 UTC 日期会重建一次,Bot 至少每 8 小时采集一次;所以快照超过 36 小时未更新时,页面提示采集可能已停止。

Expand Down
13 changes: 8 additions & 5 deletions gsb/incremental_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from zoneinfo import ZoneInfo

from .board import BoardStore
from .ci_lanes import LANES, PR_EVENTS, build_lanes, window_start
from .ci_lanes import DISPLAY_ZONE, LANES, PR_EVENTS, build_lanes, window_start
from .collectors import Context, collect_ci, summarize_issues, summarize_prs, days_between
from .coverage_store import CoverageStore
from .history import read_json, encode
Expand Down Expand Up @@ -171,7 +171,10 @@ def build_snapshot(sync):
midnight = sync.now.replace(hour=0, minute=0, second=0)
cutoff = stamp(midnight - timedelta(days=30))
progress = sync.progress()
lines = configured_lines(sync.settings, meta["default_branch"])
start = stamp(window_start(sync.now))
observed = [row for _, row in history.rows("runs") if start <= (row.get("created_at") or "") <= stamp(sync.now)]
lines = configured_lines(sync.settings, meta["default_branch"], runs=observed,
prs=[row for _, row in history.rows("prs")])
# A successful poll with no changed records does not manufacture a Pages
# deployment. Daily aging and health metadata still get a regular refresh.
cache_upgrade = supplements.get("tests_version") != SUPPLEMENT_TESTS_VERSION
Expand All @@ -180,15 +183,16 @@ def build_snapshot(sync):
old_ci = ((old.get("sections") or {}).get("ci") or {}).get("data") or {}
old_tests = ((old.get("sections") or {}).get("tests") or {}).get("data")
cache_upgrade = (cache_upgrade or "lanes" not in old_ci or (isinstance(old_tests, dict) and "tagged" not in old_tests)
or old.get("lines") != lines
or any("median_duration_s" not in lane.get("summary", {}) for lane in old_ci["lanes"].get("lanes", [])))
# Snapshots from before the Issue / PR trend charts are rebuilt once (without refreshing test data).
trend_upgrade = any(isinstance(((old.get("sections") or {}).get(kind) or {}).get("data"), dict)
and "trend" not in old["sections"][kind]["data"] for kind in ("issues", "prs"))
lanes_upgrade = False
lanes_upgrade = old.get("lines") != lines
last_day = sync.now.astimezone(DISPLAY_ZONE).date().isoformat()
for line in lines:
sections = old.get("sections", {}) if line["default"] else old.get("line_sections", {}).get(line["key"], {})
view = ((sections.get("ci") or {}).get("data") or {}).get("lanes") or {}
lanes_upgrade = lanes_upgrade or view.get("days", [])[-1:] != [last_day]
lanes_upgrade = lanes_upgrade or [lane["key"] for lane in view.get("lanes", [])] != [key for key, _ in LANES]
# Reprojecting stored run categories must not invalidate test-artifact caches.
if (not history.changed and not sync.tagged.changed and not cache_upgrade and not lanes_upgrade and not trend_upgrade and old.get("sync") == progress
Expand Down Expand Up @@ -271,7 +275,6 @@ def coverage_owner(artifact):
store = CoverageStore(read_json(history.root / ".sync/coverage.json", None),
read_json(history.root / ".sync/coverage-sources.json", None))
lines_read = 0
start = stamp(window_start(sync.now))
lane_prs = [history.get("prs", str(row["number"])) for row in all_prs if not row.get("closed_at") or row["closed_at"] >= start]
refreshed = day_changed or "ops" not in supplements
if refreshed:
Expand Down
30 changes: 25 additions & 5 deletions gsb/lines.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
"""Branch lines: long-lived branches whose CI, tests and coverage are viewed apart.
"""Branch lines: configured and observed release branches viewed apart.

A run belongs to the line its work targets: a pull request's base branch, or
the branch a push, dispatch or schedule ran on. Everything that targets no
other configured line (release tags, nightly, unmatched runs) stays with the
other line (release tags, unmatched runs) stays with the
default branch, so no run is counted twice.
"""
from __future__ import annotations

import hashlib
import re
from datetime import datetime, timezone

from .ci_lanes import PR_EVENTS, pr_number
from .ci_lanes import PR_EVENTS, lane_of, pr_number, workflow_name

KEY_RE = re.compile(r"[a-z0-9][a-z0-9-]{0,30}\Z")

Expand All @@ -33,8 +34,8 @@ def _historical_refs(entry):
return refs


def configured_lines(settings, default_branch):
"""Lines from ``branch_lines`` in board-config.json, the default branch first."""
def configured_lines(settings, default_branch, *, runs=(), prs=()):
"""Configured lines plus release branches observed in the supplied run window."""
lines, seen = [], set()
for entry in (settings or {}).get("branch_lines") or []:
if not isinstance(entry, dict):
Expand All @@ -47,6 +48,25 @@ def configured_lines(settings, default_branch):
if aliases:
line["historical_refs"] = aliases
lines.append(line)
# Discover from stored runs, including PR base branches; never list remote branches or old Actions pages.
runs, prs = list(runs), list(prs)
by_number = {pr.get("number"): pr for pr in prs}
names = {row.get("workflow_id"): row["name"] for row in runs if row.get("name") and not re.search(r"\.ya?ml$", row["name"])}
refs = set()
for row in runs:
ref = target_of(row, prs, by_number)
if isinstance(ref, str) and ref.startswith(("release/", "releases/")) and ref.split("/", 1)[1]:
if lane_of({**row, "name": workflow_name(row, names)}, (settings or {}).get("workflows"), ref):
refs.add(ref)
for ref in sorted(refs - {line["ref"] for line in lines} - {default_branch}):
salt = 0
while True:
key = "release-" + hashlib.sha256(f"{ref}:{salt}".encode()).hexdigest()[:20]
if key not in seen:
break
salt += 1
seen.add(key)
lines.append({"key": key, "ref": ref})
default = next((line for line in lines if line["ref"] == default_branch), None)
if not default:
default = {"key": default_branch if KEY_RE.match(default_branch) else "default", "ref": default_branch}
Expand Down
14 changes: 11 additions & 3 deletions site/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,15 @@
};
// Branch lines: CI, E2E and Coverage show one long-lived branch at a time. PR runs
// belong to the branch they target; sections hold the default line.
const currentLine = (snap) => { const lines = snap?.lines || []; return lines.find((l) => l.key === STATE.line) || lines[0] || { key: '', ref: snap?.repository?.default_branch, default: true }; };
const visibleLines = (snap) => (snap?.lines || []).filter((line) => {
const ci = (line.default ? snap.sections : snap.line_sections?.[line.key])?.ci?.data;
return ci?.lanes?.lanes?.some((lane) => Object.hasOwn(LANE_SOURCE, lane.key) && lane.days.some((day) => day.length));
});
const currentLine = (snap) => { const lines = visibleLines(snap); return lines.find((l) => l.key === STATE.line) || lines[0] || { key: '', ref: snap?.repository?.default_branch, default: true }; };
const lineSection = (snap, name) => { const line = currentLine(snap); return line.default ? snap.sections[name] : snap.line_sections?.[line.key]?.[name]; };
const lineBar = (snap) => {
const lines = snap.lines || [], line = currentLine(snap);
if (lines.length < 2) return '';
const lines = visibleLines(snap), line = currentLine(snap);
if (!lines.length) return '';
return `<div class="line-bar"><div class="seg line-switch" role="group" aria-label="分支线"><span class="seg-label">分支线</span>${lines.map((l) => `<button type="button" class="${l.key === line.key ? 'on' : ''}" data-line="${esc(l.key)}" aria-pressed="${l.key === line.key}">${esc(l.ref)}</button>`).join('')}</div>`
+ `<span class="muted">当前 <code>${esc(line.ref)}</code>:按运行分支及 PR 目标分支归类,按 PR、分支门禁、合并队列、Daily 与版本展示;各分支线的数据互不混合。</span></div>`;
};
Expand Down Expand Up @@ -1415,6 +1419,10 @@
safe('issues', () => renderIssues(snap.sections.issues));
safe('prs', () => renderPRs(snap.sections.prs));
const line = currentLine(snap);
if (STATE.line !== line.key) {
STATE.line = line.key;
try { localStorage.setItem(LINE_KEY, STATE.line); } catch (e) { /* private mode */ }
}
safe('ci', () => lineBar(snap) + renderCI(lineSection(snap, 'ci'), line));
safe('tests', () => lineBar(snap) + renderTests(lineSection(snap, 'tests'), line));
safe('coverage', () => lineBar(snap) + renderCoverage(lineSection(snap, 'tests'), line));
Expand Down
8 changes: 4 additions & 4 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>GitHub 状态看板</title>
<!-- Keep the UI bundle on one cache version so GitHub Pages cannot mix old CSS with new JS. -->
<link rel="stylesheet" href="./style.css?v=20261106.1">
<link rel="stylesheet" href="./style.css?v=20261111.1">
</head>
<body>
<header class="topbar">
Expand Down Expand Up @@ -44,8 +44,8 @@
<aside id="drawer" class="drawer hidden" aria-label="卡片详情"></aside>
<dialog id="board-settings" class="settings"></dialog>
<div id="tooltip" class="tooltip hidden"></div>
<script src="./board-local.js?v=20261106.1"></script><script src="./app.js?v=20261106.1"></script>
<script src="./board.js?v=20261106.1"></script>
<script src="./gitcode-sync.js?v=20261106.1"></script>
<script src="./board-local.js?v=20261111.1"></script><script src="./app.js?v=20261111.1"></script>
<script src="./board.js?v=20261111.1"></script>
<script src="./gitcode-sync.js?v=20261111.1"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions site/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ details { margin-top: 4px; }
.seg button.on { background: var(--s1); color: #fff; }
/* Branch line switch above the CI, test and coverage pages. */
.line-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0 0 14px; }
.line-switch { flex-wrap: wrap; max-width: 100%; }
.line-switch button { flex: 0 1 auto; max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
.line-bar > .muted { font-size: 12.5px; min-width: 0; }
.check { font-size: 13px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 4px; }
.grow { flex: 1 1 auto; }
Expand Down
Loading
Loading