From dcca022c8c6e4a5b13f781f82e6ce80d1bb6f99e Mon Sep 17 00:00:00 2001
From: pathC <wegood9@users.noreply.github.com>
Date: Fri, 4 Aug 2023 17:54:28 +0800
Subject: [PATCH] Chore: support the new versioning scheme of Protobuf

Protobuf has changed their versioning scheme to language-specific one. For Golang, the first version applied the scheme would be 4.21.0 which followed the preceding version,3.20.1. Basically the major part is language-specific and no longer important.
Check more:
https://protobuf.dev/news/2022-05-06/
https://github.com/protocolbuffers/protobuf/issues/11440
https://github.com/protocolbuffers/protobuf/issues/11123
---
 infra/vprotogen/main.go | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/infra/vprotogen/main.go b/infra/vprotogen/main.go
index 2551808ca69..e313257e6d0 100644
--- a/infra/vprotogen/main.go
+++ b/infra/vprotogen/main.go
@@ -120,7 +120,7 @@ func getInstalledProtocVersion(protocPath string) (string, error) {
 	if cmdErr != nil {
 		return "", cmdErr
 	}
-	versionRegexp := regexp.MustCompile(`protoc\s*(\d+\.\d+\.\d+)`)
+	versionRegexp := regexp.MustCompile(`protoc\s*(\d+\.\d+(\.\d)*)`)
 	matched := versionRegexp.FindStringSubmatch(string(output))
 	return matched[1], nil
 }
@@ -129,6 +129,9 @@ func parseVersion(s string, width int) int64 {
 	strList := strings.Split(s, ".")
 	format := fmt.Sprintf("%%s%%0%ds", width)
 	v := ""
+	if len(strList) == 2 {
+		strList = append([]string{"4"}, strList...)
+	}
 	for _, value := range strList {
 		v = fmt.Sprintf(format, v, value)
 	}