internal/rosa: overridable version check
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 1m45s
Test / Hakurei (push) Successful in 2m52s
Test / ShareFS (push) Successful in 2m50s
Test / Sandbox (race detector) (push) Successful in 5m9s
Test / Hakurei (race detector) (push) Successful in 6m13s
Test / Flake checks (push) Successful in 1m35s

For projects with strange versioning practices.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-03-06 18:57:55 +09:00
parent 16d0cf04c1
commit 95ffe0429c
2 changed files with 23 additions and 2 deletions

View File

@@ -173,9 +173,11 @@ func main() {
if v, err := meta.GetVersions(ctx); err != nil {
return err
} else if current := rosa.Std.Version(p); v.Latest != current {
} else if current, latest :=
rosa.Std.Version(p),
meta.GetLatest(v); current != latest {
n++
log.Printf("%s %s < %s", meta.Name, current, v.Latest)
log.Printf("%s %s < %s", meta.Name, current, latest)
} else {
msg.Verbosef("%s is up to date", meta.Name)
}

View File

@@ -166,6 +166,17 @@ type Metadata struct {
//
// [Anitya]: https://release-monitoring.org/
ID int `json:"-"`
// Optional custom version checking behaviour.
latest func(v *Versions) string
}
// GetLatest returns the latest version described by v.
func (meta *Metadata) GetLatest(v *Versions) string {
if meta.latest != nil {
return meta.latest(v)
}
return v.Latest
}
// Unversioned denotes an unversioned [PArtifact].
@@ -188,6 +199,14 @@ type Versions struct {
All []string `json:"versions"`
}
// getStable returns the first Stable version, or Latest if that is unavailable.
func (v *Versions) getStable() string {
if len(v.Stable) == 0 {
return v.Latest
}
return v.Stable[0]
}
// GetVersions returns versions fetched from Anitya.
func (meta *Metadata) GetVersions(ctx context.Context) (*Versions, error) {
if meta.ID == 0 {