Files
marqdo/scripts/component-release/README.md
T
cflmy b10b360cf4 fix: harden the component release transaction after review
- Build the archive from exact Git objects (git ls-tree / git cat-file) with
  fixed tar and gzip metadata instead of git archive + gzip, so export-ignore,
  export-subst and local attribute files cannot silently drop or rewrite
  released bytes; verify every member and byte against the commit blobs.
- Select the same-SHA CI pipeline deterministically (lowest successful number)
  so re-running the transaction reproduces already published evidence.
- Preflight the remote tag identity, require channel consistency on idempotent
  re-runs, add --reset-draft recovery for interrupted drafts, and stop
  forwarding the publish token across redirects.
- Reject case/NFC collisions, backslash/control-character members, wildcard
  allow entries, unknown/duplicate dependency fields; honor --source-sha and
  --out-dir in check; clean temporary directories.
- Fix the documented/template dependency syntax and add regression tests for
  determinism, export attributes, collisions, deterministic CI selection and
  remote tag identity.
2026-12-02 23:12:44 +08:00

89 lines
5.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Component release kit(唯一实现)
本目录是 Marqdo 生态**标准库与扩展库共用的组件独立发行事务**的唯一实现,
落实 [marqdo#96](https://git.cflmy.cn/cflmy/marqdo/issues/96) M1。各功能仓不复制
第二份打包/证据/发布代码,只在 `.woodpecker/publish.yml` 中引导本文件并登记自身
的发布路径;普通 push/PR 使用同一入口做确定性打包自检。
## 1. 它负责什么
| 步骤 | 行为 |
| --- | --- |
| 打包 | 从精确 tag commit 的 Git 对象(`git ls-tree` + `git cat-file`)重建**受评审路径**,固定 tar 元数据(mtime 0、uid/gid 0、mode 0644、排序路径)与 gzip 头(mtime 0、无文件名);连续打包两次必须逐字节一致,并在上传前把归档成员集合与字节回验到 commit blob。不使用 `git archive`,因此 `export-ignore`/`export-subst` 等 attributes 不能静默丢文件或改写内容;不含 `.git`、测试、缓存、凭证或工作树改动 |
| 证据 | 生成现行 `release-evidence.json`(字段与 `scripts/reconcile-releases.py` 校验一致),不新增 stdlib/ext 专用清单 |
| CI 证据 | 通过 Woodpecker 公开只读 API 找到**同 SHA** 成功的 `ci` workflow,并**确定性地选择编号最小的一次**(重跑会复现已发布的同一份证据);没有同 SHA CI 时拒绝发布 |
| 发布 | Gitea Release 草稿事务:发布前校验远端 tag 已存在时必须指向发布 commit;先传 payload、最后传证据索引、逐字节回读 sha256、再公开;已公开的同 tag 不同字节拒绝覆盖,相同字节且渠道一致时幂等成功;中断草稿可用 `--reset-draft` 显式重建;token 不随重定向转发 |
它不枚举依赖图、不修改 gitlink、不自动晋升、不自动通知合并。发行是组件事实;
根推荐/接受、消费者接入是另外的事实。
## 2. 组件仓接线
普通 CI(`.woodpecker/ci.yml`)在真实测试后追加确定性打包自检:
```yaml
- |
set -eu
kit=$(mktemp -d); trap 'rm -rf "$kit"' EXIT
base="https://git.cflmy.cn/cflmy/marqdo/raw/commit/<ROOT_COMMIT>"
curl -fsSL --retry 3 "$base/scripts/component-release/release.py" -o "$kit/release.py"
echo "<RELEASE_PY_SHA256> $kit/release.py" | sha256sum -c -
python3 "$kit/release.py" check \
--repository "$CI_REPO" --component-id <component-id> --kind stdlib \
--allow modules --allow README.md
```
受保护发布流水线(`.woodpecker/publish.yml`)只在 tag 事件运行:
```yaml
when:
event: [tag]
```
模板见 [templates/publish.yml](templates/publish.yml)。`GITEA_PUBLISH_TOKEN`
只授予该 tag 工作流,普通 PR/push 不得持有发布凭据(各仓 Woodpecker secret
已按 `manual,tag` 事件隔离)。
`<ROOT_COMMIT>` 与 `<RELEASE_PY_SHA256>` 是**唯一实现**的不可变 pin:升级 kit 时在
根仓评审、合并,再以新的根提交与文件摘要更新各组件仓的 pin 与相应 tag/证据。
pin 变更本身是普通组件 PR,不改变任何已发布资产。
## 3. 发布路径与产物
- stdlib:`modules/`(Bundle 根相对路径)与 `README.md`;产物
`marqdo-<repo>-<version>-source.tar.gz`,`target=source`。
- extension:`index.mq.md`、`marqdo.yaml`、`modules/`、`README.md`;产物
`marqdo-<repo>-<version>-package.tar.gz`,`target=source`。
- 版本由组件仓自己决定(SemVer,tag `v<version>`),与 CLI/Bundle/MQDH 版本无关。
- 依赖只登记**测试时实际使用**的精确组件身份(当前 stdlib 为 `cli` 的已发布源
SHA 与归档摘要);不得把设计输入或目录关系写成测试依赖。
## 4. 命令
```sh
# 同 SHA 确定性打包自检(不联网、不写发布)
python3 release.py check --repository cflmy/marqdo-std-text --component-id std-text \
--kind stdlib --allow modules --allow README.md
# 受保护发布(GITEA_PUBLISH_TOKEN 只在此使用)
GITEA_PUBLISH_TOKEN=... python3 release.py publish \
--repository cflmy/marqdo-std-text --component-id std-text \
--kind stdlib --allow modules --allow README.md \
--tag v0.1.0 \
--dependency "id=cli,source_sha=<cli-source-sha>,asset_sha256=<cli-archive-sha256>"
```
`publish` 校验:HEAD 必须等于发布 commit;tag 若已在本地存在必须指向该 commit;
版本字符串决定渠道(含 `-` 后缀即 prerelease,与 Gitea 标记一致);同 SHA 的
`ci` 流水线必须成功;全部资产回读摘要一致后才公开。
## 5. 边界
- 不取代 `scripts/reconcile-releases.py` 的独立核验:发布后仍由根对账做
tag→SHA、同 SHA CI、资产逐字节回读与依赖一致性检查。
- 不发布根推荐状态,不写消费者锁,不触发自动安装。
- 历史已发布的 std-text `v0.0.0-ci10.1` 演练发行不计为合格发行;本入口产生的
新发行使用真实同 SHA CI 证据。
- 规则变更走根仓 PR + 集成测试(`tests/integration/test_component_release.py`),
不在单个组件仓另行维护规则。