Documentation
¶
Overview ¶
Package mirror 提供"双仓双身份"的 Go module 镜像发布。
一份源码、两个可被 go get 的模块身份:canonical 仓库保持只读(连对象库 都不写入),每个 tag 在镜像侧合成为一个身份改写后的独立孤儿 commit (无父提交),各版本互不依赖,可对任意历史 tag 重跑。go get 按 tag 取 快照、proxy 按 tag 永久缓存,因此同 tag 的 tree 必须确定性一致——重跑 只允许改变 commit 包装,不允许改变内容;本包的合成 commit 继承源 commit 的作者/提交者身份与时间戳,同 tag 重跑 hash 完全一致。
流程:前置校验 → 读源树并全量身份改写 → 物化到临时目录跑 go build 门禁 → 镜像远端同名 tag 的 tree 一致性检查(不一致默认中止)→ 合成 tree/commit/附注 tag 写入临时仓库 → 强推 tag 与 main 快照 → 清理。
git 侧全部通过 go-git 对象 API 与 SDK gitbackend 完成,不执行任何 动态参数的子进程;go 工具链调用(build 门禁、模块验证)只用静态参数, 动态数据经由文件传递。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadModulePath ¶
ReadModulePath 从 dir/go.mod 解析 module 行(兼容带引号写法),供壳层 创建通道时带出源模块身份。
func VerifyModule ¶
VerifyModule 验证 module@version 已可被 go 工具链正常消费,成功即同时 证明:仓库可达、版本存在、zip 拉取成功、模块 go.mod 声明的身份与 module 一致——与在临时模块中执行 `go list -m <module>@<version>` 等价。
实现:在临时目录写入仅含 require 的 go.mod(动态数据只经文件传递), 由 go/packages 驱动工具链解析该模块的全部包。需要网络与 GOPROXY 配置; 私有模块需按 go 惯例设置 GOPRIVATE 等环境。
Types ¶
type Mapping ¶
type Mapping struct {
// Source 是 canonical module path,须与 RepoDir/go.mod 的 module 行一致。
Source string
// Target 是镜像 module path(如 github.com/org/repo)。
Target string
}
Mapping 描述一次模块身份改写:canonical module path → 镜像 module path。
type Options ¶
type Options struct {
// RepoDir 是 canonical 仓库的工作区路径(读取 go.mod、tag 与远端配置)。
RepoDir string
// Mapping 指定身份改写方向。
Mapping Mapping
// Tags 是要发布的 tag 列表,至少一个;每个 tag 独立生成孤儿快照,
// 支持批量补历史版本。单个失败即中止,之前成功的保留。
Tags []string
// Remote 是 canonical 仓库中指向镜像仓库的远端名,默认 "github"。
Remote string
// Auth 是访问镜像远端用的凭据;零值(AuthNone)时 native 后端以
// 本机 git 默认凭据(ssh-agent、credential helper)推送。
Auth gitbackend.AuthConfig
// AllowOverwrite 允许覆盖镜像远端上 tree 不一致的同名 tag。
// false 时检测到不一致直接报错,保护已发布版本不被误覆盖。
AllowOverwrite bool
// DryRun 为 true 时执行到远端一致性检查为止(校验、身份改写、门禁、
// 远端比对),不合成 commit/tag、不推送;用于发布前预检。
DryRun bool
}
Options 是一次镜像发布的输入。
type TagReport ¶
type TagReport struct {
Tag string
SourceCommit string
Tree string
Commit string
// ReplacedFiles 是发生了身份改写的文件(仓库内相对路径)。
ReplacedFiles []string
// VerifyCmd 是发布后建议执行的验证命令。
VerifyCmd string
// RemoteTagExisted 表示推送前镜像远端已存在同名 tag。
RemoteTagExisted bool
// TreeMatchedRemote 表示远端已有 tag 的 tree 与本次合成结果一致
// (重跑幂等的直接证据);仅在 RemoteTagExisted 且成功比对时有意义。
TreeMatchedRemote bool
// OverwroteDivergent 表示在 tree 不一致且 AllowOverwrite 下完成了覆盖。
OverwroteDivergent bool
}
TagReport 是单个 tag 的发布报告。