Skip to content

Commit de25be2

Browse files
tadeleshtadelesh
andauthored
Fix wrong versioning logic (#25733)
Co-authored-by: tadelesh <[email protected]>
1 parent 27faa48 commit de25be2

File tree

6 files changed

+101
-139
lines changed

6 files changed

+101
-139
lines changed

eng/tools/generator/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Release History
22

3+
## 0.4.2 (2025-12-08)
4+
5+
### Bugs Fixed
6+
7+
- Move logic of determining preview version after code generation to avoid incorrect version calculation.
8+
- Fix wrong override logic for stable/beta version determination.
9+
310
## 0.4.1 (2025-12-02)
411

512
### Bugs Fixed

eng/tools/generator/cmd/v2/common/cmdProcessor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func ExecuteGoGenerate(path string) error {
6262
}
6363
}
6464

65-
if cmdWaitErr != nil || stderrBuffer.Len() > 0 {
65+
if stderrBuffer.Len() > 0 {
6666
if stderrBuffer.Len() > 0 {
6767
// filter go downloading log
6868
// https://github.com/golang/go/blob/1f0c044d60211e435dc58844127544dd3ecb6a41/src/cmd/go/internal/modfetch/fetch.go#L201
@@ -123,7 +123,7 @@ func ExecuteGoimports(path string) error {
123123
}
124124

125125
func ExecuteGitPush(path, remoteName, branchName string) (string, error) {
126-
refName := fmt.Sprintf("%s", branchName+":"+branchName)
126+
refName := branchName + ":" + branchName
127127
cmd := exec.Command("git", "push", remoteName, refName)
128128
cmd.Dir = path
129129
msg, err := cmd.CombinedOutput()

eng/tools/generator/cmd/v2/common/fileProcessor.go

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,12 @@ const (
2727
)
2828

2929
var (
30-
v2BeginRegex = regexp.MustCompile("^```\\s*yaml\\s*\\$\\(go\\)\\s*&&\\s*\\$\\((track2|v2)\\)")
31-
v2EndRegex = regexp.MustCompile("^\\s*```\\s*$")
32-
newClientMethodNameRegex = regexp.MustCompile("^New.*Client$")
33-
versionLineRegex = regexp.MustCompile(`moduleVersion\s*=\s*\".*v.+"`)
34-
changelogPosWithPreviewRegex = regexp.MustCompile(`##\s*(?P<version>.+)\s*\((\d{4}-\d{2}-\d{2}|Unreleased)\)`)
35-
changelogPosWithoutPreviewRegex = regexp.MustCompile(`##\s*(?P<version>\d+\.\d+\.\d+)\s*\((\d{4}-\d{2}-\d{2}|Unreleased)\)`)
36-
packageConfigRegex = regexp.MustCompile(`\$\((package-.+)\)`)
30+
v2BeginRegex = regexp.MustCompile("^```\\s*yaml\\s*\\$\\(go\\)\\s*&&\\s*\\$\\((track2|v2)\\)")
31+
v2EndRegex = regexp.MustCompile("^\\s*```\\s*$")
32+
newClientMethodNameRegex = regexp.MustCompile("^New.*Client$")
33+
packageConfigRegex = regexp.MustCompile(`\$\((package-.+)\)`)
3734
)
3835

39-
// paramsToString converts a parameter list to a comma-delimited string with names and types
40-
func paramsToString(params []exports.Param) string {
41-
if len(params) == 0 {
42-
return ""
43-
}
44-
45-
var parts []string
46-
for _, p := range params {
47-
if p.Name != "" {
48-
parts = append(parts, p.Name+" "+p.Type)
49-
} else {
50-
parts = append(parts, p.Type)
51-
}
52-
}
53-
return strings.Join(parts, ", ")
54-
}
55-
5636
// hasExpectedClientParams checks if params match the expected ARM client constructor signature
5737
func hasExpectedClientParams(params []exports.Param) bool {
5838
expectedTypes := []string{"string", "azcore.TokenCredential", "*arm.ClientOptions"}
@@ -260,7 +240,7 @@ func GetSpecRpName(packageRootPath string) (string, error) {
260240
}
261241
}
262242
}
263-
return "", fmt.Errorf("cannot get sepc rp name from config")
243+
return "", fmt.Errorf("cannot get spec rp name from config")
264244
}
265245

266246
// ReplaceNewClientNamePlaceholder replaces `{{NewClientName}}` placeholder in README.md by first func name according to `^New.+Method$` pattern
@@ -431,9 +411,9 @@ func UpdateReadmeClientFactory(path string) error {
431411
}
432412
noOptionalFactoryReg := regexp.MustCompile(`NewClientFactory\((.*?)(?:,\s*)?cred,\s*nil\)`)
433413
withOptionalFactoryReg := regexp.MustCompile(`NewClientFactory\((.*?)(?:,\s*)?cred,\s*&options\)`)
434-
oldnoOptionalFactory := noOptionalFactoryReg.FindString(string(readmeFile))
435-
oldwithOptionalFactory := withOptionalFactoryReg.FindString(string(readmeFile))
436-
if oldnoOptionalFactory == "" && oldwithOptionalFactory == "" {
414+
oldNoOptionalFactory := noOptionalFactoryReg.FindString(string(readmeFile))
415+
oldWithOptionalFactory := withOptionalFactoryReg.FindString(string(readmeFile))
416+
if oldNoOptionalFactory == "" && oldWithOptionalFactory == "" {
437417
return nil
438418
}
439419
clientFactoryFile, err := os.ReadFile(filepath.Join(path, utils.ClientFactoryFileName))
@@ -469,10 +449,10 @@ func UpdateReadmeClientFactory(path string) error {
469449
withOptionsParams := append(factoryParams, []string{"cred", "&options"}...)
470450
newNoOptionalFactory := fmt.Sprintf("NewClientFactory(%s)", strings.Join(noOptionsParams, ", "))
471451
newWithOptionalFactory := fmt.Sprintf("NewClientFactory(%s)", strings.Join(withOptionsParams, ", "))
472-
if oldnoOptionalFactory == newNoOptionalFactory && oldwithOptionalFactory == newWithOptionalFactory {
452+
if oldNoOptionalFactory == newNoOptionalFactory && oldWithOptionalFactory == newWithOptionalFactory {
473453
return nil
474454
}
475-
content := strings.ReplaceAll(string(readmeFile), oldnoOptionalFactory, newNoOptionalFactory)
476-
content = strings.ReplaceAll(content, oldwithOptionalFactory, newWithOptionalFactory)
455+
content := strings.ReplaceAll(string(readmeFile), oldNoOptionalFactory, newNoOptionalFactory)
456+
content = strings.ReplaceAll(content, oldWithOptionalFactory, newWithOptionalFactory)
477457
return os.WriteFile(readmePath, []byte(content), 0644)
478458
}

0 commit comments

Comments
 (0)