Files
knowledge-governance/cmd/api/version_record_status.go
姚章浩 013ce4a24e
build / build (push) Successful in 1m3s
fix(version): 补全开发快照记录与同步交付闭环
收录 main、注释开发快照和完整运行 SHA;开发说明绑定原提交,补记 0.1.1–0.1.25。
进行中同步按仓库合并,完成后重新执行;启动入队,部署脚本读回版本证据。
开发快照独立于正式标签与 Release,既有冲突标签不移动。

已运行:整仓 make verify,Go 673 通过、前端 274 通过,92 个已声明可选跳过,必需跳过 0。
隔离 PostgreSQL 重复同步队列用例及 -race 通过;未更新现有 8088、未修改生产问答。
2026-10-18 18:11:49 +08:00

57 lines
2.1 KiB
Go

package main
import (
"context"
"encoding/json"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
"knowledge-governance/internal/appconfig"
"knowledge-governance/internal/version"
"os"
"time"
)
// Operator-only read-back in the existing API binary; no new public endpoint,
// no session/credential creation and no migrations or remote forge access.
func versionRecordStatus(ctx context.Context, getenv func(string) string) int {
info := version.Snapshot()
if !info.IdentityAvailable || info.CommitSHA == nil {
return printVersionStatus(false, "build_identity_missing", "")
}
config, e := appconfig.Load(getenv)
if e != nil {
return printVersionStatus(false, "configuration_invalid", *info.CommitSHA)
}
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
pool, e := pgxpool.New(ctx, config.DatabaseURL)
if e != nil {
return printVersionStatus(false, "database_unavailable", *info.CommitSHA)
}
defer pool.Close()
tag := "snapshot/v" + info.DisplayVersion
kind := "development"
if info.BuildKind == "release" {
tag = "v" + info.DisplayVersion
kind = "release"
}
evidence, _ := json.Marshal([]map[string]any{{"name": tag, "annotated": true}})
var ready bool
e = pool.QueryRow(ctx, `SELECT EXISTS(SELECT 1 FROM version_history_commits c WHERE repo_key=$1 AND commit_sha=$2 AND version_label=$3 AND record_kind=$4 AND btrim(release_notes)<>'' AND release_tags @> $5::jsonb AND snapshot_id=(SELECT max(id) FROM version_history_sync_runs WHERE repo_key=$1 AND status='completed' AND complete))`, config.VersionHistoryRepo, *info.CommitSHA, info.DisplayVersion, kind, evidence).Scan(&ready)
if e != nil {
return printVersionStatus(false, "database_unavailable", *info.CommitSHA)
}
if !ready {
return printVersionStatus(false, "version_record_pending", *info.CommitSHA)
}
return printVersionStatus(true, "verified", *info.CommitSHA)
}
func printVersionStatus(ready bool, code, sha string) int {
raw, _ := json.Marshal(map[string]any{"ready": ready, "code": code, "commit_sha": sha})
fmt.Fprintln(os.Stdout, string(raw))
if ready {
return 0
}
return 1
}