@@ -45,7 +45,7 @@ type Config struct {
45
45
ExcludeModules []string
46
46
47
47
// IgnoreModules controls whether gotagger will ignore the existence of
48
- // go.mod files when determinging how to version a project.
48
+ // go.mod files when determining how to version a project.
49
49
IgnoreModules bool
50
50
51
51
// RemoteName represents the name of the remote repository. Defaults to origin.
@@ -118,7 +118,7 @@ func (g *Gotagger) ModuleVersions(names ...string) ([]string, error) {
118
118
return g .versions (modules , nil )
119
119
}
120
120
121
- // TagRepo determines the curent version of the repository by parsing the commit
121
+ // TagRepo determines the current version of the repository by parsing the commit
122
122
// history since the previous release and returns that version. Depending
123
123
// on the CreateTag and PushTag configuration options tags may be created and
124
124
// pushed.
@@ -351,12 +351,25 @@ func (g *Gotagger) latest(tags []string) (latest *semver.Version, hash string, e
351
351
return
352
352
}
353
353
354
- func (g * Gotagger ) latestModule (m module , tags []string ) (* semver.Version , string , error ) {
355
- var hash string
356
- latest := & semver.Version {}
354
+ // latestModule returns the latest version of m and the hash of the commit
355
+ // tagged with that version.
356
+ func (g * Gotagger ) latestModule (m module , tags []string ) (latest * semver.Version , hash string , err error ) {
357
+ majorVersion := strings .TrimPrefix (versionRegex .FindString (m .name ), goModSep )
358
+ if majorVersion == "" {
359
+ majorVersion = "v1"
360
+ }
361
+ moduleVersion , err := semver .NewVersion (majorVersion + ".0.0" )
362
+ if err != nil {
363
+ return nil , "" , err
364
+ }
365
+
366
+ maximumVersion := moduleVersion .IncMajor ()
367
+ latest = new (semver.Version )
357
368
for _ , tag := range tags {
369
+ // strip the module prefix from the tag so we can parse it as a semver
358
370
tagName := strings .TrimPrefix (tag , m .prefix )
359
- if tver , err := semver .NewVersion (tagName ); err == nil && latest .LessThan (tver ) {
371
+ // we want the highest version that is less than the next major version
372
+ if tver , err := semver .NewVersion (tagName ); err == nil && tver .LessThan (& maximumVersion ) && tver .GreaterThan (latest ) {
360
373
hash , err = g .repo .RevParse (tag + "^{commit}" )
361
374
if err != nil {
362
375
return nil , "" , err
@@ -435,16 +448,13 @@ func (g *Gotagger) versionsModules(modules []module, commitModules []module) ([]
435
448
// version prefix, and the major version of this module.
436
449
// the major version is the version part of the module name
437
450
// (foo/v2, foo/v3) normalized to 'X.'
438
- var prefixes []string
439
- if major := strings .TrimPrefix (versionRegex .FindString (mod .name ), goModSep ); major == "" {
440
- // no major version in module name, so v0.x and v1.x are allowed
441
- prefixes = []string {mod .prefix + "v0.*" , mod .prefix + "v1.*" }
442
- } else {
443
- prefixes = []string {mod .prefix + major + ".*" }
451
+ prefix := g .Config .VersionPrefix
452
+ if mod .prefix != "" {
453
+ prefix = mod .prefix + prefix
444
454
}
445
455
446
456
// get tags that match the prefixes
447
- tags , err := g .repo .Tags (head , prefixes ... )
457
+ tags , err := g .repo .Tags (head , prefix )
448
458
if err != nil {
449
459
return nil , err
450
460
}
@@ -669,7 +679,7 @@ func validateCommitModules(commitModules, changedModules []module) (err error) {
669
679
return
670
680
}
671
681
672
- // TagRepo determines what the curent version of the repository is by parsing the commit
682
+ // TagRepo determines what the current version of the repository is by parsing the commit
673
683
// history since previous release and returns that version. Depending on the state of
674
684
// the Config passed it, it may also create the tag and push it.
675
685
//
0 commit comments