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

Introducing profileBuilder and rewriting generator #767

Merged
merged 36 commits into from
Sep 21, 2017
Merged

Conversation

marstr
Copy link
Member

@marstr marstr commented Sep 11, 2017

This is laying the foundation to move to the Multiple API Version and Profile future of our API. Once this is accepted, I'll send another PR with the generated new packages including each API Version and profile.

You can see examples of what the generated code looks like here:
https://github.com/Azure/azure-sdk-for-go/tree/experimental/allAPIVersions

glide.lock Outdated
=======
hash: fc11c273a4bfae9a077f2238a4693fa3af3d815dfc1b1e9ec75d9eb8e6428993
updated: 2017-05-23T10:47:59.5894489-07:00
>>>>>>> c9acadb... Fixing glide defs to include Masterminds/semver
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge branches failed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops whoops whoops, I'll get this cleaned up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed Locally


const (
defaultRemoteAzureRestAPISpecsPath = "https://github.com/Azure/azure-rest-api-specs.git"
defaultAzureRESTAPIBranch = "master"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

master [](start = 39, length = 6)

The branch we use is "current"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed locally

}

func cloneAPISpecs(origin, local string) (string, error) {
_, cloneLoc := filepath.Split(local)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autorest does not need the repo to be cloned on local. You can do autorest [https://raw.githubusercontent.com/Azure/azure-rest-api-specs/current/specification/graphrbac/data-plane/readme.md](https://raw.githubusercontent.com/Azure/azure-rest-api-specs/current/specification/graphrbac/data-plane/readme.md%60).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is a new developement, that's great :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this in here for now though, I suspect I'm going to have to make a bunch of changes to accomodate the new Autorest work.

}

fmt.Println("Summary:")
fmt.Println("\tFound: \t", found)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be useful to also go build packages, I think.

"-OutputDirectory", outputDir,
"-Modeler", "Swagger",
"-pv", version.String(),
"-SkipValidation")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from the legacy autorest CLI

`[Mm]icrosoft\.(?P<category>[\w\-]+)`,
`(?P<apiVersion>v?\d{4}-\d{2}-\d{2}(?:[\-\.][\w\d\-\.]+)?)`,
`(?P<group>[\w\-\d\.]+)\.json`,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you support md files as input?

// AcceptAll is a predefined value for `LatestStrategy.Predicate` which always returns true.
func AcceptAll(name string) (result bool) {
result = true
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to keep it simple and return true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make this change because I like you and Joel. 😝

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed locally

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=^w^=

// IgnorePreview searches a packages "API Version" to see if it contains the word "preview". It only returns true when a package is not a preview.
func IgnorePreview(name string) (result bool) {
matches := packageName.FindStringSubmatch(name)
if len(matches) >= 4 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= 4 [](start = 17, length = 4)

These number look a bit magical, add a comment explaining a little bit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're telling me you don't appreciate the magic in life? Sure thing, I'll add some documentation here.

I was actually quite frustrated with Go's Regexp library, because in C# you can reference groups by the name you gave them instead of some index. The way goes about it, it's quite prone to these sorts of magic numbers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed locally

}

var versionle = func() func(string, string) (bool, error) {
versionPattern := regexp.MustCompile(`^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})(?:[\.\-](?P<tag>.+))?$`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

versionPattern [](start = 1, length = 14)

Graphrbac uses a different pattern

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the amount of work for this versus the reward warrants fixing this in a separate PR.

outputLog.Print("Profile Name Set to: ", profileName)
}

//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// [](start = 1, length = 2)

O.O

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed locally

go get -d github.com/Azure/azure-sdk-for-go/tools/profileBuilder
cd $GOPATH/src/github.com/Azure/azure-sdk-for-go/tools/profileBuilder
glide install
export currentCommit=$(git rev-parse HEAD)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git rev-parse HEAD [](start = 23, length = 18)

Could this be executed inside the profile builder, and just have a bool flag for including or not the commit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it cannot be done this way :) That would result in the profileBuilder always telling you it was the most up-to-date version even if it wasn't. We really need to set this variable at build time the way I've done it.

- Generator now uses TEMP directory to write logs of the results.
- Autorest is called from the correct directory.
The tools/profileBuilder package will traverse services/ directory in
search of the most recent API Versions of individual Operation Groups.
Optionally, this operation will include preview versions.
It will also be able to be configured to read the individual packages
required from a list to create a custom profile.
Also, adding Apache 2.0 headers to each of the files touched here and
writing installation instructions.
@marstr marstr merged commit efc2ffd into Azure:dev Sep 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants