-
Notifications
You must be signed in to change notification settings - Fork 974
[tools/generator] add automation and release command for track2 #15271
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
93ec460
[tools/generator] add automation and release command for track2
tadelesh db0bd9c
add copyright and do gofmt
tadelesh 245a69f
Use semver to pump version, move git operation to repo package and fi…
tadelesh c82b9eb
Add specfic version to release cmd, seperate package for automation a…
tadelesh 5d4edd2
add automation script and config for track2
tadelesh 417cf29
fix: three dots path not work in linux in build script
tadelesh 5a53141
fix: ln pwsh.exe to pwsh to run in linux
tadelesh 0cd9e08
fix: ignore dep check for go-git
tadelesh 92659f5
chore: label name change for track2
tadelesh 3a27314
fix: wrong package path result in empty git commit
tadelesh 57a5c39
fix: repo addr replacement in autorest.md
tadelesh f77a02c
chore: move script to eng folder and change name
tadelesh db9c1f0
fix: onboard generation need to replace NewClientMethod
tadelesh 657ec8d
chore: change all naming from track2 to v2
tadelesh 4eabb8f
fix: add new build constraint
tadelesh ac3b18e
fix: template compat with go 1.17 and change commit msg for release
tadelesh c3bae2d
chore: add v2 to readme begin regex to support future change of `trac…
tadelesh 4afbde6
chore: remove track2 naming
tadelesh d6b470c
fix: duplicated and wrong expression
tadelesh 726242c
fix: add package title param to release cmd
tadelesh 0fd2226
fix: ci
tadelesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| set -x | ||
| set -e | ||
| export GOPATH="$(realpath ../../../..)" | ||
| if [ ! -d "$GOPATH/bin" ] | ||
| then | ||
| mkdir $GOPATH/bin | ||
| fi | ||
| PATH=$PATH:$GOPATH/bin | ||
| export GO111MODULE=on | ||
| cd tools/generator && go build && cp generator $GOPATH/bin && cd ../.. | ||
| ln -s /usr/bin/pwsh $GOPATH/bin/pwsh.exe | ||
| cat > $2 << EOF | ||
| { | ||
| "envs": { | ||
| "PATH": "$PATH:$GOPATH", | ||
| "GOPATH": "$GOPATH" | ||
| } | ||
| } | ||
| EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "$schema": "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/documentation/sdkautomation/SwaggerToSdkConfigSchema.json", | ||
| "generateOptions": { | ||
| "generateScript": { | ||
| "path": "generator automation-v2", | ||
| "stderr": { | ||
| "showInComment": "^\\[AUTOREST\\]", | ||
| "scriptError": "^\\[ERROR\\]", | ||
| "scriptWarning": "^\\[WARNING\\]" | ||
| } | ||
| } | ||
| }, | ||
| "advancedOptions": { | ||
| "cloneDir": "src/github.com/Azure/azure-sdk-for-go", | ||
| "breakingChangeTracking": true | ||
| }, | ||
| "initOptions": { | ||
| "initScript": { | ||
| "path": "sh ./eng/scripts/automation_init.sh", | ||
| "stderr": { | ||
| "scriptWarning": false | ||
| } | ||
| } | ||
| }, | ||
| "packageOptions": { | ||
| "breakingChangeLabel": "CI-BreakingChange-Go-V2" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| package automation | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/Azure/azure-sdk-for-go/tools/generator/cmd/automation/pipeline" | ||
| "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 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-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 | ||
| return nil | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if err := execute(args[0], args[1]); err != nil { | ||
| logError(err) | ||
| return err | ||
| } | ||
| return nil | ||
| }, | ||
| SilenceUsage: true, // this command is used for a pipeline, the usage should never show | ||
| } | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func execute(inputPath, outputPath string) error { | ||
| log.Printf("Reading generate input file from '%s'...", inputPath) | ||
| input, err := pipeline.ReadInput(inputPath) | ||
| if err != nil { | ||
| return fmt.Errorf("cannot read generate input: %+v", err) | ||
| } | ||
| log.Printf("Generating using the following GenerateInput...\n%s", input.String()) | ||
| cwd, err := os.Getwd() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| log.Printf("Using current directory as SDK root: %s", cwd) | ||
|
|
||
| ctx := automationContext{ | ||
| sdkRoot: utils.NormalizePath(cwd), | ||
| specRoot: input.SpecFolder, | ||
| commitHash: input.HeadSha, | ||
| } | ||
| output, err := ctx.generate(input) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| log.Printf("Output generated: \n%s", output.String()) | ||
| log.Printf("Writing output to file '%s'...", outputPath) | ||
| if err := pipeline.WriteOutput(outputPath, output); err != nil { | ||
| return fmt.Errorf("cannot write generate output: %+v", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| type automationContext struct { | ||
| sdkRoot string | ||
| specRoot string | ||
| commitHash string | ||
| } | ||
|
|
||
| // TODO -- support dry run | ||
| func (ctx *automationContext) generate(input *pipeline.GenerateInput) (*pipeline.GenerateOutput, error) { | ||
| if input.DryRun { | ||
| return nil, fmt.Errorf("dry run not supported yet") | ||
| } | ||
|
|
||
| // iterate over all the readme | ||
| results := make([]pipeline.PackageResult, 0) | ||
| errorBuilder := generateErrorBuilder{} | ||
| for _, readme := range input.RelatedReadmeMdFiles { | ||
| log.Printf("Start to process readme file: %s", readme) | ||
| generateCtx := common.GenerateContext{ | ||
| SdkPath: ctx.sdkRoot, | ||
| SpecPath: ctx.specRoot, | ||
| CommitHash: ctx.commitHash, | ||
| } | ||
|
|
||
| namespaceResults, errors := generateCtx.GenerateForAutomation(readme, input.RepoHTTPSURL) | ||
| if len(errors) != 0 { | ||
| errorBuilder.add(errors...) | ||
| continue | ||
| } | ||
|
|
||
| for _, namespaceResult := range namespaceResults { | ||
| content := namespaceResult.ChangelogMd | ||
| breaking := namespaceResult.Changelog.HasBreakingChanges() | ||
| breakingChangeItems := namespaceResult.Changelog.GetBreakingChangeItems() | ||
|
|
||
| results = append(results, pipeline.PackageResult{ | ||
| Version: namespaceResult.Version, | ||
| PackageName: namespaceResult.PackageName, | ||
| Path: []string{fmt.Sprintf("sdk/%s/%s", namespaceResult.RpName, namespaceResult.PackageName)}, | ||
| ReadmeMd: []string{readme}, | ||
| Changelog: &pipeline.Changelog{ | ||
| Content: &content, | ||
| HasBreakingChange: &breaking, | ||
| BreakingChangeItems: &breakingChangeItems, | ||
| }, | ||
| }) | ||
| } | ||
| log.Printf("Finish to process readme file: %s", readme) | ||
| } | ||
|
|
||
| return &pipeline.GenerateOutput{ | ||
| Packages: results, | ||
| }, errorBuilder.build() | ||
| } | ||
|
|
||
| type generateErrorBuilder struct { | ||
| errors []error | ||
| } | ||
|
|
||
| func (b *generateErrorBuilder) add(err ...error) { | ||
| b.errors = append(b.errors, err...) | ||
| } | ||
|
|
||
| func (b *generateErrorBuilder) build() error { | ||
| if len(b.errors) == 0 { | ||
| return nil | ||
| } | ||
| var messages []string | ||
| for _, err := range b.errors { | ||
| messages = append(messages, err.Error()) | ||
| } | ||
| return fmt.Errorf("total %d error(s): \n%s", len(b.errors), strings.Join(messages, "\n")) | ||
| } | ||
|
|
||
| func logError(err error) { | ||
| for _, line := range strings.Split(err.Error(), "\n") { | ||
| if l := strings.TrimSpace(line); l != "" { | ||
| log.Printf("[ERROR] %s", l) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| package common | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log" | ||
| "os/exec" | ||
| ) | ||
|
|
||
| // execute `go generate` command and fetch result | ||
| func ExecuteGoGenerate(path string) error { | ||
| cmd := exec.Command("go", "generate") | ||
| cmd.Dir = path | ||
| output, err := cmd.CombinedOutput() | ||
| log.Printf("Result of `go generate` execution: \n%s", string(output)) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to execute go generate '%s': %+v", string(output), err) | ||
| } | ||
| return nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.