diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 25d5a2f..82aab46 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -# 合进 main 的配方:打包(已发布的跳过)→ 重出签名索引 +# 合进 main 的配方:打包(已发布的跳过)→ arm64 容器自动实跑 selftest → 合并三级验证并重出签名索引 name: build on: push: @@ -7,8 +7,12 @@ on: workflow_dispatch: inputs: only: - description: "只打这一个组件(留空 = 全部)" + description: "只打/只验这一个组件(留空 = 全部)" required: false + skip_ci_verify: + description: "跳过 arm64 自动 selftest,直接重签索引" + type: boolean + default: false permissions: contents: write concurrency: @@ -33,7 +37,79 @@ jobs: - run: node tools/check-recipes.mjs - name: 打包 run: node tools/ci-build.mjs --devkit app/devkit ${{ inputs.only && format('--only {0}', inputs.only) || '' }} + + verify-ci: + needs: build + if: ${{ !inputs.skip_ci_verify }} + runs-on: ubuntu-24.04-arm + timeout-minutes: 90 + strategy: + fail-fast: false + matrix: + shard: ["0/4", "1/4", "2/4", "3/4"] + env: + GH_TOKEN: ${{ github.token }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + - name: arm64 容器实跑 selftest(分片 ${{ matrix.shard }}) + run: | + SHARD_ID=$(echo "${{ matrix.shard }}" | tr '/' '-') + node tools/ci-verify-base.mjs \ + --shard "${{ matrix.shard }}" \ + ${{ inputs.only && format('--only {0}', inputs.only) || '' }} \ + --out "work/ci-shard-${SHARD_ID}.json" + - uses: actions/upload-artifact@v4 + with: + name: ci-verified-${{ strategy.job-index }} + path: work/ci-shard-*.json + retention-days: 7 + + index: + needs: [build, verify-ci] + if: ${{ always() && needs.build.result == 'success' && (needs.verify-ci.result == 'success' || needs.verify-ci.result == 'skipped') }} + runs-on: ubuntu-latest + timeout-minutes: 30 + env: + GH_TOKEN: ${{ github.token }} + steps: + - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + with: + repository: greyoak111/cccodroid + path: app + sparse-checkout: devkit + - uses: actions/setup-node@v4 + with: + node-version: 22 + - name: 收集已有与本轮 CI 自动验证记录 + run: | + mkdir -p work/shards + gh release download index -R "$GITHUB_REPOSITORY" -p ci-verified.json -O work/prev-ci-verified.json --clobber || echo '{}' > work/prev-ci-verified.json + - name: 下载各分片产物 + if: ${{ !inputs.skip_ci_verify }} + uses: actions/download-artifact@v4 + with: + pattern: ci-verified-* + path: work/shards + merge-multiple: true + - name: 合并 CI 自动验证记录 + run: | + node -e ' + import fs from "node:fs"; + import path from "node:path"; + import { mergeCiVerified } from "./tools/build-index.mjs"; + const parts = [JSON.parse(fs.readFileSync("work/prev-ci-verified.json", "utf8"))]; + for (const f of fs.readdirSync("work/shards").filter((x) => x.endsWith(".json")).sort()) { + parts.push(JSON.parse(fs.readFileSync(path.join("work/shards", f), "utf8"))); + } + const merged = mergeCiVerified(...parts); + fs.writeFileSync("work/ci-verified.json", JSON.stringify(merged, null, 2) + "\n"); + console.log("合并 CI 验证记录:" + Object.keys(merged).length + " 个组件"); + ' --input-type=module - name: 出索引并签名 env: INDEX_SIGNING_KEY: ${{ secrets.INDEX_SIGNING_KEY }} - run: node tools/build-index.mjs --upload + run: node tools/build-index.mjs --devkit app/devkit --ci-verified work/ci-verified.json --upload diff --git a/docs/recipe.md b/docs/recipe.md index e9203d1..7c37a24 100644 --- a/docs/recipe.md +++ b/docs/recipe.md @@ -191,10 +191,12 @@ description: <一句话:什么时候该用它> 只有在真机上装过、`selftest` 过了、skill 装上的构建才写进去;`checks` 如实写做了哪些检查。 没写的构建在 App 里显示"未经真机验证"。 -**换底座不用全部重测**:出索引时,同一版本在别的底座上验证过的构建,如果组件自己的包(名字 + sha256)没变、 -它依赖链里由底座提供的包(构建清单的 `baseDeps`)在两个底座里版本都相同、它 requires 的组件在新底座上也算验证过, -就自动继承那条记录(索引里带 `inherited`:从哪个底座、为什么)。只有真变了的才进待测列表。 +**三级验证体系(换底座不用人工重测全部组件)**: + +1. **真机直接验证(`kind: "device"`)**:`verified.json` 里对应 `(组件, 版本, 底座前 12 位)` 的记录。 +2. **ABI 兼容继承(`kind: "inherited"`)**:同一版本在老底座上有真机验证,且组件自己的包(名字 + sha256)没变、它 `baseDeps` 里的底座包在新旧底座之间**没有发生 ABI-MAJOR / SONAME 破坏性变化**(补丁、次版本、CLI 主版本漂移不再一刀切作废继承)、它 `requires` 的其他组件在新底座上也已验证。 +3. **ARM64 容器自动验证(`kind: "ci-arm64"`)**:`build.yml` 在打包完成后会在 `ubuntu-24.04-arm` + `termux/termux-docker:aarch64` 上按分片并行自动实跑真实底座解包 + `first-run.sh` + `selftest`,通过且资产 `gzSha256` 一致的记录写入 `ci-verified.json` 并合并进签名索引。**凡声明了 `needs.gpu` / `needs.display` / `needs.shizuku` 的硬件相关组件,一律禁止走 `ci-arm64`,必须真机验证或严格继承。** **批量真机验证**:`node tools/verify-device.mjs --pending --app "cccodroid <版本>" --by ` -把当前工具包下所有还没验证(含继承)的组件按依赖顺序挨个验完,最后打印一份合并好的记录。 +默认只验当前工具包下仍未验证(即硬件组件或 CI 未通过的少数几项)且本机支持的组件;如需把仅由 CI 验过的组件也纳入真机复验,可加 `--include-ci`。 加 `--pr` 就直接把通过的记录并进 `verified.json` 开 PR(用 gh,要对本仓库有写权限;不用 clone)。 diff --git a/tools/build-index.mjs b/tools/build-index.mjs index b4ba096..e4aee72 100644 --- a/tools/build-index.mjs +++ b/tools/build-index.mjs @@ -1,128 +1,316 @@ // 从各组件 Release 收集构建清单,合成 App 读的 components.json,并用 ed25519 签名: -// INDEX_SIGNING_KEY= node tools/build-index.mjs [--out DIR] [--upload] +// INDEX_SIGNING_KEY= node tools/build-index.mjs [--out DIR] [--devkit ../cccodroid/devkit] +// [--ci-verified file.json] [--upload] // // 产物:components.json + components.json.sig(对 components.json 原始字节的签名,base64) // App 内置公钥,验签不过整份索引作废 —— 所以索引里的 sha256 可信,包被换了也装不上。 // 只收录仓库里还有配方的组件;每个底座只留最新版本。 // -// 验证继承:换了底座、组件没变的,不用重新真机验证。同一版本在别的底座上验证过,且 -// · 组件自己的包(名字 + sha256)一模一样, -// · 它依赖链里由底座提供的包(构建清单的 baseDeps)在两个底座里版本都相同, -// · 它 requires 的组件在新底座上也算验证过, -// 就把那条记录带过来,标上 inherited(从哪个底座、为什么)。旧构建清单没有 baseDeps 的不继承。 +// 三级验证体系(避免每次重打底座都要人工真机重验全部组件): +// 1. device(真机直接验证):verified.json 里对应组件版本 + 底座前 12 位的记录。 +// 2. inherited(ABI 兼容继承):同一版本在老底座上有真机验证,且: +// · 组件自己的包(名字 + sha256)一模一样; +// · 它依赖的底座包(baseDeps)在新旧底座之间没有发生 ABI-MAJOR / REMOVED 变化 +// (优先比对 devkit.lock.json 的 abi.sonames,老锁文件退回 abi-policy 共享库/运行时规则; +// patch/minor/CLI-major 漂移不再一刀切作废验证); +// · 它 requires 的其他组件在新底座上也已验证(module:* 由底座提供,不误判)。 +// 3. ci-arm64(CI 容器自动验证):不依赖手机硬件(无 GPU / 屏幕 / Shizuku)的组件, +// 在 ubuntu-24.04-arm + termux-docker:aarch64 真实底座快照里跑通安装 + first-run + selftest, +// 且 gzSha256 与当前资产完全一致。硬件相关组件禁止走 ci-arm64,必须真机验。 import fs from "node:fs"; import path from "node:path"; import crypto from "node:crypto"; +import { fileURLToPath } from "node:url"; import { ROOT, REPO, APP_REPO, recipes, run, asset, modelsOf } from "./lib.mjs"; -const args = process.argv.slice(2); -const opt = (k) => { const i = args.indexOf("--" + k); return i >= 0 ? args[i + 1] : undefined; }; -const OUT = path.resolve(opt("out") || path.join(ROOT, "work", "index")); -const gh = (...a) => run("gh", a); -const verified = JSON.parse(fs.readFileSync(path.join(ROOT, "verified.json"), "utf8")); -fs.mkdirSync(OUT, { recursive: true }); - -// 底座的包清单(devkit.lock.json):按 gz 前 12 位缓存 -const locks = new Map(); -function baseLock(tag) { - if (!tag) return null; - if (locks.has(tag)) return locks.get(tag); - const d = path.join(OUT, "bases", tag); - let lock = null; - try { - if (!fs.existsSync(path.join(d, "devkit.lock.json"))) { fs.mkdirSync(d, { recursive: true }); gh("release", "download", tag, "-R", APP_REPO, "-p", "devkit.lock.json", "-D", d, "--clobber"); } - lock = JSON.parse(fs.readFileSync(path.join(d, "devkit.lock.json"), "utf8")); - } catch {} - locks.set(tag, lock && new Map(lock.packages.map((p) => [p.name, p.version]))); - return locks.get(tag); +// 兜底 ABI 策略(若通过 --devkit 指向了 cccodroid/devkit,会直接读取那里的 abi-policy.json) +const FALLBACK_ABI_POLICY = { + soProviders: { + libicu: { scheme: "major" }, openssl: { scheme: "major" }, "libc++": { scheme: "major" }, + libllvm: { scheme: "major" }, clang: { scheme: "major" }, glibc: { scheme: "minor" }, + libxml2: { scheme: "major" }, ffmpeg: { scheme: "major" }, "openjdk-21": { scheme: "major" }, + zlib: { scheme: "major" }, libsqlite: { scheme: "major" }, libcurl: { scheme: "major" }, + libpng: { scheme: "major" }, "libjpeg-turbo": { scheme: "major" }, libwebp: { scheme: "major" }, + libffi: { scheme: "major" }, liblzma: { scheme: "major" }, libzstd: { scheme: "major" }, + libarchive: { scheme: "major" }, glib: { scheme: "major" }, freetype: { scheme: "major" }, + fontconfig: { scheme: "major" }, harfbuzz: { scheme: "major" }, cairo: { scheme: "major" }, + pango: { scheme: "major" }, mesa: { scheme: "major" }, "vulkan-loader": { scheme: "major" }, + }, + runtimeAbi: { + python: { scheme: "minor" }, nodejs: { scheme: "major" }, perl: { scheme: "minor" }, ruby: { scheme: "minor" }, + }, + cliOnly: ["npm", "git", "openssh", "bash", "coreutils", "curl", "tar", "gzip", "xz-utils", "zstd", "python-pip"], +}; + +export function isHardwareBound(needs = {}) { + return !!(needs.gpu === "adreno" || needs.gpu === "mali" || needs.gpu === true || needs.display || needs.shizuku); +} + +function parseVer(raw) { + const s = String(raw || "").trim(); + const epIdx = s.indexOf(":"); + const rest = epIdx >= 0 ? s.slice(epIdx + 1) : s; + const dashIdx = rest.lastIndexOf("-"); + const upstream = dashIdx > 0 ? rest.slice(0, dashIdx) : rest; + const nums = (upstream.match(/\d+/g) || []).map(Number); + return { upstream, nums }; +} + +function versionDelta(fromRaw, toRaw) { + if (fromRaw === toRaw) return "same"; + const a = parseVer(fromRaw), b = parseVer(toRaw); + if (a.upstream === b.upstream) return "patch"; + if ((a.nums[0] ?? 0) !== (b.nums[0] ?? 0)) return "major"; + if ((a.nums[1] ?? 0) !== (b.nums[1] ?? 0)) return "minor"; + return "patch"; +} + +/** + * 判断某个底座依赖包从老底座 lockA 到新底座 lockB 是否发生了可能破坏 ABI 的变化。 + * 返回阻断原因字符串,兼容时返回 null。 + */ +export function basePkgAbiBreaking(name, lockA, lockB, policy = FALLBACK_ABI_POLICY) { + const va = lockA.pkgs.get(name), vb = lockB.pkgs.get(name); + if (va === vb) return null; + if (!va || !vb) return `${name} ${va || "无"}→${vb || "无"}`; + + // 若新旧锁文件都带有实测 ELF SONAME,优先按 SONAME 是否消失判定 + const snA = lockA.sonames?.[name], snB = lockB.sonames?.[name]; + if (Array.isArray(snA) && Array.isArray(snB)) { + const setB = new Set(snB); + const removed = snA.filter((s) => !setB.has(s)); + if (removed.length) return `${name} SONAME 变化(移除 ${removed.join(", ")})`; + // 运行时 ABI(python 次版本 / nodejs 主版本)即使 SONAME 不变也会破坏扩展路径,继续核对 runtimeAbi + if (!policy.runtimeAbi?.[name]) return null; + } + + const delta = versionDelta(va, vb); + const rt = policy.runtimeAbi?.[name]; + if (rt) { + const hit = rt.scheme === "minor" ? (delta === "major" || delta === "minor") : delta === "major"; + return hit ? `${name} 运行时 ABI 升级 ${va}→${vb}` : null; + } + const so = policy.soProviders?.[name]; + if (so) { + const hit = so.scheme === "minor" ? (delta === "major" || delta === "minor") : delta === "major"; + return hit ? `${name} 共享库 ABI 升级 ${va}→${vb}` : null; + } + const cli = new Set(policy.cliOnly || []); + if (cli.has(name)) return null; + if (/^lib[a-z0-9]/.test(name) && delta === "major") return `${name} 共享库主版本升级 ${va}→${vb}`; + return null; } -const pkgKey = (m) => m.packages.map((p) => p.name + "@" + p.sha256).sort().join("\n"); -/** m(新底座上的构建)能不能继承 a(别的底座上验证过的同版本构建)的验证:不能就返回原因 */ -function inheritBlocker(m, a) { + +export const pkgKey = (m) => (m.packages || []).map((p) => p.name + "@" + p.sha256).sort().join("\n"); + +/** m(新底座上的构建)能否从 a(老底座上真机验过的同版本构建)继承验证;不能就返回原因 */ +export function inheritBlockerWithLocks(m, a, lockB, lockA, policy = FALLBACK_ABI_POLICY) { if (!Array.isArray(m.baseDeps)) return "构建清单没有 baseDeps"; if (pkgKey(m) !== pkgKey(a)) return "组件自己的包变了"; - const lb = baseLock(m.base.tag), la = baseLock(a.base.tag); - if (!lb || !la) return "底座清单取不到"; - const diff = m.baseDeps.filter((d) => la.get(d.name) !== lb.get(d.name)).map((d) => `${d.name} ${la.get(d.name) || "无"}→${lb.get(d.name)}`); - return diff.length ? "依赖的底座包变了:" + diff.slice(0, 5).join(", ") : null; + if (!lockB || !lockA) return "底座清单取不到"; + const breaking = []; + for (const d of m.baseDeps) { + const why = basePkgAbiBreaking(d.name, lockA, lockB, policy); + if (why) breaking.push(why); + } + return breaking.length ? "依赖的底座包发生 ABI 变化:" + breaking.slice(0, 5).join(", ") : null; } -const vcmp = (a, b) => a.localeCompare(b, "en", { numeric: true }); -const idx = { schema: 1, source: REPO, generated: new Date().toISOString(), components: {} }; -for (const r of recipes()) { - let rel; - try { rel = JSON.parse(gh("release", "view", r.id, "-R", REPO, "--json", "assets")).assets; } catch { console.log(`· ${r.id}: 还没有发布的构建`); continue; } - const names = new Set(rel.map((a) => a.name)); - const dl = path.join(OUT, "meta", r.id); - fs.rmSync(dl, { recursive: true, force: true }); - fs.mkdirSync(dl, { recursive: true }); - gh("release", "download", r.id, "-R", REPO, "-p", "*.json", "-D", dl); - const byBase = new Map(), all = []; - for (const f of fs.readdirSync(dl)) { - const m = JSON.parse(fs.readFileSync(path.join(dl, f), "utf8")); - const name = asset(m.id, m.version, m.base.gz); - if (m.id !== r.id || !names.has(name + ".tar.gz")) continue; // 包没传完的不收 - all.push(m); - const cur = byBase.get(m.base.gz); - if (!cur || vcmp(m.version, cur.version) > 0) byBase.set(m.base.gz, { ...m, asset: name + ".tar.gz" }); - } - if (!byBase.size) continue; - idx.components[r.id] = { - name: r.name, desc: r.desc, kind: r.kind || "termux", license: r.license, homepage: r.homepage || "", - category: r.category || "other", - ...(r.mcp ? { mcp: { name: r.mcp.name, bin: r.mcp.bin } } : {}), - maintainers: r.maintainers || [], needs: r.needs || {}, requires: r.requires || [], - ...((m) => (m.length ? { models: m } : {}))(modelsOf(r).models), - builds: [...byBase.values()].map((m) => { - let v = verified[r.id]?.[m.version]?.[m.base.gz.slice(0, 12)] || null; - if (!v) { - const why = []; - for (const a of all.filter((x) => x.version === m.version && x.base.gz !== m.base.gz)) { - const va = verified[r.id]?.[a.version]?.[a.base.gz.slice(0, 12)]; - if (!va || va.inherited) continue; - const block = inheritBlocker(m, a); - if (!block) { v = { ...va, inherited: { from: a.base.gz.slice(0, 12), fromTag: a.base.tag || "", why: "component packages and the base packages it depends on are unchanged" } }; break; } - why.push(`${a.base.gz.slice(0, 12)}:${block}`); +/** 合并多份 ci-verified 对象({ id: { version: { base12: rec } } }) */ +export function mergeCiVerified(...sources) { + const out = {}; + for (const src of sources) { + if (!src || typeof src !== "object") continue; + for (const [id, vers] of Object.entries(src)) { + if (!vers || typeof vers !== "object") continue; + out[id] = out[id] || {}; + for (const [ver, basesMap] of Object.entries(vers)) { + if (!basesMap || typeof basesMap !== "object") continue; + out[id][ver] = out[id][ver] || {}; + for (const [b12, rec] of Object.entries(basesMap)) { + if (rec && typeof rec === "object") out[id][ver][b12] = rec; } - if (!v && why.length) console.log(` ${r.id} ${m.version} for ${m.base.gz.slice(0, 12)} 不继承验证(${why.join(";")})`); } - return { - base: m.base.gz, baseTag: m.base.tag || "", version: m.version, upstream: m.upstream, - url: `https://github.com/${REPO}/releases/download/${encodeURIComponent(r.id)}/${encodeURIComponent(m.asset)}`, asset: m.asset, - sha256: m.gz.sha256, bytes: m.gz.bytes, installed: m.installed, - bin: m.bin, skill: m.skill, selftest: m.selftest, packages: m.packages.length, - // 依赖链里由底座提供的包:cccodroid 0.4.0 起的模块化工具包据此算出组件要先装哪些模块 - baseDeps: (m.baseDeps || []).map((d) => d.name), - verified: v, - }; - }), - }; + } + } + return out; } -// requires 的组件在同一底座上没验证过:继承来的验证不算数(自己直接验的不受影响) -for (let changed = true; changed;) { - changed = false; + +function loadAbiPolicy(devkitDir) { + const candidates = [ + devkitDir && path.join(devkitDir, "abi-policy.json"), + path.join(ROOT, "app", "devkit", "abi-policy.json"), + path.join(ROOT, "..", "cccodroid", "devkit", "abi-policy.json"), + ].filter(Boolean); + for (const p of candidates) { + if (fs.existsSync(p)) { + try { return JSON.parse(fs.readFileSync(p, "utf8")); } catch {} + } + } + return FALLBACK_ABI_POLICY; +} + +function main() { + const args = process.argv.slice(2); + const opt = (k) => { const i = args.indexOf("--" + k); return i >= 0 ? args[i + 1] : undefined; }; + const OUT = path.resolve(opt("out") || path.join(ROOT, "work", "index")); + const gh = (...a) => run("gh", a); + const policy = loadAbiPolicy(opt("devkit")); + const verified = JSON.parse(fs.readFileSync(path.join(ROOT, "verified.json"), "utf8")); + fs.mkdirSync(OUT, { recursive: true }); + + // 读取 CI 自动验证记录:优先命令行传入,否则尝试从 index Release 拉取已有记录 + let ciVerified = {}; + const ciArg = opt("ci-verified"); + if (ciArg && fs.existsSync(ciArg)) { + ciVerified = JSON.parse(fs.readFileSync(ciArg, "utf8")); + } else { + const dlCi = path.join(OUT, "ci-verified.json"); + try { + gh("release", "download", "index", "-R", REPO, "-p", "ci-verified.json", "-O", dlCi, "--clobber"); + ciVerified = JSON.parse(fs.readFileSync(dlCi, "utf8")); + } catch {} + } + + // 底座锁文件缓存:保留 packages 版本映射 + 可选 abi.sonames + const locks = new Map(); + function baseLock(tag) { + if (!tag) return null; + if (locks.has(tag)) return locks.get(tag); + const d = path.join(OUT, "bases", tag); + let parsed = null; + try { + if (!fs.existsSync(path.join(d, "devkit.lock.json"))) { + fs.mkdirSync(d, { recursive: true }); + gh("release", "download", tag, "-R", APP_REPO, "-p", "devkit.lock.json", "-D", d, "--clobber"); + } + const lock = JSON.parse(fs.readFileSync(path.join(d, "devkit.lock.json"), "utf8")); + parsed = { + pkgs: new Map((lock.packages || []).map((p) => [p.name, p.version])), + sonames: lock.abi?.sonames || null, + }; + } catch {} + locks.set(tag, parsed); + return parsed; + } + + const vcmp = (a, b) => a.localeCompare(b, "en", { numeric: true }); + const idx = { schema: 1, source: REPO, generated: new Date().toISOString(), components: {} }; + for (const r of recipes()) { + let rel; + try { rel = JSON.parse(gh("release", "view", r.id, "-R", REPO, "--json", "assets")).assets; } catch { console.log(`· ${r.id}: 还没有发布的构建`); continue; } + const names = new Set(rel.map((a) => a.name)); + const dl = path.join(OUT, "meta", r.id); + fs.rmSync(dl, { recursive: true, force: true }); + fs.mkdirSync(dl, { recursive: true }); + gh("release", "download", r.id, "-R", REPO, "-p", "*.json", "-D", dl); + const byBase = new Map(), all = []; + for (const f of fs.readdirSync(dl)) { + const m = JSON.parse(fs.readFileSync(path.join(dl, f), "utf8")); + const name = asset(m.id, m.version, m.base.gz); + if (m.id !== r.id || !names.has(name + ".tar.gz")) continue; // 包没传完的不收 + all.push(m); + const cur = byBase.get(m.base.gz); + if (!cur || vcmp(m.version, cur.version) > 0) byBase.set(m.base.gz, { ...m, asset: name + ".tar.gz" }); + } + if (!byBase.size) continue; + const hwBound = isHardwareBound(r.needs); + idx.components[r.id] = { + name: r.name, desc: r.desc, kind: r.kind || "termux", license: r.license, homepage: r.homepage || "", + category: r.category || "other", + ...(r.mcp ? { mcp: { name: r.mcp.name, bin: r.mcp.bin } } : {}), + maintainers: r.maintainers || [], needs: r.needs || {}, requires: r.requires || [], + ...((m) => (m.length ? { models: m } : {}))(modelsOf(r).models), + builds: [...byBase.values()].map((m) => { + const b12 = m.base.gz.slice(0, 12); + // 1. 直接真机验证 + const rawDevice = verified[r.id]?.[m.version]?.[b12] || null; + let v = rawDevice ? { kind: "device", ...rawDevice } : null; + // 2. ABI 兼容继承(来自老底座的真机验证) + if (!v) { + const why = []; + for (const a of all.filter((x) => x.version === m.version && x.base.gz !== m.base.gz)) { + const va = verified[r.id]?.[a.version]?.[a.base.gz.slice(0, 12)]; + if (!va || va.inherited) continue; + const block = inheritBlockerWithLocks(m, a, baseLock(m.base.tag), baseLock(a.base.tag), policy); + if (!block) { + v = { + kind: "inherited", + ...va, + inherited: { + from: a.base.gz.slice(0, 12), + fromTag: a.base.tag || "", + why: "component packages are unchanged and baseDeps have no ABI-breaking changes", + }, + }; + break; + } + why.push(`${a.base.gz.slice(0, 12)}:${block}`); + } + if (!v && why.length) console.log(` ${r.id} ${m.version} for ${b12} 不继承验证(${why.join(";")})`); + } + // 3. CI arm64 容器实跑 selftest(硬件依赖组件禁止走这一档) + if (!v && !hwBound) { + const ci = ciVerified[r.id]?.[m.version]?.[b12]; + if (ci && ci.gzSha256 === m.gz.sha256) { + v = { kind: "ci-arm64", ...ci }; + } + } + return { + base: m.base.gz, baseTag: m.base.tag || "", version: m.version, upstream: m.upstream, + url: `https://github.com/${REPO}/releases/download/${encodeURIComponent(r.id)}/${encodeURIComponent(m.asset)}`, asset: m.asset, + sha256: m.gz.sha256, bytes: m.gz.bytes, installed: m.installed, + bin: m.bin, skill: m.skill, selftest: m.selftest, packages: m.packages.length, + // 依赖链里由底座提供的包:cccodroid 0.4.0 起的模块化工具包据此算出组件要先装哪些模块 + baseDeps: (m.baseDeps || []).map((d) => d.name), + verified: v, + }; + }), + }; + } + // requires 的组件在同一底座上没验证过:继承来的验证不算数(自己直接验或 CI 实跑过的本身已连同依赖跑过)。 + // 跳过 module::工具包模块由底座发布并随底座验证,不在组件索引里。 + for (let changed = true; changed;) { + changed = false; + for (const [id, c] of Object.entries(idx.components)) for (const b of c.builds) { + if (!b.verified?.inherited) continue; + const bad = c.requires.filter((d) => !d.startsWith("module:") && !idx.components[d]?.builds.some((x) => x.base === b.base && x.verified)); + if (bad.length) { console.log(` ${id} ${b.version} for ${b.base.slice(0, 12)} 撤掉继承(依赖 ${bad.join(", ")} 在这个底座上没验证)`); b.verified = null; changed = true; } + } + } for (const [id, c] of Object.entries(idx.components)) for (const b of c.builds) { - if (!b.verified?.inherited) continue; - const bad = c.requires.filter((d) => !idx.components[d]?.builds.some((x) => x.base === b.base && x.verified)); - if (bad.length) { console.log(` ${id} ${b.version} for ${b.base.slice(0, 12)} 撤掉继承(依赖 ${bad.join(", ")} 在这个底座上没验证)`); b.verified = null; changed = true; } + const tag = b.verified + ? b.verified.inherited ? ` ✓已验证(ABI继承自 ${b.verified.inherited.from})` + : b.verified.kind === "ci-arm64" ? " ✓已验证(CI arm64 selftest)" + : " ✓已验证(真机)" + : " (未验证)"; + console.log(`${id} ${b.version} for ${b.base.slice(0, 12)}${tag}`); + } + + const body = Buffer.from(JSON.stringify(idx, null, 1) + "\n"); + const jf = path.join(OUT, "components.json"); + fs.writeFileSync(jf, body); + const pem = process.env.INDEX_SIGNING_KEY || (process.env.INDEX_SIGNING_KEY_FILE && fs.readFileSync(process.env.INDEX_SIGNING_KEY_FILE, "utf8")); + if (!pem) { console.log("\n⚠ 没有 INDEX_SIGNING_KEY,只出未签名的索引(App 默认不认)"); process.exit(args.includes("--upload") ? 1 : 0); } + const key = crypto.createPrivateKey(pem); + const sig = crypto.sign(null, body, key).toString("base64"); + if (!crypto.verify(null, body, crypto.createPublicKey(key), Buffer.from(sig, "base64"))) throw new Error("自验签失败"); + fs.writeFileSync(jf + ".sig", sig + "\n"); + console.log(`\n✓ ${jf}(${Object.keys(idx.components).length} 个组件,已签名)`); + if (args.includes("--upload")) { + try { gh("release", "view", "index", "-R", REPO); } + catch { gh("release", "create", "index", "-R", REPO, "--title", "Component index / 组件索引", "--notes", "App 读这里的 components.json(ed25519 签名在 .sig)。由 CI 自动更新,别手动改。", "--latest=false"); } + const uploadFiles = [jf, jf + ".sig"]; + if (ciArg && fs.existsSync(ciArg)) { + const ciOut = path.join(OUT, "ci-verified.json"); + if (path.resolve(ciArg) !== path.resolve(ciOut)) fs.copyFileSync(ciArg, ciOut); + uploadFiles.push(ciOut); + } + gh("release", "upload", "index", "-R", REPO, ...uploadFiles, "--clobber"); + console.log(" ↑ 已上传到 index"); } } -for (const [id, c] of Object.entries(idx.components)) for (const b of c.builds) - console.log(`${id} ${b.version} for ${b.base.slice(0, 12)}${b.verified ? (b.verified.inherited ? ` ✓已验证(继承自 ${b.verified.inherited.from})` : " ✓已验证") : " (未真机验证)"}`); - -const body = Buffer.from(JSON.stringify(idx, null, 1) + "\n"); -const jf = path.join(OUT, "components.json"); -fs.writeFileSync(jf, body); -const pem = process.env.INDEX_SIGNING_KEY || (process.env.INDEX_SIGNING_KEY_FILE && fs.readFileSync(process.env.INDEX_SIGNING_KEY_FILE, "utf8")); -if (!pem) { console.log("\n⚠ 没有 INDEX_SIGNING_KEY,只出未签名的索引(App 默认不认)"); process.exit(args.includes("--upload") ? 1 : 0); } -const key = crypto.createPrivateKey(pem); -const sig = crypto.sign(null, body, key).toString("base64"); -if (!crypto.verify(null, body, crypto.createPublicKey(key), Buffer.from(sig, "base64"))) throw new Error("自验签失败"); -fs.writeFileSync(jf + ".sig", sig + "\n"); -console.log(`\n✓ ${jf}(${Object.keys(idx.components).length} 个组件,已签名)`); -if (args.includes("--upload")) { - try { gh("release", "view", "index", "-R", REPO); } - catch { gh("release", "create", "index", "-R", REPO, "--title", "Component index / 组件索引", "--notes", "App 读这里的 components.json(ed25519 签名在 .sig)。由 CI 自动更新,别手动改。", "--latest=false"); } - gh("release", "upload", "index", "-R", REPO, jf, jf + ".sig", "--clobber"); - console.log(" ↑ 已上传到 index"); + +if (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url))) { + main(); } diff --git a/tools/ci-verify-base.mjs b/tools/ci-verify-base.mjs new file mode 100644 index 0000000..a25f9f7 --- /dev/null +++ b/tools/ci-verify-base.mjs @@ -0,0 +1,257 @@ +// 批量 CI 实跑 selftest(arm64 + termux-docker):新底座打包完后,自动为所有不依赖手机硬件 +// (无 GPU / 屏幕 / Shizuku 需求)且尚未有验证记录的组件跑一遍安装 + first-run + selftest, +// 产出 ci-verified 片段供 build-index.mjs 合并进签名索引(kind: "ci-arm64")。 +// +// 用法: +// node tools/ci-verify-base.mjs [--base ] [--only ] [--shard ] +// [--ci-verified ] [--out ] +// [--strict] +import fs from "node:fs"; +import path from "node:path"; +import { execFileSync, spawnSync } from "node:child_process"; +import { ROOT, REPO, APP_REPO, recipes, bases, run, asset } from "./lib.mjs"; + +const args = process.argv.slice(2); +const opt = (k) => { const i = args.indexOf("--" + k); return i >= 0 ? args[i + 1] : undefined; }; +const STRICT = args.includes("--strict"); +const ONLY = opt("only") || ""; +const SHARD = opt("shard") || "0/1"; +const OUT = path.resolve(opt("out") || path.join(ROOT, "work", "ci-verified-shard.json")); +const WORK = path.resolve(process.env.WORK || path.join(ROOT, "work")); +const IMAGE = process.env.TERMUX_DOCKER_IMAGE || "termux/termux-docker:aarch64"; +const LIVE = "/data/data/cc.codroid", SNAP = "/opt/cc-base", USR = `${LIVE}/files/usr`; +const ST = path.join(WORK, "ci-verify"); +fs.mkdirSync(ST, { recursive: true }); +fs.mkdirSync(path.dirname(OUT), { recursive: true }); + +const [shardIdx, shardTotal] = SHARD.split("/").map((x) => Number(x)); +if (!Number.isInteger(shardIdx) || !Number.isInteger(shardTotal) || shardIdx < 0 || shardIdx >= shardTotal) { + console.error(`✗ --shard 格式应为 0/4 这种,收到:${SHARD}`); + process.exit(2); +} + +const gh = (...a) => run("gh", a); +const sudo = (...a) => execFileSync("sudo", a, { stdio: ["ignore", "pipe", "inherit"], maxBuffer: 1 << 26 }); +const needsHardware = (r) => { + const n = r.needs || {}; + return !!(n.gpu === "adreno" || n.gpu === "mali" || n.gpu === true || n.display || n.shizuku); +}; + +function loadExistingCiVerified() { + const p = opt("ci-verified"); + if (p && fs.existsSync(p)) return JSON.parse(fs.readFileSync(p, "utf8")); + const dl = path.join(ST, "existing-ci-verified.json"); + try { + gh("release", "download", "index", "-R", REPO, "-p", "ci-verified.json", "-O", dl, "--clobber"); + return JSON.parse(fs.readFileSync(dl, "utf8")); + } catch { + return {}; + } +} + +function inContainer(script, timeoutSec) { + const f = path.join(ST, "in.sh"); + fs.writeFileSync(f, [ + `export PREFIX=${USR} HOME=${LIVE}/files/home LANG=en_US.UTF-8 TERM=xterm-256color`, + `export TMPDIR=$PREFIX/tmp PATH=$PREFIX/bin:/system/bin SHELL=$PREFIX/bin/bash`, + `mkdir -p "$TMPDIR" "$HOME"`, + `[ -f $PREFIX/lib/libtermux-exec-ld-preload.so ] && export LD_PRELOAD=$PREFIX/lib/libtermux-exec-ld-preload.so`, + script, + ].join("\n") + "\n"); + const r = spawnSync("docker", ["run", "--rm", "-v", `${LIVE}:${LIVE}`, "-v", `${ST}:/st`, "--entrypoint", "/system/bin/sh", IMAGE, "/st/in.sh"], + { encoding: "utf8", timeout: (timeoutSec + 60) * 1000, maxBuffer: 1 << 26 }); + return { code: r.status ?? -1, out: ((r.stdout || "") + (r.stderr || "")).trim() }; +} + +const tag = opt("base") || bases()[0]?.tag; +if (!tag) { console.error("✗ bases.json 里没有底座"); process.exit(1); } + +const baseDir = path.join(WORK, "bases", tag); +fs.mkdirSync(baseDir, { recursive: true }); +const lockFile = path.join(baseDir, "devkit.lock.json"); +if (!fs.existsSync(lockFile)) { + gh("release", "download", tag, "-R", APP_REPO, "-p", "devkit.lock.json", "-D", baseDir, "--clobber"); +} +const lock = JSON.parse(fs.readFileSync(lockFile, "utf8")); +const baseSha = lock.gz.sha256; +const base12 = baseSha.slice(0, 12); + +const verified = JSON.parse(fs.readFileSync(path.join(ROOT, "verified.json"), "utf8")); +const existingCi = loadExistingCiVerified(); + +const allRecipes = recipes().sort((a, b) => a.id.localeCompare(b.id)); +const recipeById = new Map(allRecipes.map((r) => [r.id, r])); + +// 拉取某个组件在当前底座上最新发布的构建清单 + 资产名 +const metaCache = new Map(); +function latestBuildForBase(id) { + if (metaCache.has(id)) return metaCache.get(id); + const vcmp = (a, b) => a.localeCompare(b, "en", { numeric: true }); + let assets; + try { assets = JSON.parse(gh("release", "view", id, "-R", REPO, "--json", "assets")).assets.map((a) => a.name); } + catch { metaCache.set(id, null); return null; } + const assetSet = new Set(assets); + const dl = path.join(ST, "meta", id); + fs.rmSync(dl, { recursive: true, force: true }); + fs.mkdirSync(dl, { recursive: true }); + try { gh("release", "download", id, "-R", REPO, "-p", `*-for-${base12}.json`, "-D", dl); } + catch { metaCache.set(id, null); return null; } + let best = null; + for (const f of fs.readdirSync(dl)) { + const m = JSON.parse(fs.readFileSync(path.join(dl, f), "utf8")); + const name = asset(m.id, m.version, m.base.gz); + if (m.id !== id || m.base.gz !== baseSha || !assetSet.has(name + ".tar.gz")) continue; + if (!best || vcmp(m.version, best.version) > 0) best = { ...m, asset: name + ".tar.gz" }; + } + metaCache.set(id, best); + return best; +} + +const candidates = allRecipes.filter((r) => { + if (ONLY && r.id !== ONLY) return false; + if (needsHardware(r)) return false; + if (!r.selftest) return false; + return true; +}); + +const myCandidates = candidates.filter((_, idx) => idx % shardTotal === shardIdx); +const todo = []; +const rows = []; + +for (const r of myCandidates) { + const b = latestBuildForBase(r.id); + if (!b) { rows.push([r.id, "—", `底座 ${base12} 尚无构建`]); continue; } + if (verified[r.id]?.[b.version]?.[base12]) { rows.push([r.id, "✓", "已有真机验证,跳过"]); continue; } + const prevCi = existingCi[r.id]?.[b.version]?.[base12]; + if (prevCi && prevCi.gzSha256 === b.gz.sha256) { rows.push([r.id, "✓", "已有同哈希 CI 验证,跳过"]); continue; } + todo.push({ recipe: r, build: b }); +} + +console.log(`底座 ${tag}(${base12})· shard ${shardIdx}/${shardTotal} · 待跑 ${todo.length} / ${myCandidates.length}`); + +const passed = {}; +let fails = 0; + +if (todo.length) { + const gz = path.join(WORK, "base-gz", tag, `devkit-${lock.target || "cc.codroid"}.tar.gz`); + if (!fs.existsSync(gz)) { + fs.mkdirSync(path.dirname(gz), { recursive: true }); + execFileSync("gh", ["release", "download", tag, "-R", APP_REPO, "-p", path.basename(gz), "-O", gz], { stdio: "inherit" }); + } + console.log(`解包底座 ${tag} 并跑首次运行…`); + sudo("rm", "-rf", LIVE, SNAP); + sudo("mkdir", "-p", `${LIVE}/files/home`); + sudo("tar", "xzf", gz, "-C", `${LIVE}/files`); + const fr = inContainer(`sh $PREFIX/libexec/devkit/first-run.sh >/st/base-first-run.log 2>&1; echo "rc=$?"`, 900); + console.log(" base first-run: " + fr.out.split("\n").pop()); + sudo("cp", "-a", LIVE, SNAP); + + const downloadAsset = (id, assetName) => { + const p = path.join(ST, "pkg", id, assetName); + if (!fs.existsSync(p)) { + fs.mkdirSync(path.dirname(p), { recursive: true }); + gh("release", "download", id, "-R", REPO, "-p", assetName, "-O", p, "--clobber"); + } + return p; + }; + const downloadModule = (mid) => { + const fname = `devkit-${mid}-${lock.target || "cc.codroid"}.tar.gz`; + const p = path.join(ST, "mod", tag, fname); + if (!fs.existsSync(p)) { + fs.mkdirSync(path.dirname(p), { recursive: true }); + gh("release", "download", tag, "-R", APP_REPO, "-p", fname, "-O", p, "--clobber"); + } + return p; + }; + + // 解析组件依赖链(拓扑序:依赖在前,支持 requires 里的 module:) + const collectDeps = (id, seen = new Set(), compChain = [], modIds = new Set()) => { + if (seen.has(id)) return { compChain, modIds, missing: null }; + seen.add(id); + const r = recipeById.get(id); + if (!r) return { compChain, modIds, missing: id }; + for (const req of r.requires || []) { + if (req.startsWith("module:")) { modIds.add(req.slice(7)); continue; } + const sub = collectDeps(req, seen, compChain, modIds); + if (sub.missing) return sub; + } + const b = latestBuildForBase(id); + if (!b) return { compChain, modIds, missing: `${id}@${base12}` }; + compChain.push({ id, build: b }); + return { compChain, modIds, missing: null }; + }; + + for (const { recipe: r, build: b } of todo) { + console.log(`\n══ [${r.id}] ${b.version}:${r.selftest}`); + const deps = collectDeps(r.id); + if (deps.missing) { + fails++; + rows.push([r.id, "❌", `依赖 ${deps.missing} 在底座 ${base12} 上缺构建`]); + continue; + } + sudo("rm", "-rf", LIVE); + sudo("cp", "-a", SNAP, LIVE); + + // 额外可选模块(full:false 的模块不在整包里,如 go/node/rust,按需叠加) + const modFirstRuns = []; + let depErr = null; + for (const mid of deps.modIds) { + try { + const mtar = downloadModule(mid); + sudo("tar", "xzf", mtar, "-C", `${LIVE}/files`); + modFirstRuns.push(`f=$PREFIX/libexec/devkit/modules/${mid}/first-run.sh; [ -f "$f" ] && sh "$f"`); + } catch (e) { depErr = `模块 ${mid} 下载失败:${e.message.split("\n")[0]}`; break; } + } + if (depErr) { fails++; rows.push([r.id, "❌", depErr]); continue; } + + for (const c of deps.compChain) { + const tar = downloadAsset(c.id, c.build.asset); + sudo("tar", "xzf", tar, "-C", `${LIVE}/files`); + } + const compFirstRuns = deps.compChain.map((c) => `f=$PREFIX/libexec/devkit/components/${c.id}/first-run.sh; [ -f "$f" ] && { PIP_NO_INDEX=1 sh "$f" || echo "(${c.id} first-run rc=$?)"; }`); + fs.writeFileSync(path.join(ST, "cmd"), r.selftest + "\n"); + const runRes = inContainer([ + ...modFirstRuns, + ...compFirstRuns, + `cd "$HOME"; timeout 300 $PREFIX/bin/bash /st/cmd >/st/${r.id}.log 2>&1; echo "rc=$?"`, + ].join("\n"), 900); + const code = Number((/rc=(\d+)\s*$/.exec(runRes.out) || [])[1] ?? -1); + let log = ""; try { log = fs.readFileSync(path.join(ST, `${r.id}.log`), "utf8").trim(); } catch {} + const last = log.split("\n").filter(Boolean).slice(-1)[0] || ""; + console.log(log.split("\n").slice(-6).map((l) => " | " + l).join("\n") + `\n rc=${code}`); + + if (code === 0) { + passed[r.id] = { + [b.version]: { + [base12]: { + kind: "ci-arm64", + date: new Date().toISOString().slice(0, 10), + device: "GitHub Actions ubuntu-24.04-arm (termux-docker:aarch64)", + app: `devkit ${tag}`, + gzSha256: b.gz.sha256, + checks: `ci-verify-base on ${tag}: installed on real base snapshot; first-run ok; selftest exit 0${last ? ": " + last.slice(0, 140) : ""}`, + by: "github-actions[bot]", + }, + }, + }; + rows.push([r.id, "✅", `selftest 0${last ? ";`" + last.slice(0, 80).replace(/`/g, "'") + "`" : ""}`]); + } else { + fails++; + rows.push([r.id, "❌", `${code === 124 ? "超时(5 分钟)" : "退出码 " + code}${last ? ";`" + last.slice(0, 80).replace(/`/g, "'") + "`" : ""}`]); + } + } + sudo("rm", "-rf", LIVE, SNAP); +} + +fs.writeFileSync(OUT, JSON.stringify(passed, null, 2) + "\n"); +const md = [ + `### CI 自动验证(底座 \`${tag}\` · shard ${shardIdx}/${shardTotal})`, + "", + rows.length ? "| 组件 | 结果 | 说明 |\n|---|---|---|\n" + rows.map((r) => `| ${r.join(" | ")} |`).join("\n") : "本分片无待验证组件。", + "", + `通过 ${Object.keys(passed).length} 个,失败 ${fails} 个(硬件组件已跳过,仍须真机验证)。`, + "", +].join("\n"); +console.log("\n" + md); +if (process.env.GITHUB_STEP_SUMMARY) fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, md); +if (STRICT && fails > 0) process.exit(1); diff --git a/tools/test-verify.mjs b/tools/test-verify.mjs new file mode 100644 index 0000000..4267226 --- /dev/null +++ b/tools/test-verify.mjs @@ -0,0 +1,66 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { isHardwareBound, basePkgAbiBreaking, inheritBlockerWithLocks, mergeCiVerified } from "./build-index.mjs"; + +test("isHardwareBound:仅 GPU / display / shizuku 强制真机验证", () => { + assert.equal(isHardwareBound({}), false); + assert.equal(isHardwareBound({ gpu: false, display: false, shizuku: false }), false); + assert.equal(isHardwareBound({ gpu: "adreno" }), true); + assert.equal(isHardwareBound({ gpu: "mali" }), true); + assert.equal(isHardwareBound({ gpu: true }), true); + assert.equal(isHardwareBound({ display: true }), true); + assert.equal(isHardwareBound({ shizuku: true }), true); +}); + +test("basePkgAbiBreaking 与 inheritBlockerWithLocks:补丁/次版本漂移允许继承,ABI-MAJOR 阻断继承", () => { + const lockOld = { + pkgs: new Map([ + ["bash", "5.2.37"], + ["openssl", "3.5.0"], + ["python", "3.14.8"], + ["libicu", "78.3"], + ["npm", "11.10.0"], + ["zlib", "1.3.2"], + ]), + sonames: null, + }; + const lockNew = { + pkgs: new Map([ + ["bash", "5.2.38"], + ["openssl", "3.5.1"], + ["python", "3.14.10"], + ["libicu", "79.1"], + ["npm", "12.2.2"], + ["zlib", "1.4"], + ]), + sonames: null, + }; + + // 不依赖 libicu 的组件(只依赖 bash/openssl/python/npm/zlib):全部属于兼容漂移,允许继承 + const ghOld = { packages: [{ name: "gh", sha256: "aaa" }], baseDeps: [{ name: "bash" }, { name: "openssl" }, { name: "npm" }, { name: "zlib" }] }; + const ghNew = { packages: [{ name: "gh", sha256: "aaa" }], baseDeps: [{ name: "bash" }, { name: "openssl" }, { name: "npm" }, { name: "zlib" }] }; + assert.equal(inheritBlockerWithLocks(ghNew, ghOld, lockNew, lockOld), null); + + // 依赖 libicu 的组件:libicu 78.3→79.1 属于 ABI-MAJOR,必须阻断继承 + const loOld = { packages: [{ name: "libreoffice", sha256: "bbb" }], baseDeps: [{ name: "libicu" }, { name: "openssl" }] }; + const loNew = { packages: [{ name: "libreoffice", sha256: "bbb" }], baseDeps: [{ name: "libicu" }, { name: "openssl" }] }; + const block = inheritBlockerWithLocks(loNew, loOld, lockNew, lockOld); + assert.match(block, /libicu/); + + // 若新旧底座锁文件带实测 SONAME 且完全相同,即使主版本变了也不误拦 + const snOld = { pkgs: new Map([["libxml2", "2.13.8"]]), sonames: { libxml2: ["libxml2.so.2"] } }; + const snNewSame = { pkgs: new Map([["libxml2", "3.0.0"]]), sonames: { libxml2: ["libxml2.so.2"] } }; + const snNewBroken = { pkgs: new Map([["libxml2", "2.14.0"]]), sonames: { libxml2: ["libxml2.so.16"] } }; + assert.equal(basePkgAbiBreaking("libxml2", snOld, snNewSame), null); + assert.match(basePkgAbiBreaking("libxml2", snOld, snNewBroken), /SONAME/); +}); + +test("mergeCiVerified:合并多片结果并保留历史底座记录", () => { + const prev = { gh: { "2.104.0-r2": { oldbase12345: { kind: "ci-arm64", gzSha256: "111" } } } }; + const shard0 = { gh: { "2.104.0-r2": { newbase67890: { kind: "ci-arm64", gzSha256: "222" } } } }; + const shard1 = { d2: { "0.9.0-r1": { newbase67890: { kind: "ci-arm64", gzSha256: "333" } } } }; + const merged = mergeCiVerified(prev, shard0, shard1); + assert.equal(merged.gh["2.104.0-r2"].oldbase12345.gzSha256, "111"); + assert.equal(merged.gh["2.104.0-r2"].newbase67890.gzSha256, "222"); + assert.equal(merged.d2["0.9.0-r1"].newbase67890.gzSha256, "333"); +}); diff --git a/tools/verify-device.mjs b/tools/verify-device.mjs index b7ddfdc..1286378 100644 --- a/tools/verify-device.mjs +++ b/tools/verify-device.mjs @@ -5,7 +5,8 @@ // node verify-device.mjs --pending --app … --by … [--out 结果.txt] [--pr] // --pr:跑完直接把通过的记录并进 verified.json、开 PR(用 gh,要已登录且对市场仓库有写权限; // 没权限就照旧打印,手动提)。不用 clone 仓库,走 GitHub API。 -// 批量:索引里当前工具包有构建、还没验证(直接验或继承都算验过)的组件,按依赖顺序挨个验。 +// 批量:索引里当前工具包有构建、还没验证(真机直接验、ABI 继承、或非硬件组件的 CI arm64 自动验证都算已验; +// 只剩硬件组件与 CI 未通过的少数几项)的组件,按依赖顺序挨个验。加 --include-ci 可把仅 CI 验过的也纳入真机复验。 // 全部跑完打印一份合并好的记录(只含通过的),没通过的列在最后。开着屏幕等它跑完即可。 // // 做的事: @@ -29,6 +30,8 @@ const APP = opt("--app"), BY = opt("--by") || "", OUT = opt("--out"), KEEP = fla const IDS = (opt("--ids") || "").split(",").map((x) => x.trim()).filter((x) => /^[a-z0-9][a-z0-9-]{0,39}$/.test(x)); // --all:索引里所有适配当前工具包、本机能用的组件(社区在前、预置在后)——验证清单从索引取,不靠人手列 const ALL = flag("--all"); +// --include-ci:把索引里仅由 CI arm64 验过(还没有真机 verified.json 记录)的组件也纳入 --pending +const INCLUDE_CI = flag("--include-ci"); const PENDING = PENDING0 || IDS.length > 0 || ALL; // selftest 的时限(分钟)。blender 这类第一次运行要先下载、解包运行环境(几百 MB),5 分钟不够 const SELFTEST_MIN = Number(opt("--selftest-timeout") || 5); @@ -295,9 +298,20 @@ if (!PENDING) { records = r.record; } else { const ix = await list(true); + // 若传了 --include-ci,去索引查哪些组件目前只有 ci-arm64 验证(无真机记录) + let ciOnlySet = new Set(); + if (INCLUDE_CI && !IDS.length && !ALL) { + try { + const pubIdx = await (await fetch("https://github.com/greyoak111/cccodroid-components/releases/download/index/components.json")).json(); + for (const [id, c] of Object.entries(pubIdx.components || {})) { + const b = (c.builds || []).find((x) => String(x.base).startsWith(ix.devkit)); + if (b && b.verified?.kind === "ci-arm64") ciOnlySet.add(id); + } + } catch {} + } const todo = IDS.length ? IDS.filter((id) => ix.items.some((c) => c.id === id)) : ALL ? ix.items.filter((c) => c.available && !c.unsupported).sort((a, b) => (a.source === "preset") - (b.source === "preset") || a.id.localeCompare(b.id)).map((c) => c.id) - : ix.items.filter((c) => c.available && !c.verified && c.source !== "preset").map((c) => c.id); + : ix.items.filter((c) => c.available && !c.unsupported && (!c.verified || ciOnlySet.has(c.id)) && c.source !== "preset").map((c) => c.id); if (ALL) for (const c of ix.items.filter((c) => !c.available || c.unsupported)) log(`· 跳过 ${c.id}:${c.unsupported ? `要 ${c.unsupported} GPU,本机没有` : "没有适配当前工具包的构建"}`); if (IDS.length && todo.length < IDS.length) log(`⚠ 索引里没有:${IDS.filter((id) => !todo.includes(id)).join("、")}`); // 依赖排在前面:被依赖的先验,后面装依赖时用的就是刚验过的