version: find from build info if unset
Some checks failed
Go / Lint (latest) (push) Has been cancelled
Go / Build (old, libolm) (push) Has been cancelled
Go / Build (latest, libolm) (push) Has been cancelled
Go / Build (old, goolm) (push) Has been cancelled
Go / Build (latest, goolm) (push) Has been cancelled

This commit is contained in:
Tulir Asokan 2025-09-28 20:33:20 +03:00
commit f2b77f0433
3 changed files with 15 additions and 3 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"regexp"
"runtime"
"runtime/debug"
"strings"
)
@ -18,6 +19,17 @@ var DefaultUserAgent = "mautrix-go/" + Version + " go/" + strings.TrimPrefix(run
var goModVersionRegex = regexp.MustCompile(`v.+\d{14}-([0-9a-f]{12})`)
func init() {
if GoModVersion == "" {
info, _ := debug.ReadBuildInfo()
if info != nil {
for _, mod := range info.Deps {
if mod.Path == "maunium.net/go/mautrix" {
GoModVersion = mod.Version
break
}
}
}
}
if GoModVersion != "" {
match := goModVersionRegex.FindStringSubmatch(GoModVersion)
if match != nil {