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
59 changes: 59 additions & 0 deletions .github/compose/check-hub-contract.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node
// Hub contract: everything this repository's workflows call in the private
// components must exist in the assembled workspace. Run from the workspace root.
//
// node .github/compose/check-hub-contract.mjs # names and paths only
// node .github/compose/check-hub-contract.mjs --run-tests # also run ci.yml's node:test suites
//
// Component CI runs it on every private-repo PR, so removing or renaming a script
// that a deploy-branch workflow uses fails there, not after release (server v1.0.5).
// --run-tests brings ci.yml's dependency-free node:test suites to PR time, such as
// the production migration approval guard (the 0034 incident).
import { readdirSync, readFileSync, existsSync } from 'node:fs';
import { execFileSync } from 'node:child_process';
import { join } from 'node:path';

const workflowsDir = '.github/workflows';
// Tests come from ci.yml's Application checks job (verify), which needs no services;
// these of its suites need a build or the workerd runtime that PR CI does not set up.
const testsNeedingBuild = new Set(['scripts/google-oauth-workerd.test.mjs', 'scripts/cost-monitor-watchdog.test.mjs', 'scripts/cost-monitor-verify.test.mjs', 'scripts/traffic-report-preview.test.mjs']);
const pnpmBuiltins = new Set(['install', 'i', 'add', 'exec', 'dlx', 'run', 'why', 'store', 'list', 'ls', 'audit']);

