| 23 | const suffix = "rc" |
| 24 | |
| 25 | func main() { |
| 26 | pre := flag.Bool("pre", false, "Create a prerelease") |
| 27 | flag.Parse() |
| 28 | |
| 29 | // Get the latest "v1.22.3" or "v1.22.3-rc.1" style tag. |
| 30 | latestTag, err := cmd("git", "describe", "--abbrev=0", "--match", "v[0-9].*") |
| 31 | if err != nil { |
| 32 | fmt.Println(err) |
| 33 | os.Exit(1) |
| 34 | } |
| 35 | latest, err := semver.NewVersion(latestTag[1:]) |
| 36 | if err != nil { |
| 37 | fmt.Println(err) |
| 38 | os.Exit(1) |
| 39 | } |
| 40 | |
| 41 | // Get the latest "v1.22.3" style tag, excludeing prereleases. |
| 42 | latestStableTag, err := cmd("git", "describe", "--abbrev=0", "--match", "v[0-9].*", "--exclude", "*-*") |
| 43 | if err != nil { |
| 44 | fmt.Println(err) |
| 45 | os.Exit(1) |
| 46 | } |
| 47 | latestStable, err := semver.NewVersion(latestStableTag[1:]) |
| 48 | if err != nil { |
| 49 | fmt.Println(err) |
| 50 | os.Exit(1) |
| 51 | } |
| 52 | |
| 53 | // Get the commit logs since the latest stable tag. |
| 54 | logsSinceLatest, err := cmd("git", "log", "--pretty=format:%s", latestStableTag+"..HEAD") |
| 55 | if err != nil { |
| 56 | fmt.Println(err) |
| 57 | os.Exit(1) |
| 58 | } |
| 59 | |
| 60 | // Check if the next version should be a feature or a patch release |
| 61 | nextIsFeature := false |
| 62 | for _, line := range strings.Split(logsSinceLatest, "\n") { |
| 63 | if strings.HasPrefix(line, "feat") { |
| 64 | nextIsFeature = true |
| 65 | break |
| 66 | } |
| 67 | } |
| 68 | next := *latestStable |
| 69 | if nextIsFeature { |
| 70 | next.BumpMinor() |
| 71 | } else { |
| 72 | next.BumpPatch() |
| 73 | } |
| 74 | |
| 75 | if latest.PreRelease != "" { |
| 76 | if !*pre { |
| 77 | // We want a stable release. Simply remove the prerelease |
| 78 | // suffix. |
| 79 | latest.PreRelease = "" |
| 80 | fmt.Println("v" + latest.String()) |
| 81 | return |
| 82 | } |