mirror of
https://github.com/vale981/agru
synced 2025-03-06 02:01:41 -05:00
speedup, add name field
This commit is contained in:
parent
c00433661f
commit
e87b3ee1ae
1 changed files with 22 additions and 10 deletions
32
main.go
32
main.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
@ -14,6 +15,7 @@ type RequirementsFile []RequirementsEntry
|
||||||
type RequirementsEntry struct {
|
type RequirementsEntry struct {
|
||||||
Src string `yaml:"src"`
|
Src string `yaml:"src"`
|
||||||
Version string `yaml:"version"`
|
Version string `yaml:"version"`
|
||||||
|
Name string `yaml:"name,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var requirementsPath string
|
var requirementsPath string
|
||||||
|
@ -32,13 +34,22 @@ func main() {
|
||||||
|
|
||||||
func updateRequirements(path string) {
|
func updateRequirements(path string) {
|
||||||
entries := parseRequirements(path)
|
entries := parseRequirements(path)
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(len(entries))
|
||||||
for i, entry := range entries {
|
for i, entry := range entries {
|
||||||
newVersion := updateRequirementEntry(entry)
|
go func(i int, entry RequirementsEntry, wg *sync.WaitGroup) {
|
||||||
if newVersion != "" {
|
newVersion := getNewVersion(entry.Src, entry.Version)
|
||||||
log.Println(entry.Src, entry.Version, "->", newVersion)
|
if newVersion != "" {
|
||||||
entries[i].Version = newVersion
|
log.Println(entry.Src, entry.Version, "->", newVersion)
|
||||||
}
|
entry.Version = newVersion
|
||||||
|
entries[i] = entry
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}(i, entry, &wg)
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
outb, err := yaml.Marshal(entries)
|
outb, err := yaml.Marshal(entries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("ERROR: ", err)
|
log.Println("ERROR: ", err)
|
||||||
|
@ -63,17 +74,17 @@ func parseRequirements(path string) RequirementsFile {
|
||||||
return req
|
return req
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateRequirementEntry(entry RequirementsEntry) string {
|
func getNewVersion(src, version string) string {
|
||||||
if ignoredVersions[entry.Version] {
|
if ignoredVersions[version] {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// not a git repo
|
// not a git repo
|
||||||
if !strings.Contains(entry.Src, "https") && !strings.Contains(entry.Src, "git") {
|
if !strings.Contains(src, "git") {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := strings.Replace(entry.Src, "git+https", "https", 1)
|
repo := strings.Replace(src, "git+https", "https", 1)
|
||||||
tags, err := execute("git ls-remote -tq --sort=-version:refname " + repo)
|
tags, err := execute("git ls-remote -tq --sort=-version:refname " + repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("ERROR: ", err)
|
log.Println("ERROR: ", err)
|
||||||
|
@ -90,7 +101,8 @@ func updateRequirementEntry(entry RequirementsEntry) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
last := strings.Replace(lastline[tagidx:], "refs/tags/", "", 1)
|
last := strings.Replace(lastline[tagidx:], "refs/tags/", "", 1)
|
||||||
if last != entry.Version {
|
last = strings.Replace(last, "^{}", "", 1) // NOTE: very weird case with some github repos, didn't find out why it does that
|
||||||
|
if last != version {
|
||||||
return last
|
return last
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue