Skip to content

Commit

Permalink
chore: change all naming from track2 to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
tadelesh committed Aug 18, 2021
1 parent db9c1f0 commit b9aa7a7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions eng/swagger_to_sdk_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/documentation/sdkautomation/SwaggerToSdkConfigSchema.json",
"generateOptions": {
"generateScript": {
"path": "generator automation-new-version",
"path": "generator automation-v2",
"stderr": {
"showInComment": "^\\[AUTOREST\\]",
"scriptError": "^\\[ERROR\\]",
Expand All @@ -23,6 +23,6 @@
}
},
"packageOptions": {
"breakingChangeLabel": "CI-BreakingChange-Go-NewVersion"
"breakingChangeLabel": "CI-BreakingChange-Go-V2"
}
}
8 changes: 4 additions & 4 deletions tools/generator/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/Azure/azure-sdk-for-go/tools/generator/cmd/automation"
"github.com/Azure/azure-sdk-for-go/tools/generator/cmd/issue"
"github.com/Azure/azure-sdk-for-go/tools/generator/cmd/template"
automation_track2 "github.com/Azure/azure-sdk-for-go/tools/generator/cmd/track2/automation"
release_track2 "github.com/Azure/azure-sdk-for-go/tools/generator/cmd/track2/release"
automation_v2 "github.com/Azure/azure-sdk-for-go/tools/generator/cmd/v2/automation"
release_v2 "github.com/Azure/azure-sdk-for-go/tools/generator/cmd/v2/release"
"github.com/spf13/cobra"
)

Expand All @@ -31,8 +31,8 @@ func Command() *cobra.Command {

rootCmd.AddCommand(
automation.Command(),
automation_track2.Command(),
release_track2.Command(),
automation_v2.Command(),
release_v2.Command(),
issue.Command(),
template.Command(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
"strings"

"github.com/Azure/azure-sdk-for-go/tools/generator/cmd/automation/pipeline"
"github.com/Azure/azure-sdk-for-go/tools/generator/cmd/track2/common"
"github.com/Azure/azure-sdk-for-go/tools/generator/cmd/v2/common"
"github.com/Azure/azure-sdk-for-go/tools/internal/utils"
"github.com/spf13/cobra"
)

// Command returns the automation for track2 command. Note that this command is designed to run in the root directory of
// Command returns the automation v2 command. Note that this command is designed to run in the root directory of
// azure-sdk-for-go. It does not work if you are running this tool in somewhere else
func Command() *cobra.Command {
cmd := &cobra.Command{
Use: "automation-new-version <generate input filepath> <generate output filepath>",
Use: "automation-v2 <generate input filepath> <generate output filepath>",
Args: cobra.ExactArgs(2),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
log.SetFlags(0) // remove the time stamp prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ const (
)

var (
track2BeginRegex = regexp.MustCompile("^```\\s*yaml\\s*\\$\\(go\\)\\s*&&\\s*\\$\\(track2\\)")
track2EndRegex = regexp.MustCompile("^\\s*```\\s*$")
v2BeginRegex = regexp.MustCompile("^```\\s*yaml\\s*\\$\\(go\\)\\s*&&\\s*\\$\\(track2\\)")
v2EndRegex = regexp.MustCompile("^\\s*```\\s*$")
autorestMdSwaggerURLBeginRegex = regexp.MustCompile(`https://github.com/.+/azure-rest-api-specs/`)
newClientMethodNameRegex = regexp.MustCompile("^New.+Client$")
)

// reads from readme.go.md, parses the `track2` section to get module and package name
func ReadTrack2ModuleNameToGetNamespace(path string) (map[string][]string, error) {
func ReadV2ModuleNameToGetNamespace(path string) (map[string][]string, error) {
result := make(map[string][]string)
log.Printf("Reading from readme.go.md '%s'...", path)
file, err := os.Open(path)
Expand All @@ -52,30 +52,30 @@ func ReadTrack2ModuleNameToGetNamespace(path string) (map[string][]string, error
var start []int
var end []int
for i, line := range lines {
if track2BeginRegex.MatchString(line) {
if v2BeginRegex.MatchString(line) {
start = append(start, i)
}
if len(start) != len(end) && track2EndRegex.MatchString(line) {
if len(start) != len(end) && v2EndRegex.MatchString(line) {
end = append(end, i)
}
}

if len(start) == 0 {
return nil, fmt.Errorf("cannot find any track2 section")
return nil, fmt.Errorf("cannot find any `track2` section")
}
if len(start) != len(end) {
return nil, fmt.Errorf("last track2 section does not properly end")
return nil, fmt.Errorf("last `track2` section does not properly end")
}

for i := range start {
// get the content of the track2 section
track2Section := lines[start[i]+1 : end[i]]
// get the content of the `track2` section
section := lines[start[i]+1 : end[i]]
// iterate over the rest lines, get module name
for _, line := range track2Section {
for _, line := range section {
if strings.HasPrefix(line, swagger_md_module_name_prefix) {
modules := strings.Split(strings.TrimSpace(line[len(swagger_md_module_name_prefix):]), "/")
if len(modules) != 3 {
return nil, fmt.Errorf("cannot parse module name from track2 section")
return nil, fmt.Errorf("cannot parse module name from `track2` section")
}
namespaceName := strings.TrimSuffix(strings.TrimSuffix(modules[2], "\n"), "\r")
log.Printf("RP: %s Package: %s", modules[1], namespaceName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (ctx GenerateContext) GenerateForAutomation(readme string, repo string) ([]
var errors []error

log.Printf("Get all namespaces from readme file")
rpMap, err := ReadTrack2ModuleNameToGetNamespace(absReadmeGo)
rpMap, err := ReadV2ModuleNameToGetNamespace(absReadmeGo)
if err != nil {
return nil, []error{
fmt.Errorf("cannot get rp and namespaces from readme '%s': %+v", readme, err),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"
"time"

"github.com/Azure/azure-sdk-for-go/tools/generator/cmd/track2/common"
"github.com/Azure/azure-sdk-for-go/tools/generator/cmd/v2/common"
"github.com/Azure/azure-sdk-for-go/tools/generator/flags"
"github.com/Azure/azure-sdk-for-go/tools/generator/repo"
"github.com/spf13/cobra"
Expand All @@ -19,9 +19,9 @@ import (
// Release command
func Command() *cobra.Command {
releaseCmd := &cobra.Command{
Use: "release-track2 <azure-sdk-for-go directory> <azure-rest-api-specs directory> <rp-name> <namespaceName>",
Short: "Generate a track2 release of azure-sdk-for-go",
Long: `This command will generate a new track2 release for azure-sdk-for-go with given rp name and namespace name.
Use: "release-v2 <azure-sdk-for-go directory> <azure-rest-api-specs directory> <rp-name> <namespaceName>",
Short: "Generate a v2 release of azure-sdk-for-go",
Long: `This command will generate a new v2 release for azure-sdk-for-go with given rp name and namespace name.
azure-sdk-for-go directory: the directory path of the azure-sdk-for-go with git control
azure-rest-api-specs directory: the directory path of the azure-rest-api-specs with git control
Expand Down

0 comments on commit b9aa7a7

Please sign in to comment.