// Commands only: comment lines often quote commands that no longer exist.
const commandText = file => readFileSync(`${workflowsDir}/${file}`, 'utf8').split('\n').filter(line => !/^\s*#/.test(line)).join('\n');
// component-*.yml run in the private repos' own CI, which already fails on them.
const workflows = readdirSync(workflowsDir).filter(f => /\.ya?ml$/.test(f) && !f.startsWith('component-')).map(file => ({ file, text: commandText(file) }));
// A step starts at "- key:"; its commands resolve against its working-directory.
const steps = text => text.split(/\n(?=\s*- [\w-]+:)/).map(body => ({ body, dir: body.match(/^\s*working-directory:\s*['"]?([^'"\s]+)/m)?.[1] ?? '.' }));
const scriptsIn = dir => existsSync(join(dir, 'package.json')) ? JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')).scripts ?? {} : {};
const problems = [];

for (const { file, text } of workflows) {
for (const { body, dir } of steps(text)) {
if (dir.includes('${{')) continue;
const scripts = scriptsIn(dir);
for (const [, name] of body.matchAll(/(?:^|[ \t;&|(])pnpm[ \t]+(?:run[ \t]+)?([a-z][\w:.-]*)/gm)) {
if (!pnpmBuiltins.has(name) && !Object.hasOwn(scripts, name)) problems.push(`${file}: pnpm ${name} — no such script in ${join(dir, 'package.json')}`);
}
for (const [path] of body.matchAll(/(?<![\w/.-])scripts\/[\w./-]+\.(?:mjs|mts|cjs|js|ts|py|sh)\b/g)) {
if (!existsSync(join(dir, path))) problems.push(`${file}: ${join(dir, path)} — file missing`);
}
}
}

if (problems.length) {
console.error(`hub contract: ${problems.length} broken reference(s) from FindAny/ghfind workflows:`);
for (const p of [...new Set(problems)]) console.error(` - ${p}`);
console.error('Release the hub change that drops these references before releasing the component (docs/runbook.md, "Release order").');
process.exit(1);
}
console.log(`hub contract: ${workflows.length} workflows, every pnpm script and scripts/ path resolves`);

if (process.argv.includes('--run-tests')) {
const ci = workflows.find(w => w.file === 'ci.yml').text;
const verifyJob = ci.match(/\n verify:\n([\s\S]*?)(?=\n [a-z][\w-]*:\n|$)/)?.[1];
if (!verifyJob) throw new Error('hub contract: ci.yml has no verify job');
const tests = [...new Set([...verifyJob.matchAll(/node --test ([^\n;&|]+)/g)].flatMap(([, list]) => list.trim().split(/\s+/)))].filter(t => !testsNeedingBuild.has(t));
console.log(`hub contract: running ${tests.length} ci.yml node:test suites`);
execFileSync(process.execPath, ['--test', ...tests], { stdio: 'inherit' });
}
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ jobs:
- name: Install locked dependencies
run: pnpm install --frozen-lockfile

- name: Hub contract (every script these workflows call exists)
run: node .github/compose/check-hub-contract.mjs

- name: Verify release versions
# Consistency of config/release-versions.json and the version constants in
# the assembled workspace. The diff-based rule (a version change must update
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/component-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ jobs:
echo "::error::Dependencies differ from ghfind-server's pnpm-lock.yaml. Dependency changes need a matching lockfile update in FindAny/ghfind-server."
exit 1
fi
- name: Hub contract (scripts the deploy workflows call, release contract tests)
working-directory: workspace
run: |
# The workspace is the latest hub release; releases before the check have no script.
if [ -f .github/compose/check-hub-contract.mjs ]; then node .github/compose/check-hub-contract.mjs --run-tests
else echo "::notice::hub ${{ steps.public.outputs.ref }} predates the hub contract check"; fi
- name: Verify release versions against ghfind-server history
if: inputs.component == 'ghfind-server'
working-directory: self
Expand Down
6 changes: 3 additions & 3 deletions docs/deployment.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ ghfind 是 GitHub 开发者与开源项目的评估平台,生产站点为 <htt

### 4.3 发布顺序规则

公开仓库的流水线会调用后端仓库的脚本,而部署提交使用的是公开仓库**最新已发布版本**中的流水线。因此,如果后端改动删除或改名了流水线依赖的脚本或命令,必须先更新并发布公开仓库,再发布后端,否则部署前的全量测试会失败,生产不会更新(不影响线上运行)。
公开仓库的流水线会调用后端仓库的脚本,而部署提交使用的是公开仓库**最新已发布版本**中的流水线。因此,如果后端改动删除或改名了流水线依赖的脚本或命令,必须先更新并发布公开仓库,再发布后端,否则部署前的全量测试会失败,生产不会更新(不影响线上运行)。私有仓库的每个 Pull Request 都会自动检查这一点:公开仓库流水线依赖的脚本或命令一旦缺失,PR 检查即失败。

### 4.4 实际耗时(参考)

Expand All @@ -117,15 +117,15 @@ Feed(社区信息流)运行在 Cloudflare Containers 中,发布风险高
## 6. 数据库变更管理

- 核心数据库(D1)的迁移文件放在私有后端仓库中,按编号顺序执行,原则上只做增量变更(新增表、列、索引)。
- **生产审批清单**:生产部署只执行列在 `ops/feed-production-schema-release.json` 中的迁移,每个文件都附 SHA-256 校验值。迁移文件在审批后被改动的,部署会直接报错(approved migration changed)并停止。新迁移需要单独提交审批,并通过测试后才会进入生产。
- **生产审批清单**:生产部署只执行列在 `ops/feed-production-schema-release.json` 中的迁移,每个文件都附 SHA-256 校验值。迁移文件在审批后被改动的,部署会直接报错(approved migration changed)并停止。新迁移需要单独提交审批,并通过测试后才会进入生产。后端仓库的 PR 检查会核对:每个迁移文件都必须已列入审批清单(少数历史迁移列在冻结的例外名单中),否则检查失败,避免新迁移被生产静默跳过。
- 生产迁移由部署流水线按审批清单执行。Worker 回滚不会回滚数据库,因此破坏性变更(删除、改名)必须分步进行:先上线兼容的新代码,再在后续版本中清理。

## 7. 质量保障

| 阶段 | 检查内容 |
| --- | --- |
| Pull Request | 评分三语言一致性与开源边界、JavaScript SDK、工作流语法与仓库保护策略(必须全部通过才能合并) |
| 合并到 main | 私有仓库:类型检查、代码规范、单元测试、Go 测试、前端构建;公开仓库:全量测试 |
| 合并到 main | 私有仓库:类型检查、代码规范、单元测试、Go 测试、前端构建、公开仓库流水线依赖检查与发布契约测试(含迁移审批核对);公开仓库:全量测试 |
| 版本发布 | 发布流水线再次确认该提交的 CI 已通过,否则拒绝发布 |
| 部署前 | deploy 分支全量测试;部署流水线核对“该提交的 CI 已成功”的证据,核对不通过则在任何写操作之前停止 |
| 部署后 | 公开冒烟测试(首页、排行榜、个人页、评分 API、徽章、站点地图等);失败则自动回滚到部署前记录的版本,并再次验证 |
Expand Down
6 changes: 4 additions & 2 deletions docs/runbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ workflows of the latest *released* hub. So when a server change removes or renam
something a hub workflow uses, update the hub, merge it and release it first. Only
then release the server. Otherwise CI on `deploy` fails and nothing deploys. (This
happened on 2026-11-08: server v1.0.5 removed `smoke:backend:*` while hub v1.0.1
still ran it. Fixed by hub v1.0.2.) Before tagging, check with
`grep -rn '<removed name>' .github/` here.
still ran it. Fixed by hub v1.0.2.) Component CI enforces this: on every private-repo
PR, `.github/compose/check-hub-contract.mjs` fails if a `pnpm` script or `scripts/`
file that a hub workflow calls is missing. It also runs ci.yml's Application-checks
`node:test` suites, which include the production migration approval guard.

### compose

Expand Down
Loading