Skip to content

Commit 5f029fd

Browse files
authored
Upgrade the module version used in live test (Azure#21464)
* Upgrade the module version used in live test when the sdk has major version bump * fix
1 parent eb06afe commit 5f029fd

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,27 @@ func replaceModuleImport(path, rpName, namespaceName, previousVersion, currentVe
566566
return nil
567567
})
568568
}
569+
570+
func existSuffixFile(path, suffix string) bool {
571+
572+
existed := false
573+
err := filepath.WalkDir(path, func(p string, d fs.DirEntry, err error) error {
574+
if err != nil {
575+
return err
576+
}
577+
578+
if d.IsDir() {
579+
return nil
580+
}
581+
582+
if strings.HasSuffix(d.Name(), suffix) {
583+
existed = true
584+
}
585+
return nil
586+
})
587+
if err != nil {
588+
return false
589+
}
590+
591+
return existed
592+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,15 @@ func (ctx *GenerateContext) GenerateForSingleRPNamespace(generateParam *Generate
306306
}
307307
}
308308

309+
// When sdk has major version bump, the live test needs to update the module referenced in the code.
310+
if changelog.HasBreakingChanges() && existSuffixFile(packagePath, "_live_test.go") {
311+
log.Printf("Replace live test module v2+...")
312+
if err = replaceModuleImport(packagePath, generateParam.RPName, generateParam.NamespaceName, previousVersion, version.String(),
313+
"", "_live_test.go"); err != nil {
314+
return nil, err
315+
}
316+
}
317+
309318
// Example generation should be the last step because the package import relay on the new calculated version
310319
if !generateParam.SkipGenerateExample {
311320
log.Printf("Generate examples...")

0 commit comments

Comments
 (0)