Skip to content

Commit ec58f5b

Browse files
Verify autorest in pipeline (Azure#16667)
Azure#13724
1 parent 775284a commit ec58f5b

File tree

11 files changed

+209
-20
lines changed

11 files changed

+209
-20
lines changed

eng/.docsettings.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,15 @@ known_content_issues:
8888
- ['sdk/eventgrid/azure-eventgrid/README.md', '#4554']
8989
- ['sdk/graphrbac/azure-graphrbac/README.md', '#4554']
9090
- ['sdk/loganalytics/azure-loganalytics/README.md', '#4554']
91-
- ['sdk/schemaregistry/azure-schemaregistry/swagger/README.md', '#4554']
9291
- ['sdk/servicebus/azure-servicebus/README.md', '#4554']
93-
- ['sdk/servicebus/azure-servicebus/swagger/README.md', '#4554']
9492
- ['sdk/servicebus/azure-servicebus/tests/perf_tests/README.md', '#4554']
9593
- ['sdk/servicefabric/azure-servicefabric/README.md', '#4554']
9694
- ['sdk/storage/azure-storage-nspkg/README.md', '#4554']
97-
- ['sdk/storage/azure-storage-blob/swagger/README.md', '#4554']
98-
- ['sdk/storage/azure-storage-file-datalake/swagger/README.md', '#4554']
99-
- ['sdk/storage/azure-storage-file-share/swagger/README.md', '#4554']
10095
- ['sdk/storage/azure-storage/README.md', '#4554']
10196
- ['sdk/storage/azure-storage-nspkg/README.rst', '#4554']
102-
- ['sdk/storage/azure-storage-queue/swagger/README.md', '#4554']
10397
- ['sdk/storage/README.md', '#4554']
10498
- ['sdk/textanalytics/azure-ai-textanalytics/samples/README.md', '#4554']
105-
- ['sdk/monitor/azure-monitor-opentelemetry-exporter/swagger/README.md', '#4554']
10699
- ['sdk/monitor/azure-monitor-opentelemetry-exporter/README.md', '#4554']
107-
- ['sdk/digitaltwins/azure-digitaltwins-core/swagger/README.md', '#4554']
108-
- ['sdk/textanalytics/azure-ai-textanalytics/swagger/README.md', '#4554']
109100
- ['sdk/media/azure-media-nspkg/README.md', '#4554']
110101
- ['sdk/containerregistry/azure-containerregistry/swagger/README.md', '#4554']
111102
- ['sdk/appconfiguration/azure-appconfiguration/swagger/README.md', '#4554']
@@ -156,6 +147,18 @@ known_content_issues:
156147
- ['doc/dev/mgmt/README.md', 'dev readme']
157148
- ['doc/dev/README.md', dev readme']
158149
- ['doc/README.md', 'dev readme']
150+
151+
# swagger files
152+
- ['sdk/schemaregistry/azure-schemaregistry/swagger/README.md', '#4554']
153+
- ['sdk/servicebus/azure-servicebus/swagger/README.md', '#4554']
154+
- ['sdk/storage/azure-storage-blob/swagger/README.md', '#4554']
155+
- ['sdk/storage/azure-storage-file-datalake/swagger/README.md', '#4554']
156+
- ['sdk/storage/azure-storage-file-share/swagger/README.md', '#4554']
157+
- ['sdk/storage/azure-storage-queue/swagger/README.md', '#4554']
158+
- ['sdk/monitor/azure-monitor-opentelemetry-exporter/swagger/README.md', '#4554']
159+
- ['sdk/digitaltwins/azure-digitaltwins-core/swagger/README.md', '#4554']
160+
- ['sdk/textanalytics/azure-ai-textanalytics/swagger/README.md', '#4554']
161+
- ['sdk/appconfiguration/azure-appconfiguration/swagger/README.md', '#4554']
159162
package_indexing_exclusion_list:
160163
- 'azure-sdk-tools'
161164
- 'azure-template'

eng/autorest_req.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ pytest-cov==2.8.1
44
pytest-asyncio==0.12.0; python_version >= '3.5'
55
isodate==0.6.0
66
msrest==0.6.14
7-
aiohttp==3.6.2
8-
wheel==0.34.2
7+
wheel==0.34.2
8+
GitPython==3.1.14
9+
aiohttp==3.6.2; python_version >= '3.6'

eng/pipelines/templates/jobs/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ parameters:
4343
- name: MatrixReplace
4444
type: object
4545
default: []
46+
- name: VerifyAutorest
47+
type: boolean
48+
default: false
4649

4750
jobs:
4851
- job: 'Build'
@@ -100,6 +103,7 @@ jobs:
100103
AdditionalTestArgs: '--wheel_dir="$(Build.ArtifactStagingDirectory)"'
101104
TestPipeline: ${{ parameters.TestPipeline }}
102105
Artifacts: ${{ parameters.Artifacts }}
106+
VerifyAutorest: ${{ parameters.VerifyAutorest }}
103107

104108
- template: /eng/common/pipelines/templates/jobs/archetype-sdk-tests-generate.yml
105109
parameters:

eng/pipelines/templates/stages/archetype-sdk-client.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ parameters:
5757
- name: MatrixReplace
5858
type: object
5959
default: []
60+
- name: VerifyAutorest
61+
type: boolean
62+
default: false
6063

6164
stages:
6265
- stage: Build
@@ -88,6 +91,7 @@ stages:
8891
- OsVmImage=macOS-10.15/MMSUbuntu18.04
8992
- ${{ each replacement in parameters.MatrixReplace }}:
9093
- ${{ replacement }}
94+
VerifyAutorest: ${{ parameters.VerifyAutorest }}
9195

9296

9397
# The Prerelease and Release stages are conditioned on whether we are building a pull request and the branch.
@@ -115,4 +119,4 @@ stages:
115119
ArtifactName: conda
116120
${{ if eq(parameters.ServiceDirectory, 'template') }}:
117121
TestPipeline: true
118-
122+

eng/pipelines/templates/steps/analyze.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ parameters:
55
AdditionalTestArgs: ''
66
Artifacts: []
77
TestPipeline: false
8+
VerifyAutorest: false
89

910
steps:
1011
- template: /eng/pipelines/templates/steps/analyze_dependency.yml
@@ -57,6 +58,11 @@ steps:
5758
parameters:
5859
SourceDirectory: $(Build.SourcesDirectory)
5960

61+
- template: ../steps/verify-autorest.yml
62+
parameters:
63+
ServiceDirectory: ${{ parameters.ServiceDirectory }}
64+
VerifyAutorest: ${{ parameters.VerifyAutorest }}
65+
6066
- task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
6167
# ComponentGovernance is currently unable to run on pull requests of public projects. Running on non-PR
6268
# builds should be sufficient.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
parameters:
2+
- name: ServiceDirectory
3+
type: string
4+
- name: NodeVersion
5+
type: string
6+
default: '12.x'
7+
- name: PythonVersion
8+
type: string
9+
default: '$(PythonVersion)'
10+
- name: auto_rest_clone_url
11+
type: string
12+
default: 'https://github.com/Azure/autorest.python.git'
13+
- name: VerifyAutorest
14+
type: boolean
15+
default: false
16+
17+
steps:
18+
- ${{if eq(parameters.VerifyAutorest, 'true')}}:
19+
- template: /eng/common/pipelines/templates/steps/set-default-branch.yml
20+
21+
- task: UsePythonVersion@0
22+
displayName: Use
23+
inputs:
24+
versionSpec: ${{ parameters.PythonVersion }}
25+
26+
- task: NodeTool@0
27+
inputs:
28+
versionSpec: ${{ parameters.NodeVersion }}
29+
30+
- script: |
31+
npm install -g autorest
32+
autorest --help
33+
displayName: "Install autorest"
34+
35+
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
36+
parameters:
37+
Paths:
38+
- "/*"
39+
Repositories:
40+
- Name: "Azure/autorest.python"
41+
Commitish: "master"
42+
WorkingDirectory: "$(Build.SourcesDirectory)/autorest.python"
43+
SkipDefaultCheckout: true
44+
45+
- script: |
46+
python --version
47+
pip install -r eng/autorest_req.txt
48+
cd autorest.python
49+
npm install
50+
displayName: 'Prepare Environment'
51+
52+
- task: PythonScript@0
53+
displayName: 'Verify autorest'
54+
inputs:
55+
scriptPath: 'scripts/devops_tasks/verify_autorest.py'
56+
arguments: >-
57+
--service_directory="${{ parameters.ServiceDirectory }}"
58+
59+
- ${{ if and(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['System.TeamProject'], 'internal')) }}:
60+
- template: /eng/common/pipelines/templates/steps/create-pull-request.yml
61+
# # displayName: Create PR for ${{ ServiceDirectory }}
62+
# condition: and(ne(variables['Build.Reason'],'PullRequest'), eq(variables['System.TeamProject'], 'internal'))
63+
parameters:
64+
CommitMsg: "Regenerated code from nightly builds"
65+
PRTitle: "Automated autorest generation"
66+
PRBranchName: 'autorest-${{ ServiceDirectory }}'
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env python
2+
3+
# --------------------------------------------------------------------------------------------
4+
# Copyright (c) Microsoft Corporation. All rights reserved.
5+
# Licensed under the MIT License. See License.txt in the project root for license information.
6+
# --------------------------------------------------------------------------------------------
7+
8+
import argparse
9+
import os
10+
import logging
11+
import sys
12+
13+
from common_tasks import run_check_call
14+
15+
logging.getLogger().setLevel(logging.INFO)
16+
17+
root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", ".."))
18+
sdk_dir = os.path.join(root_dir, "sdk")
19+
20+
SWAGGER_FOLDER = "swagger"
21+
22+
23+
def run_autorest(service_dir):
24+
logging.info("Running autorest for {}".format(service_dir))
25+
26+
service_dir = os.path.join(sdk_dir, service_dir)
27+
28+
swagger_folders = find_swagger_folders(service_dir)
29+
30+
for working_dir in swagger_folders:
31+
os.chdir(working_dir)
32+
f = os.path.abspath(os.path.join(working_dir, "README.md"))
33+
if os.path.exists(f):
34+
reset_command = ["autorest", "--reset"]
35+
run_check_call(reset_command, root_dir)
36+
37+
command = ["autorest", "--python", f, "--verbose"]
38+
logging.info("Command: {}\nLocation: {}\n".format(command, working_dir))
39+
run_check_call(command, working_dir)
40+
return swagger_folders
41+
42+
43+
def find_swagger_folders(directory):
44+
logging.info("Searching for swagger files in: {}".format(directory))
45+
46+
ret = []
47+
for root, subdirs, files in os.walk(directory):
48+
for d in subdirs:
49+
if d == SWAGGER_FOLDER:
50+
if os.path.exists(os.path.join(root, d, "README.md")):
51+
ret.append(os.path.join(root, d))
52+
53+
logging.info("Found swagger files at: {}".format(ret))
54+
return ret
55+
56+
57+
def check_diff(folder):
58+
# We don't care about changes to txt files (dev_requirements change)
59+
run_check_call(["git", "status"], sdk_dir, always_exit=False)
60+
61+
command = [
62+
"git",
63+
"checkout",
64+
"--",
65+
"**/*.txt",
66+
]
67+
result = run_check_call(command, sdk_dir, always_exit=False)
68+
69+
# Remove the whl dirs
70+
command = [
71+
"rm",
72+
"-r",
73+
"**/.tmp_whl_dir/"
74+
]
75+
result = run_check_call(command, sdk_dir, always_exit=False)
76+
77+
# Next we need to move the autorest and _tox_logs directories and then replace them
78+
79+
dir_changed = folder.split("/")[:-2]
80+
command = [
81+
"git",
82+
"diff",
83+
"--exit-code",
84+
"{}".format("/".join(dir_changed)),
85+
]
86+
result = run_check_call(command, sdk_dir, always_exit=False)
87+
if result:
88+
command = ["git", "status"]
89+
run_check_call(command, root_dir)
90+
raise ValueError(
91+
"Found difference between re-generated code and current commit. Please re-generate with the latest autorest."
92+
)
93+
94+
95+
if __name__ == "__main__":
96+
parser = argparse.ArgumentParser(
97+
description="Run autorest to verify generated code."
98+
)
99+
parser.add_argument(
100+
"--service_directory", help="Directory of the package being tested"
101+
)
102+
103+
args = parser.parse_args()
104+
folders = run_autorest(args.service_directory)
105+
106+
if len(folders):
107+
for folder in folders:
108+
check_diff(folder)

sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/_configuration.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(
5151
self.endpoint = endpoint
5252
self.sync_token = sync_token
5353
self.api_version = "1.0"
54-
self.credential_scopes = kwargs.pop('credential_scopes', [])
54+
self.credential_scopes = kwargs.pop('credential_scopes', ['https://dev.azuresynapse.net/.default'])
5555
kwargs.setdefault('sdk_moniker', 'appconfiguration/{}'.format(VERSION))
5656
self._configure(**kwargs)
5757

@@ -69,7 +69,5 @@ def _configure(
6969
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
7070
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)
7171
self.authentication_policy = kwargs.get('authentication_policy')
72-
if not self.credential_scopes and not self.authentication_policy:
73-
raise ValueError("You must provide either credential_scopes or authentication_policy as kwargs")
7472
if self.credential and not self.authentication_policy:
7573
self.authentication_policy = policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)

sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/aio/_configuration.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(
4848
self.endpoint = endpoint
4949
self.sync_token = sync_token
5050
self.api_version = "1.0"
51-
self.credential_scopes = kwargs.pop('credential_scopes', [])
51+
self.credential_scopes = kwargs.pop('credential_scopes', ['https://dev.azuresynapse.net/.default'])
5252
kwargs.setdefault('sdk_moniker', 'appconfiguration/{}'.format(VERSION))
5353
self._configure(**kwargs)
5454

@@ -65,7 +65,5 @@ def _configure(
6565
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
6666
self.redirect_policy = kwargs.get('redirect_policy') or policies.AsyncRedirectPolicy(**kwargs)
6767
self.authentication_policy = kwargs.get('authentication_policy')
68-
if not self.credential_scopes and not self.authentication_policy:
69-
raise ValueError("You must provide either credential_scopes or authentication_policy as kwargs")
7068
if self.credential and not self.authentication_policy:
7169
self.authentication_policy = policies.AsyncBearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)

sdk/appconfiguration/azure-appconfiguration/swagger/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ enable-xml: true
1515
vanilla: true
1616
add-credentials: true
1717
credential-scopes: https://dev.azuresynapse.net/.default
18-
```
18+
```

0 commit comments

Comments
 (0)