Move versioning up to src package layer

This commit is contained in:
ferreo 2024-08-04 11:51:54 +01:00
parent bfd6f2e2a9
commit d7f6126eb7
3 changed files with 49 additions and 38 deletions

View File

@ -13,7 +13,6 @@ import (
"time" "time"
"golang.org/x/net/html" "golang.org/x/net/html"
"pault.ag/go/debian/version"
) )
func StartPackageQueueWorker(ctx context.Context) { func StartPackageQueueWorker(ctx context.Context) {
@ -29,37 +28,11 @@ func StartPackageQueueWorker(ctx context.Context) {
} }
packs := packages.GetPackages() packs := packages.GetPackages()
packs.ForEach(func(k string, v domain.SourcePackage) bool { packs.ForEach(func(k string, v domain.SourcePackage) bool {
needsBuild := false needsBuild := v.Status == domain.Missing || v.Status == domain.Stale || v.Status == domain.Error
buildVersion := "" buildVersion := v.NewVersion
v.Packages.ForEach(func(k string, v domain.PackageInfo) bool { if buildVersion == "" {
if v.Status == domain.Current { buildVersion = v.Version
return true }
}
vs := v.NewVersion
if vs == "" {
vs = v.Version
}
if v.Status == domain.Missing || v.Status == domain.Stale {
needsBuild = true
}
if buildVersion == "" {
buildVersion = vs
} else {
ver, err := version.Parse(buildVersion)
if err != nil {
return true
}
vsVer, err := version.Parse(vs)
if err != nil {
return true
}
if version.Compare(ver, vsVer) < 0 {
buildVersion = vs
}
}
return true
})
if needsBuild { if needsBuild {
state, err := helpers.DBInst.GetBuildState(v.Name) state, err := helpers.DBInst.GetBuildState(v.Name)
if err != nil { if err != nil {
@ -117,9 +90,16 @@ func processQueueAndStatus(ctx context.Context) {
if err != nil { if err != nil {
updateBuildState(item, domain.Error) updateBuildState(item, domain.Error)
item.Source.Status = domain.Error
item.Source.LastBuildStatus = domain.Error
item.Source.BuildAttempts++
updatePackageStatus(&item, domain.Error) updatePackageStatus(&item, domain.Error)
} else { } else {
updateBuildState(item, domain.Built) updateBuildState(item, domain.Built)
item.Source.Status = domain.Built
item.Source.LastBuildStatus = domain.Built
item.Source.BuildAttempts = 0
item.Source.Version = item.BuildVersion
updatePackageStatus(&item, domain.Current) updatePackageStatus(&item, domain.Current)
} }
packages.UpdateSourcePackage(item.Source) packages.UpdateSourcePackage(item.Source)

View File

@ -16,9 +16,14 @@ type PackagesCount struct {
} }
type SourcePackage struct { type SourcePackage struct {
Name string `gorm:"primarykey"` Name string `gorm:"primarykey"`
Has32bit bool Has32bit bool
Packages *haxmap.Map[string, PackageInfo] `gorm:"foreignKey:PackageInfo;references:PackageName"` Version string
NewVersion string
Status PackageStatus
LastBuildStatus PackageStatus
BuildAttempts int
Packages *haxmap.Map[string, PackageInfo] `gorm:"foreignKey:PackageInfo;references:PackageName"`
} }
type SourcePackageDTO struct { type SourcePackageDTO struct {

View File

@ -232,6 +232,8 @@ func LoadInternalPackages(internalPackages *haxmap.Map[string, domain.SourcePack
internalPackages.Set(newPkg.Source, domain.SourcePackage{ internalPackages.Set(newPkg.Source, domain.SourcePackage{
Name: newPkg.Source, Name: newPkg.Source,
Packages: newMap, Packages: newMap,
Status: domain.Current,
Version: newPkg.Version,
}) })
return true return true
} }
@ -244,7 +246,9 @@ func LoadInternalPackages(internalPackages *haxmap.Map[string, domain.SourcePack
extVer, _ := version.Parse(newPkg.Version) extVer, _ := version.Parse(newPkg.Version)
cmpVal := version.Compare(extVer, mVer) cmpVal := version.Compare(extVer, mVer)
if cmpVal >= 0 { if cmpVal >= 0 {
pk.Version = getHighestVer(pkg.Version, newPkg.Version)
pk.Packages.Set(newKey, newPkg) pk.Packages.Set(newKey, newPkg)
internalPackages.Set(newPkg.Source, pk)
return true return true
} }
return true return true
@ -309,24 +313,41 @@ func ProcessMissingPackages(internalPackages *haxmap.Map[string, domain.SourcePa
_, ok := internalPackages.Get(k) _, ok := internalPackages.Get(k)
if !ok && src.Packages.Len() > 0 { if !ok && src.Packages.Len() > 0 {
newStatus := domain.Missing newStatus := domain.Missing
vers := ""
src.Packages.ForEach(func(k string, v domain.PackageInfo) bool { src.Packages.ForEach(func(k string, v domain.PackageInfo) bool {
v.Status = newStatus v.Status = newStatus
v.Version = strings.Split(v.Version, "+b")[0] v.Version = strings.Split(v.Version, "+b")[0]
vers = getHighestVer(vers, v.Version)
src.Packages.Set(k, v) src.Packages.Set(k, v)
return true return true
}) })
src.Version = vers
src.Status = newStatus
internalPackages.Set(k, src) internalPackages.Set(k, src)
} }
return true return true
}) })
} }
func getHighestVer(ver string, newVer string) string {
mVer, _ := version.Parse(ver)
extVer, _ := version.Parse(newVer)
cmpVal := version.Compare(mVer, extVer)
if cmpVal < 0 {
return newVer
}
return ver
}
func ProcessStalePackages(internalPackages *haxmap.Map[string, domain.SourcePackage], externalPackages *haxmap.Map[string, domain.SourcePackage]) { func ProcessStalePackages(internalPackages *haxmap.Map[string, domain.SourcePackage], externalPackages *haxmap.Map[string, domain.SourcePackage]) {
externalPackages.ForEach(func(newPackage string, newSource domain.SourcePackage) bool { externalPackages.ForEach(func(newPackage string, newSource domain.SourcePackage) bool {
matchedPackage, ok := internalPackages.Get(newPackage) matchedPackage, ok := internalPackages.Get(newPackage)
if !ok || matchedPackage.Packages.Len() == 0 { if !ok || matchedPackage.Packages.Len() == 0 {
return true return true
} }
ver := ""
status := matchedPackage.Status
matchedPackage.Packages.ForEach(func(currentKey string, currentPackage domain.PackageInfo) bool { matchedPackage.Packages.ForEach(func(currentKey string, currentPackage domain.PackageInfo) bool {
if currentPackage.Status == domain.Missing { if currentPackage.Status == domain.Missing {
return true return true
@ -340,9 +361,9 @@ func ProcessStalePackages(internalPackages *haxmap.Map[string, domain.SourcePack
extVer, _ := version.Parse(newVersion) extVer, _ := version.Parse(newVersion)
cmpVal := version.Compare(mVer, extVer) cmpVal := version.Compare(mVer, extVer)
if cmpVal < 0 { if cmpVal < 0 {
if currentPackage.Status != domain.Error { currentPackage.Status = domain.Stale
currentPackage.Status = domain.Stale status = domain.Stale
} ver = getHighestVer(currentPackage.Version, extVer.String())
currentPackage.NewVersion = extVer.String() currentPackage.NewVersion = extVer.String()
matchedPackage.Packages.Set(currentKey, currentPackage) matchedPackage.Packages.Set(currentKey, currentPackage)
} }
@ -350,6 +371,11 @@ func ProcessStalePackages(internalPackages *haxmap.Map[string, domain.SourcePack
}) })
return true return true
}) })
if ver != matchedPackage.Version {
matchedPackage.NewVersion = ver
}
matchedPackage.Status = status
internalPackages.Set(newPackage, matchedPackage)
return true return true
}) })
} }