2020-09-10 17:27:46 +00:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"go.jolheiser.com/vanity/flags"
|
|
|
|
"go.jolheiser.com/vanity/service"
|
|
|
|
|
|
|
|
"go.jolheiser.com/beaver"
|
|
|
|
)
|
|
|
|
|
|
|
|
var svc service.Service
|
|
|
|
|
|
|
|
func cronStart() {
|
2020-09-12 01:38:18 +00:00
|
|
|
ticker := time.NewTicker(flags.Interval)
|
2020-09-10 17:27:46 +00:00
|
|
|
for {
|
|
|
|
<-ticker.C
|
|
|
|
beaver.Debug("Running package update...")
|
|
|
|
cronUpdate()
|
|
|
|
beaver.Debugf("Finished package update: %s", cache.Names())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func cronUpdate() {
|
|
|
|
packages, err := svc.Packages()
|
|
|
|
if err != nil {
|
|
|
|
beaver.Errorf("could not update packages: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter
|
|
|
|
for name, pkg := range packages {
|
|
|
|
if err := service.Check(pkg); err != nil {
|
|
|
|
beaver.Debug(err)
|
|
|
|
delete(packages, name)
|
|
|
|
continue
|
|
|
|
}
|
2020-09-12 01:38:18 +00:00
|
|
|
goMod, err := svc.GoMod(pkg)
|
|
|
|
if err != nil {
|
|
|
|
beaver.Debugf("No go.mod could be found in the root directory of %s", pkg.Name)
|
|
|
|
delete(packages, name)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
lines := strings.Split(goMod, "\n")
|
|
|
|
line := strings.Fields(lines[0])
|
|
|
|
if !strings.HasPrefix(line[1], flags.Domain) {
|
|
|
|
beaver.Debugf("%s is a Go project, however its module does not include this domain", pkg.Name)
|
2020-09-10 17:27:46 +00:00
|
|
|
delete(packages, name)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
beaver.Debugf("Including %s", pkg.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overrides
|
|
|
|
for name, pkg := range packages {
|
2020-09-12 01:38:18 +00:00
|
|
|
for key, override := range flags.Override {
|
2020-09-10 17:27:46 +00:00
|
|
|
if strings.EqualFold(name, key) {
|
2020-09-12 01:38:18 +00:00
|
|
|
beaver.Debugf("Overriding %s -> %s", name, override)
|
2020-09-10 17:27:46 +00:00
|
|
|
delete(packages, key)
|
2020-09-12 01:38:18 +00:00
|
|
|
pkg.Name = override
|
|
|
|
packages[override] = pkg
|
2020-09-10 17:27:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-12 01:38:18 +00:00
|
|
|
// Add packages manually added to config
|
|
|
|
for _, pkg := range flags.ConfigPackages {
|
|
|
|
packages[pkg.Name] = pkg
|
|
|
|
}
|
|
|
|
|
2020-09-10 17:27:46 +00:00
|
|
|
cache.Update(packages)
|
|
|
|
}
|