Skip to content

Commit

Permalink
Upgrade the module version used in live test (#21464)
Browse files Browse the repository at this point in the history
* Upgrade the module version used in live test when the sdk has major version bump

* fix
  • Loading branch information
Alancere authored Sep 14, 2023
1 parent eb06afe commit 5f029fd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
24 changes: 24 additions & 0 deletions eng/tools/generator/cmd/v2/common/fileProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,27 @@ func replaceModuleImport(path, rpName, namespaceName, previousVersion, currentVe
return nil
})
}

func existSuffixFile(path, suffix string) bool {

existed := false
err := filepath.WalkDir(path, func(p string, d fs.DirEntry, err error) error {
if err != nil {
return err
}

if d.IsDir() {
return nil
}

if strings.HasSuffix(d.Name(), suffix) {
existed = true
}
return nil
})
if err != nil {
return false
}

return existed
}
9 changes: 9 additions & 0 deletions eng/tools/generator/cmd/v2/common/generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ func (ctx *GenerateContext) GenerateForSingleRPNamespace(generateParam *Generate
}
}

// When sdk has major version bump, the live test needs to update the module referenced in the code.
if changelog.HasBreakingChanges() && existSuffixFile(packagePath, "_live_test.go") {
log.Printf("Replace live test module v2+...")
if err = replaceModuleImport(packagePath, generateParam.RPName, generateParam.NamespaceName, previousVersion, version.String(),
"", "_live_test.go"); err != nil {
return nil, err
}
}

// Example generation should be the last step because the package import relay on the new calculated version
if !generateParam.SkipGenerateExample {
log.Printf("Generate examples...")
Expand Down

0 comments on commit 5f029fd

Please sign in to comment.