oficina / alta Public

Clone
git clone https://amadan.net/oficina/alta

Plain git — no account needed to clone.

Download

Download this file

1package adopt
2
3import (
4 "regexp"
5 "strings"
6)
7
8// describeName is a `git describe --tags` name of an untagged commit,
9// v<maj>.<min>.<patch>-<n>-g<hex>, capturing the commit's hex. Git writes
10// it lowercase; so must the app.
11var 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})$`)
12
13// commitID is a commit id, full or abbreviated to at least 7 lowercase hex.
14var commitID = regexp.MustCompile(`^[0-9a-f]{7,64}$`)
15
16// SameRelease says the /api/version body and X-Carlos-Version name the
17// same release (controller ruling, 2026-11-17). They do when they are
18// equal, or when the body is a describe name, the header a commit id, and
19// one hex is a prefix of the other: both are at least 7 digits, so at
20// least 7 are in common. Production serves both forms (Sheets: body
21// v0.1.0-53-gef9c313, header ef9c313). Anything else is
22// version-header-mismatch. Only the header is the served release name the
23// artifact hashes; the body is what Home is sent as app_version.
24func SameRelease(body, header string) bool {
25 if body == header {
26 return true
27 }
28 m := describeName.FindStringSubmatch(body)
29 if m == nil || !commitID.MatchString(header) {
30 return false
31 }
32 return strings.HasPrefix(m[1], header) || strings.HasPrefix(header, m[1])
33}
34