Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automation support data plan #23879

Merged
merged 17 commits into from
Dec 27, 2024
16 changes: 8 additions & 8 deletions eng/tools/generator/cmd/v2/automation/automationCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ func (ctx *automationContext) generate(input *pipeline.GenerateInput) (*pipeline
errorBuilder.add(err)
continue
}

packageRelativePath := tsc.GetRelativePath()
tadelesh marked this conversation as resolved.
Show resolved Hide resolved
namespaceResult, err := generateCtx.GenerateForTypeSpec(&common.GenerateParam{
RPName: module[0],
NamespaceName: module[1],
SkipGenerateExample: true,
GoVersion: ctx.goVersion,
TspClientOptions: []string{"--debug"},
})
}, packageRelativePath)
if err != nil {
errorBuilder.add(err)
continue
Expand All @@ -147,25 +147,25 @@ func (ctx *automationContext) generate(input *pipeline.GenerateInput) (*pipeline
breaking := namespaceResult.Changelog.HasBreakingChanges()
breakingChangeItems := namespaceResult.Changelog.GetBreakingChangeItems()

srcFolder := filepath.Join(sdkRepo.Root(), "sdk", "resourcemanager", namespaceResult.RPName, namespaceResult.PackageName)
apiViewArtifact := filepath.Join(sdkRepo.Root(), "sdk", "resourcemanager", namespaceResult.RPName, namespaceResult.PackageName+".gosource")
srcFolder := filepath.Join(sdkRepo.Root(), packageRelativePath)
apiViewArtifact := filepath.Join(sdkRepo.Root(), packageRelativePath+".gosource")
err := zipDirectory(srcFolder, apiViewArtifact)
if err != nil {
fmt.Println(err)
}

results = append(results, pipeline.PackageResult{
Version: namespaceResult.Version,
PackageName: fmt.Sprintf("sdk/resourcemanager/%s/%s", namespaceResult.RPName, namespaceResult.PackageName),
Path: []string{fmt.Sprintf("sdk/resourcemanager/%s/%s", namespaceResult.RPName, namespaceResult.PackageName)},
PackageFolder: fmt.Sprintf("sdk/resourcemanager/%s/%s", namespaceResult.RPName, namespaceResult.PackageName),
PackageName: packageRelativePath,
Path: []string{packageRelativePath},
PackageFolder: packageRelativePath,
TypespecProject: []string{tspProjectFolder},
Changelog: &pipeline.Changelog{
Content: &content,
HasBreakingChange: &breaking,
BreakingChangeItems: &breakingChangeItems,
},
APIViewArtifact: fmt.Sprintf("sdk/resourcemanager/%s/%s", namespaceResult.RPName, namespaceResult.PackageName+".gosource"),
APIViewArtifact: packageRelativePath + ".gosource",
Language: "Go",
})

Expand Down
7 changes: 4 additions & 3 deletions eng/tools/generator/cmd/v2/common/changelogProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ const (
sdk_remote_url = "https://github.com/Azure/azure-sdk-for-go.git"
)

func GetAllVersionTags(rpName, namespaceName string) ([]string, error) {
log.Printf("Fetching all release tags from GitHub for RP: '%s' Package: '%s' ...", rpName, namespaceName)
func GetAllVersionTags(relativePath string) ([]string, error) {
arr := strings.Split(relativePath, "/")
log.Printf("Fetching all release tags from GitHub for RP: '%s' Package: '%s' ...", arr[len(arr)-2], arr[len(arr)-1])
client := http.Client{}
res, err := client.Get(sdk_tag_fetch_url)
if err != nil {
Expand All @@ -51,7 +52,7 @@ func GetAllVersionTags(rpName, namespaceName string) ([]string, error) {
versionTag := make(map[string]string)
for _, tag := range result {
tagName := tag["ref"].(string)
if strings.Contains(tagName, "sdk/resourcemanager/"+rpName+"/"+namespaceName+"/v") {
if strings.Contains(tagName, relativePath+"/v") {
m := regexp.MustCompile(semver.SemVerRegex).FindString(tagName)
versions = append(versions, m)
versionTag[m] = tagName
Expand Down
2 changes: 1 addition & 1 deletion eng/tools/generator/cmd/v2/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ package common

const (
ChangelogFileName = "CHANGELOG.md"
MgmtSDKModulePrefix = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager"
tadelesh marked this conversation as resolved.
Show resolved Hide resolved
MgmtSDKModulePrefix = "github.com/Azure/azure-sdk-for-go"
)
8 changes: 4 additions & 4 deletions eng/tools/generator/cmd/v2/common/fileProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func ReplaceNewClientNamePlaceholder(packageRootPath string, exports exports.Con
return os.WriteFile(path, []byte(content), 0644)
}

func UpdateModuleDefinition(packageRootPath, rpName, namespaceName string, version *semver.Version) error {
func UpdateModuleDefinition(packageRootPath, relativePath string, version *semver.Version) error {
if version.Major() > 1 {
path := filepath.Join(packageRootPath, "go.mod")

Expand All @@ -431,7 +431,7 @@ func UpdateModuleDefinition(packageRootPath, rpName, namespaceName string, versi
line = strings.TrimRight(line, "\r")
parts := strings.Split(line, "/")
if parts[len(parts)-1] != fmt.Sprintf("v%d", version.Major()) {
lines[i] = fmt.Sprintf("module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/%s/%s/v%d", rpName, namespaceName, version.Major())
lines[i] = fmt.Sprintf("module github.com/Azure/azure-sdk-for-go/%s/v%d", relativePath, version.Major())
}
break
}
Expand Down Expand Up @@ -621,13 +621,13 @@ func existSuffixFile(path, suffix string) bool {
return existed
}

func replaceReadmeModule(path, rpName, namespaceName, currentVersion string) error {
func replaceReadmeModule(path, relativePath, currentVersion string) error {
readmeFile, err := os.ReadFile(filepath.Join(path, "README.md"))
if err != nil {
return err
}

module := fmt.Sprintf("github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/%s/%s", rpName, namespaceName)
module := fmt.Sprintf("github.com/Azure/azure-sdk-for-go/%s", relativePath)

readmeModule := module
match := regexp.MustCompile(fmt.Sprintf(`%s/v\d+`, module))
Expand Down
20 changes: 10 additions & 10 deletions eng/tools/generator/cmd/v2/common/generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (ctx *GenerateContext) GenerateForSingleRPNamespace(generateParam *Generate
if !onBoard {
log.Printf("Get ori exports for changelog generation...")

tags, err := GetAllVersionTags(generateParam.RPName, generateParam.NamespaceName)
tags, err := GetAllVersionTags("sdk/resourcemanager/" + generateParam.RPName + "/" + generateParam.NamespaceName)
tadelesh marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -308,7 +308,7 @@ func (ctx *GenerateContext) GenerateForSingleRPNamespace(generateParam *Generate
}

log.Printf("Update module definition if v2+...")
err = UpdateModuleDefinition(packagePath, generateParam.RPName, generateParam.NamespaceName, version)
err = UpdateModuleDefinition(packagePath, filepath.Join("sdk/resourcemanager", generateParam.RPName, generateParam.NamespaceName), version)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -341,7 +341,7 @@ func (ctx *GenerateContext) GenerateForSingleRPNamespace(generateParam *Generate
}

log.Printf("Replace README.md module...")
if err = replaceReadmeModule(packagePath, generateParam.RPName, generateParam.NamespaceName, version.String()); err != nil {
if err = replaceReadmeModule(packagePath, filepath.Join("sdk/resourcemanager", generateParam.RPName, generateParam.NamespaceName), version.String()); err != nil {
return nil, err
}

Expand Down Expand Up @@ -374,8 +374,8 @@ func (ctx *GenerateContext) GenerateForSingleRPNamespace(generateParam *Generate
}
}

func (ctx *GenerateContext) GenerateForTypeSpec(generateParam *GenerateParam) (*GenerateResult, error) {
packagePath := filepath.Join(ctx.SDKPath, "sdk", "resourcemanager", generateParam.RPName, generateParam.NamespaceName)
func (ctx *GenerateContext) GenerateForTypeSpec(generateParam *GenerateParam, relativePath string) (*GenerateResult, error) {
packagePath := filepath.Join(ctx.SDKPath, relativePath)
changelogPath := filepath.Join(packagePath, ChangelogFileName)

version, err := semver.NewVersion("0.1.0")
Expand Down Expand Up @@ -448,13 +448,13 @@ func (ctx *GenerateContext) GenerateForTypeSpec(generateParam *GenerateParam) (*
if !onBoard {
log.Printf("Get ori exports for changelog generation...")

tags, err := GetAllVersionTags(generateParam.RPName, generateParam.NamespaceName)
tags, err := GetAllVersionTags(relativePath)
if err != nil {
return nil, err
}

if len(tags) == 0 {
return nil, fmt.Errorf("github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/%s/%s hasn't been released, it's supposed to OnBoard", generateParam.RPName, generateParam.NamespaceName)
return nil, fmt.Errorf("github.com/Azure/azure-sdk-for-go/%s hasn't been released, it's supposed to OnBoard", relativePath)
}

previousVersionTag := GetPreviousVersionTag(isCurrentPreview, tags)
Expand Down Expand Up @@ -546,7 +546,7 @@ func (ctx *GenerateContext) GenerateForTypeSpec(generateParam *GenerateParam) (*
}

log.Printf("Update module definition if v2+...")
err = UpdateModuleDefinition(packagePath, generateParam.RPName, generateParam.NamespaceName, version)
err = UpdateModuleDefinition(packagePath, relativePath, version)
if err != nil {
return nil, err
}
Expand All @@ -561,7 +561,7 @@ func (ctx *GenerateContext) GenerateForTypeSpec(generateParam *GenerateParam) (*
return nil, err
}

baseModule := fmt.Sprintf("%s/%s/%s", MgmtSDKModulePrefix, generateParam.RPName, generateParam.NamespaceName)
baseModule := fmt.Sprintf("%s/%s", MgmtSDKModulePrefix, relativePath)
tadelesh marked this conversation as resolved.
Show resolved Hide resolved
if _, err := os.Stat(filepath.Join(packagePath, "fake")); !os.IsNotExist(err) && oldModuleVersion.Major() != version.Major() {
log.Printf("Replace fake module v2+...")
if err = ReplaceModule(version, packagePath, baseModule, ".go"); err != nil {
Expand All @@ -578,7 +578,7 @@ func (ctx *GenerateContext) GenerateForTypeSpec(generateParam *GenerateParam) (*
}

log.Printf("Replace README.md module...")
if err = replaceReadmeModule(packagePath, generateParam.RPName, generateParam.NamespaceName, version.String()); err != nil {
if err = replaceReadmeModule(packagePath, relativePath, version.String()); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion eng/tools/generator/cmd/v2/release/releaseCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (c *commandContext) generate(sdkRepo repo.SDKRepository, specCommitHash str
GoVersion: c.flags.GoVersion,
TypeSpecEmitOption: c.flags.TypeSpecGoOption,
TspClientOptions: c.flags.TspClientOption,
})
}, generateCtx.TypeSpecConfig.GetRelativePath())
} else {
log.Printf("Generate SDK through AutoRest...")
result, err = generateCtx.GenerateForSingleRPNamespace(&common.GenerateParam{
Expand Down
8 changes: 6 additions & 2 deletions eng/tools/generator/typespec/tspconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func ParseTypeSpecConfig(tspconfigPath string) (*TypeSpecConfig, error) {
return &tspConfig, err
}

func (tsc *TypeSpecConfig) GetRelativePath() string {
tadelesh marked this conversation as resolved.
Show resolved Hide resolved
return tsc.Options["@azure-tools/typespec-go"].(map[string]interface{})["service-dir"].(string) + "/" + tsc.Options["@azure-tools/typespec-go"].(map[string]interface{})["package-dir"].(string)
tadelesh marked this conversation as resolved.
Show resolved Hide resolved
}

func (tc *TypeSpecConfig) EditOptions(emit string, option map[string]any, append bool) {
if tc.Options == nil {
tc.Options = make(map[string]any)
Expand Down Expand Up @@ -177,8 +181,8 @@ func (tc TypeSpecConfig) GetModuleName() ([2]string, error) {
if l != 7 {
return [2]string{}, fmt.Errorf("module is invalid and must be in the format of `github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/{rpName}/{packageName}`")
}
if !strings.Contains(s[l-1], "arm") {
return [2]string{}, fmt.Errorf("packageName is invalid and must start with `arm`")
if !strings.Contains(s[l-1], "arm") && !strings.Contains(s[l-1], "az") {
return [2]string{}, fmt.Errorf("packageName is invalid and must start with `arm` or `az`")
}

return [2]string{s[l-2], s[l-1]}, nil
Expand Down
Loading