Skip to content

Commit 9bf9c68

Browse files
quinna-hbouwkast
authored andcommitted
tidy
1 parent 1cb6db2 commit 9bf9c68

File tree

1 file changed

+18
-33
lines changed

1 file changed

+18
-33
lines changed

.github/workflows/apps/new_latest_major_versions.go

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,7 @@ type ModuleInfo struct {
3434

3535
type GithubLatests struct {
3636
Version string
37-
Module string
38-
}
39-
40-
type PackageResult struct {
41-
Base string
42-
LatestVersion string
43-
ModulePath string
44-
Error error
37+
Module string // the base name of the module
4538
}
4639

4740
func getGoModVersion(repository string, pkg string) (string, string, error) {
@@ -97,15 +90,17 @@ func getGoModVersion(repository string, pkg string) (string, string, error) {
9790

9891
func fetchGoMod(origin, tag string) (*modfile.File, error) {
9992
// https://raw.githubusercontent.com/gin-gonic/gin/refs/tags/v1.7.7/go.mod
100-
if !strings.HasPrefix(origin, "https://github.com") {
101-
return nil, fmt.Errorf("provider not supported: %s", origin)
102-
}
10393

94+
// Process the URL
10495
repoPath := strings.TrimPrefix(origin, "https://github.com/")
96+
repoPath = strings.TrimPrefix(repoPath, "https://gopkg.in/")
10597
repoPath = strings.TrimSuffix(repoPath, ".git")
98+
// Remove .vX version suffix if present (e.g., ".v1", ".v2")
99+
repoPath = regexp.MustCompile(`\.v\d+$`).ReplaceAllString(repoPath, "")
100+
106101
url := fmt.Sprintf("https://raw.githubusercontent.com/%s/refs/tags/%s/go.mod", repoPath, tag)
107102

108-
log.Printf("fetching %s\n", url)
103+
// log.Printf("fetching %s\n", url)
109104

110105
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
111106
defer cancel()
@@ -119,6 +114,8 @@ func fetchGoMod(origin, tag string) (*modfile.File, error) {
119114
if err != nil {
120115
return nil, err
121116
}
117+
defer resp.Body.Close()
118+
122119
if resp.StatusCode != http.StatusOK {
123120
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
124121
}
@@ -226,16 +223,11 @@ func truncateMajorVersion(version string) string {
226223
}
227224

228225
func main() {
229-
// log.SetFlags(0) // disable date and time logging
230-
log.Println("starting")
231226

232227
// Find latest major
233228
github_latests := map[string]GithubLatests{} // map module (base name) => latest on github
234229
contrib_latests := map[string]string{} // map module (base name) => latest on go.mod
235230

236-
// var wg sync.WaitGroup
237-
results := make(chan PackageResult, 10) // Buffered channel to avoid blocking
238-
239231
for pkg, packageInfo := range instrumentation.GetPackages() {
240232

241233
// Step 1: get the version from the module go.mod
@@ -300,7 +292,7 @@ func main() {
300292
// 5b. If request returns a `go.mod`, parse the modfile and extract the mod name
301293

302294
// Get the latest version for each major
303-
for _, versions := range majors {
295+
for major, versions := range majors {
304296
latest := getLatestVersion(versions)
305297

306298
log.Printf("fetching go.mod for %s@%s\n", origin, latest)
@@ -310,24 +302,17 @@ func main() {
310302
continue
311303
}
312304
log.Printf("go.mod for %s@%s: %s\n", origin, latest, f.Module.Mod.Path)
313-
}
314-
}
315-
316-
// Iterate through results
317-
for result := range results {
318-
if result.Error != nil {
319-
fmt.Println("Error:", result.Error)
320-
continue
321-
}
322-
323-
if latestGithub, ok := github_latests[result.Base]; ok {
324-
if semver.Compare(result.LatestVersion, latestGithub.Version) > 0 {
325-
github_latests[result.Base] = GithubLatests{result.LatestVersion, result.ModulePath}
305+
if latestGithub, ok := github_latests[base]; ok {
306+
if semver.Compare(major, latestGithub.Version) > 0 {
307+
// if latest > latestGithubMajor
308+
github_latests[base] = GithubLatests{major, base}
309+
}
310+
} else {
311+
github_latests[base] = GithubLatests{major, base}
326312
}
327-
} else {
328-
github_latests[result.Base] = GithubLatests{result.LatestVersion, result.ModulePath}
329313
}
330314
}
315+
331316
// check if there are any outdated majors
332317
// output if there is a new major package we do not support
333318
for base, contribMajor := range contrib_latests {

0 commit comments

Comments
 (0)