package adopt import ( "regexp" "strings" ) // describeName is a `git describe --tags` name of an untagged commit, // v..--g, capturing the commit's hex. Git writes // it lowercase; so must the app. var describeName = regexp.MustCompile(`^v(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)-(?:0|[1-9][0-9]*)-g([0-9a-f]{7,64})$`) // commitID is a commit id, full or abbreviated to at least 7 lowercase hex. var commitID = regexp.MustCompile(`^[0-9a-f]{7,64}$`) // SameRelease says the /api/version body and X-Carlos-Version name the // same release (controller ruling, 2026-11-17). They do when they are // equal, or when the body is a describe name, the header a commit id, and // one hex is a prefix of the other: both are at least 7 digits, so at // least 7 are in common. Production serves both forms (Sheets: body // v0.1.0-53-gef9c313, header ef9c313). Anything else is // version-header-mismatch. Only the header is the served release name the // artifact hashes; the body is what Home is sent as app_version. func SameRelease(body, header string) bool { if body == header { return true } m := describeName.FindStringSubmatch(body) if m == nil || !commitID.MatchString(header) { return false } return strings.HasPrefix(m[1], header) || strings.HasPrefix(header, m[1]) }