fix(version): 补全开发快照记录与同步交付闭环
build / build (push) Successful in 1m3s

收录 main、注释开发快照和完整运行 SHA;开发说明绑定原提交,补记 0.1.1–0.1.25。
进行中同步按仓库合并,完成后重新执行;启动入队,部署脚本读回版本证据。
开发快照独立于正式标签与 Release,既有冲突标签不移动。

已运行:整仓 make verify,Go 673 通过、前端 274 通过,92 个已声明可选跳过,必需跳过 0。
隔离 PostgreSQL 重复同步队列用例及 -race 通过;未更新现有 8088、未修改生产问答。
This commit is contained in:
姚章浩
2026-10-18 18:11:49 +08:00
parent 90901a4458
commit 013ce4a24e
19 changed files with 860 additions and 32 deletions
+53 -16
View File
@@ -130,22 +130,24 @@ type SyncOutcome struct {
// SyncerConfig 装配同步器。
type SyncerConfig struct {
Source Source
Store SyncStore
RepoKey string
Changelog string // 提交内的变更记录文件路径,默认 CHANGELOG.md
Now func() time.Time
MaxPages int
Source Source
Store SyncStore
RepoKey string
Changelog string // 提交内的变更记录文件路径,默认 CHANGELOG.md
Now func() time.Time
MaxPages int
TargetSHAs []string
}
// Syncer 抓取远端 main 可达的全部提交并换算版本记录。
type Syncer struct {
source Source
store SyncStore
repoKey string
changelog string
now func() time.Time
maxPages int
source Source
store SyncStore
repoKey string
changelog string
now func() time.Time
maxPages int
targetSHAs []string
}
const syncerDefaultMaxPages = 200
@@ -170,7 +172,12 @@ func NewSyncer(config SyncerConfig) (*Syncer, error) {
if maxPages <= 0 {
maxPages = syncerDefaultMaxPages
}
return &Syncer{source: config.Source, store: config.Store, repoKey: config.RepoKey,
for _, sha := range config.TargetSHAs {
if !fullSHA.MatchString(sha) {
return nil, errors.New("版本记录:运行身份必须是完整 SHA")
}
}
return &Syncer{targetSHAs: append([]string{}, config.TargetSHAs...), source: config.Source, store: config.Store, repoKey: config.RepoKey,
changelog: changelog, now: now, maxPages: maxPages}, nil
}
@@ -204,9 +211,22 @@ func (s *Syncer) Sync(ctx context.Context, jobID, triggeredBy string) (governanc
return fail(err)
}
commits, err = s.includeDeliveredCommits(ctx, commits, tags)
if err != nil {
return fail(err)
}
total = len(commits)
deliveryArchive := ""
if len(s.targetSHAs) > 0 {
deliveryArchive, err = s.source.ReadFile(ctx, s.targetSHAs[0], s.changelog)
if err != nil {
return fail(err)
}
}
derived := DeriveVersions(DeriveInput{RepoKey: s.repoKey, CommitURLBase: s.source.CommitURLBase(),
TagURLBase: s.source.TagURLBase(),
Commits: commits, Tags: tags, SnapshotID: runID,
TagURLBase: s.source.TagURLBase(),
DeliveryArchive: deliveryArchive,
Commits: commits, Tags: tags, SnapshotID: runID,
Changelog: func(sha string) (string, error) {
return s.source.ReadFile(ctx, sha, s.changelog)
}})
@@ -220,6 +240,9 @@ func (s *Syncer) Sync(ctx context.Context, jobID, triggeredBy string) (governanc
} else {
sourceHead = headSHA(commits) // 读分支失败不致命:退回提交列表最新一条
}
if len(s.targetSHAs) > 0 {
sourceHead = s.targetSHAs[0]
}
outcome := SyncOutcome{SourceHeadSHA: sourceHead, FetchedCount: len(commits),
ExpectedCount: total, Complete: derived.GraphComplete && (total == 0 || len(commits) == total)}
if err := s.store.FinishVersionHistorySync(ctx, runID, outcome, s.now().UTC()); err != nil {
@@ -232,6 +255,9 @@ func (s *Syncer) Sync(ctx context.Context, jobID, triggeredBy string) (governanc
// fetchAllCommits 逐页抓取并按 SHA 去重;短页即终止(也防住服务端忽略 page 参数)。
func (s *Syncer) fetchAllCommits(ctx context.Context) ([]RawCommit, int, error) {
return s.fetchCommitsAt(ctx, "")
}
func (s *Syncer) fetchCommitsAt(ctx context.Context, ref string) ([]RawCommit, int, error) {
pageSize := s.source.PageSize()
if pageSize <= 0 {
pageSize = giteaDefaultPageSize
@@ -240,7 +266,18 @@ func (s *Syncer) fetchAllCommits(ctx context.Context) ([]RawCommit, int, error)
commits := make([]RawCommit, 0, pageSize)
total := 0
for page := 1; page <= s.maxPages; page++ {
pageCommits, pageTotal, err := s.source.ListCommits(ctx, page, pageSize)
var pageCommits []RawCommit
var pageTotal int
var err error
if ref == "" {
pageCommits, pageTotal, err = s.source.ListCommits(ctx, page, pageSize)
} else if source, ok := s.source.(interface {
ListCommitsAtRef(context.Context, string, int, int) ([]RawCommit, int, error)
}); ok {
pageCommits, pageTotal, err = source.ListCommitsAtRef(ctx, ref, page, pageSize)
} else {
return nil, 0, errors.New("版本来源不支持开发快照历史")
}
if err != nil {
return nil, 0, err
}