@@ -34,14 +34,7 @@ type ModuleInfo struct {
34
34
35
35
type GithubLatests struct {
36
36
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
45
38
}
46
39
47
40
func getGoModVersion (repository string , pkg string ) (string , string , error ) {
@@ -97,15 +90,17 @@ func getGoModVersion(repository string, pkg string) (string, string, error) {
97
90
98
91
func fetchGoMod (origin , tag string ) (* modfile.File , error ) {
99
92
// 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
- }
103
93
94
+ // Process the URL
104
95
repoPath := strings .TrimPrefix (origin , "https://github.com/" )
96
+ repoPath = strings .TrimPrefix (repoPath , "https://gopkg.in/" )
105
97
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
+
106
101
url := fmt .Sprintf ("https://raw.githubusercontent.com/%s/refs/tags/%s/go.mod" , repoPath , tag )
107
102
108
- log .Printf ("fetching %s\n " , url )
103
+ // log.Printf("fetching %s\n", url)
109
104
110
105
ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
111
106
defer cancel ()
@@ -119,6 +114,8 @@ func fetchGoMod(origin, tag string) (*modfile.File, error) {
119
114
if err != nil {
120
115
return nil , err
121
116
}
117
+ defer resp .Body .Close ()
118
+
122
119
if resp .StatusCode != http .StatusOK {
123
120
return nil , fmt .Errorf ("unexpected status code: %d" , resp .StatusCode )
124
121
}
@@ -226,16 +223,11 @@ func truncateMajorVersion(version string) string {
226
223
}
227
224
228
225
func main () {
229
- // log.SetFlags(0) // disable date and time logging
230
- log .Println ("starting" )
231
226
232
227
// Find latest major
233
228
github_latests := map [string ]GithubLatests {} // map module (base name) => latest on github
234
229
contrib_latests := map [string ]string {} // map module (base name) => latest on go.mod
235
230
236
- // var wg sync.WaitGroup
237
- results := make (chan PackageResult , 10 ) // Buffered channel to avoid blocking
238
-
239
231
for pkg , packageInfo := range instrumentation .GetPackages () {
240
232
241
233
// Step 1: get the version from the module go.mod
@@ -300,7 +292,7 @@ func main() {
300
292
// 5b. If request returns a `go.mod`, parse the modfile and extract the mod name
301
293
302
294
// Get the latest version for each major
303
- for _ , versions := range majors {
295
+ for major , versions := range majors {
304
296
latest := getLatestVersion (versions )
305
297
306
298
log .Printf ("fetching go.mod for %s@%s\n " , origin , latest )
@@ -310,24 +302,17 @@ func main() {
310
302
continue
311
303
}
312
304
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 }
326
312
}
327
- } else {
328
- github_latests [result .Base ] = GithubLatests {result .LatestVersion , result .ModulePath }
329
313
}
330
314
}
315
+
331
316
// check if there are any outdated majors
332
317
// output if there is a new major package we do not support
333
318
for base , contribMajor := range contrib_latests {
0 commit comments