Skip to content
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
fbc3261
added pipeline stage to verify autorest
seankane-msft Feb 10, 2021
03dcdf4
syntax issue
seankane-msft Feb 10, 2021
31b4333
correcting node install
seankane-msft Feb 10, 2021
7fee4f7
adding python script, installing autorest.python
seankane-msft Feb 10, 2021
791b909
adding swagger file for appconfig
seankane-msft Mar 10, 2021
d1d8cf9
created scripts to automatically run autorest and verify, failing on …
seankane-msft Mar 10, 2021
bbffe46
fixing autorest yml file
seankane-msft Mar 10, 2021
8a6a96d
changing the order of ops so readme failure is later
seankane-msft Mar 10, 2021
8f9f913
changing node install
seankane-msft Mar 10, 2021
1b81463
fixed my node install
seankane-msft Mar 10, 2021
25dea73
adding GitPython package
seankane-msft Mar 10, 2021
60e3869
more fixes
seankane-msft Mar 10, 2021
98f8f5c
fixing aiohttp req:
seankane-msft Mar 10, 2021
52d9b22
adding a python 3.9 req
seankane-msft Mar 10, 2021
9519a2d
adding a step to remove autorest.python
seankane-msft Mar 10, 2021
5592a03
had leftovers from a copy
seankane-msft Mar 10, 2021
1a2fd97
cleaning up script, always run clear of autorest python
seankane-msft Mar 10, 2021
019d2d8
fixing removal
seankane-msft Mar 11, 2021
3be480a
adding step to delete autorest.python folder
seankane-msft Mar 11, 2021
9c99288
trying to figure out why it wont delete autorest afterwards
seankane-msft Mar 11, 2021
422591b
reverting back
seankane-msft Mar 11, 2021
1a41e66
moving autorest to the back of the order
seankane-msft Mar 11, 2021
ba004bc
moving the autorest to the analyze yml file
seankane-msft Mar 11, 2021
9214c10
changing params to the format of archetype-sdk-client.yml
seankane-msft Mar 11, 2021
04ab76c
merge conflicts
seankane-msft Mar 11, 2021
1f67ec5
adding a section for swagger files, added appconfig to this list
seankane-msft Mar 11, 2021
158457d
adding a line to run git diff only when running autorest
seankane-msft Mar 11, 2021
68b818e
making it a verbose for more error reporting
seankane-msft Mar 11, 2021
f7a200c
setting storage and appconfig to false
seankane-msft Apr 7, 2021
51c07ed
undoing changes
seankane-msft Apr 7, 2021
b546a87
undoing appconfig
seankane-msft Apr 7, 2021
83168da
do not verify for container registry
seankane-msft Apr 7, 2021
13f7327
merge conflicts
seankane-msft Apr 14, 2021
f39d4af
fixes suggested from scott
seankane-msft Apr 14, 2021
7046828
removing install pip line
seankane-msft Apr 14, 2021
b79fe26
adding VerifyAutorest param
seankane-msft Apr 14, 2021
235c363
making verify a boolean and deciding in verify-autorest.yml file
seankane-msft Apr 14, 2021
26ca1e8
error from copy paste
seankane-msft Apr 14, 2021
fc6c93d
sparse checkout of autorest
seankane-msft Apr 15, 2021
b3b7e06
adding a step to create a PR
seankane-msft Apr 15, 2021
fd3dee0
removed failed condition
seankane-msft Apr 15, 2021
031c32c
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-pytho…
seankane-msft Apr 15, 2021
7bf5442
fixing syntax issues
seankane-msft Apr 15, 2021
af59dd2
passing through verify autorest
seankane-msft Apr 15, 2021
4c63c1c
turning autorest automation into opt-in, starting with appconfig
seankane-msft Apr 15, 2021
7f79740
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-pytho…
seankane-msft Apr 16, 2021
0226f0e
regen appconfig to avoid failures, merge upstream/master
seankane-msft Apr 16, 2021
2ec2b9e
fixing a default
seankane-msft Apr 16, 2021
efd3be9
adding change to look for changes in only directory autorest ran in
seankane-msft Apr 16, 2021
6c49c4c
adding directory, autorest doesnt work from inside python locally
seankane-msft Apr 16, 2021
df8676a
using a git command instead of GitPython
seankane-msft Apr 16, 2021
eeb61e7
adding steps to remove things that don't need to be included in PR
seankane-msft Apr 16, 2021
075f040
adding a debug step
seankane-msft Apr 16, 2021
0b23815
removing unnecessary VerifyAutorest: false
seankane-msft Apr 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions eng/.docsettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,15 @@ known_content_issues:
- ['sdk/eventgrid/azure-eventgrid/README.md', '#4554']
- ['sdk/graphrbac/azure-graphrbac/README.md', '#4554']
- ['sdk/loganalytics/azure-loganalytics/README.md', '#4554']
- ['sdk/schemaregistry/azure-schemaregistry/swagger/README.md', '#4554']
- ['sdk/servicebus/azure-servicebus/README.md', '#4554']
- ['sdk/servicebus/azure-servicebus/swagger/README.md', '#4554']
- ['sdk/servicebus/azure-servicebus/tests/perf_tests/README.md', '#4554']
- ['sdk/servicefabric/azure-servicefabric/README.md', '#4554']
- ['sdk/storage/azure-storage-nspkg/README.md', '#4554']
- ['sdk/storage/azure-storage-blob/swagger/README.md', '#4554']
- ['sdk/storage/azure-storage-file-datalake/swagger/README.md', '#4554']
- ['sdk/storage/azure-storage-file-share/swagger/README.md', '#4554']
- ['sdk/storage/azure-storage/README.md', '#4554']
- ['sdk/storage/azure-storage-nspkg/README.rst', '#4554']
- ['sdk/storage/azure-storage-queue/swagger/README.md', '#4554']
- ['sdk/storage/README.md', '#4554']
- ['sdk/textanalytics/azure-ai-textanalytics/samples/README.md', '#4554']
- ['sdk/monitor/azure-monitor-opentelemetry-exporter/swagger/README.md', '#4554']
- ['sdk/monitor/azure-monitor-opentelemetry-exporter/README.md', '#4554']
- ['sdk/digitaltwins/azure-digitaltwins-core/swagger/README.md', '#4554']
- ['sdk/textanalytics/azure-ai-textanalytics/swagger/README.md', '#4554']
- ['sdk/media/azure-media-nspkg/README.md', '#4554']
- ['sdk/containerregistry/azure-containerregistry/swagger/README.md', '#4554']
- ['sdk/appconfiguration/azure-appconfiguration/swagger/README.md', '#4554']
Expand Down Expand Up @@ -155,6 +146,18 @@ known_content_issues:
- ['doc/dev/mgmt/README.md', 'dev readme']
- ['doc/dev/README.md', dev readme']
- ['doc/README.md', 'dev readme']

# swagger files
- ['sdk/schemaregistry/azure-schemaregistry/swagger/README.md', '#4554']
- ['sdk/servicebus/azure-servicebus/swagger/README.md', '#4554']
- ['sdk/storage/azure-storage-blob/swagger/README.md', '#4554']
- ['sdk/storage/azure-storage-file-datalake/swagger/README.md', '#4554']
- ['sdk/storage/azure-storage-file-share/swagger/README.md', '#4554']
- ['sdk/storage/azure-storage-queue/swagger/README.md', '#4554']
- ['sdk/monitor/azure-monitor-opentelemetry-exporter/swagger/README.md', '#4554']
- ['sdk/digitaltwins/azure-digitaltwins-core/swagger/README.md', '#4554']
- ['sdk/textanalytics/azure-ai-textanalytics/swagger/README.md', '#4554']
- ['sdk/appconfiguration/azure-appconfiguration/swagger/README.md', '#4554']
package_indexing_exclusion_list:
- 'azure-sdk-tools'
- 'azure-template'
5 changes: 3 additions & 2 deletions eng/autorest_req.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ pytest-cov==2.8.1
pytest-asyncio==0.12.0; python_version >= '3.5'
isodate==0.6.0
msrest==0.6.14
aiohttp==3.6.2
wheel==0.34.2
wheel==0.34.2
GitPython==3.1.14
aiohttp==3.6.2; python_version >= '3.6'
6 changes: 6 additions & 0 deletions eng/pipelines/templates/steps/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ parameters:
AdditionalTestArgs: ''
Artifacts: []
TestPipeline: false
VerifyAutorest: true

steps:
- template: /eng/pipelines/templates/steps/analyze_dependency.yml
Expand Down Expand Up @@ -112,6 +113,11 @@ steps:
TestMarkArgument: ${{ parameters.TestMarkArgument }}
AdditionalTestArgs: ${{parameters.AdditionalTestArgs}}

- ${{if eq(parameters.VerifyAutorest, 'true')}}:
- template: ../steps/verify-autorest.yml
parameters:
ServiceDirectory: ${{ parameters.ServiceDirectory }}

- template: /eng/common/pipelines/templates/steps/create-apireview.yml
parameters:
Artifacts: ${{ parameters.Artifacts }}
Expand Down
48 changes: 48 additions & 0 deletions eng/pipelines/templates/steps/verify-autorest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
parameters:
- name: ServiceToTest
type: string
default: ''
- name: SDKType
type: string
default: 'client'
- name: ServiceDirectory
type: string
- name: NodeVersion
type: string
default: '12.x'
- name: PythonVersion
type: string
default: '$(PythonVersion)'
- name: auto_rest_clone_url
type: string
default: 'https://github.com/Azure/autorest.python.git'

steps:
- task: UsePythonVersion@0
displayName: Use
inputs:
versionSpec: ${{ parameters.PythonVersion }}

- task: NodeTool@0
inputs:
versionSpec: ${{ parameters.NodeVersion }}

- script: |
npm install -g autorest
autorest --help
displayName: "Install autorest"

- script: |
python --version
pip install -r eng/autorest_req.txt
git clone ${{ parameters.auto_rest_clone_url }}

@scbedd scbedd Apr 14, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit, as I don't believe autorest repo is that big. but can we use a sparse checkout?

  - template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
    parameters:
      Paths:
        - "/*"
      Repositories:
        - Name: "Azure/autorest.python"
          Commitish: "master"
          WorkingDirectory: "$(Build.SourcesDirectory)/autorest.python"
      SkipDefaultCheckout: true

I'm like 99% certain this will work. This will basically grab zero history for the commitsh you ask for. I'm adding path "/" to tell it to grab every file in the repo.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm testing this locally to confirm that it's good advice. Feel free to ignore this comment for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok I tested this locally.

This will not work for what I'm asking you to do until I update the sparse-checkout.yml to NOT grab the folder eng by default. It would work if the pattern was simply:

        git clone --no-checkout --filter=tree:0 git://github.com/Azure/autorest.python .
        git sparse-checkout init
        git sparse-checkout add /
        git checkout <targetcommit> (master in your case)

But because by default it has a

       git sparse-checkout set eng

Run before it adds the path, it actually won't work for git repos without an eng folder. It just quietly doesn't checkout properly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@scbedd I would set the path to /* instead of / which will work with eng. This is what git sparse-checkout defaults to using anyway before we run git sparse-checkout set

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah ok. I'll definitely give it a shot locally.

@scbedd scbedd Apr 14, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@seankane-msft this works. I updated the example above. I believe it should be a drop in replacement.

cd autorest.python
npm install
displayName: 'Prepare Environment'

- task: PythonScript@0
displayName: 'Run autorest Python'
inputs:
scriptPath: 'scripts/devops_tasks/verify_autorest.py'
arguments: >-
--service_directory="${{ parameters.ServiceDirectory }}"
82 changes: 82 additions & 0 deletions scripts/devops_tasks/verify_autorest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env python

# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import argparse
from git import Repo
import os
import logging
import sys

from common_tasks import run_check_call

logging.getLogger().setLevel(logging.INFO)

root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", ".."))
sdk_dir = os.path.join(root_dir, "sdk")

SWAGGER_FOLDER = "swagger"


def run_autorest(service_dir):
logging.info("Running autorest for {}".format(service_dir))

service_dir = os.path.join(sdk_dir, service_dir)

swagger_folders = find_swagger_folders(service_dir)

for working_dir in swagger_folders:
os.chdir(working_dir)
f = os.path.join(working_dir, "README.md")
if os.path.exists(f):
reset_command = ["autorest", "--reset"]
run_check_call(reset_command, root_dir)

command = ["autorest", "--python", f, "--verbose"]
logging.info("Command: {}\nLocation: {}\n".format(command, working_dir))
run_check_call(command, working_dir)
return swagger_folders


def find_swagger_folders(directory):
logging.info("Searching for swagger files in: {}".format(directory))

ret = []
for root, subdirs, files in os.walk(directory):
for d in subdirs:
if d == SWAGGER_FOLDER:
if os.path.exists(os.path.join(root, d, "README.md")):
ret.append(os.path.join(root, d))

logging.info("Found swagger files at: {}".format(ret))
return ret


def check_diff():
repo = Repo(root_dir)
t = repo.head.commit.tree
d = repo.git.diff(t)
if d:
command = ["git", "status"]
run_check_call(command, root_dir)
raise ValueError(
"Found difference between re-generated code and current commit. Please re-generate with the latest autorest."
)


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Run autorest to verify generated code."
)
parser.add_argument(
"--service_directory", help="Directory of the package being tested"
)

args = parser.parse_args()
folders = run_autorest(args.service_directory)

if len(folders):
check_diff()
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ enable-xml: true
vanilla: true
add-credentials: true
credential-scopes: https://dev.azuresynapse.net/.default
```
```
1 change: 1 addition & 0 deletions sdk/appconfiguration/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ extends:
safeName: azureappconfiguration
- name: azure-mgmt-appconfiguration
safeName: azuremgmtappconfiguration
VerifyAutorest: false
3 changes: 2 additions & 1 deletion sdk/containerregistry/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ extends:
- name: azure-mgmt-containerregistry
safeName: azuremgmtcontainerregistry
- name: azure-containerregistry
safeName: azurecontainerregistry
safeName: azurecontainerregistry
VerifyAutorest: false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In these the udpated ci.yml, VerifyAutorest is set to false. Are these ones that you KNOW will have issues, so you're kinda pushing it off? That's totally fine, but what about the rest of the repo? Have you run VerifyAutorest against all the service directories?

Trying to get a feel for the impact if we check this in.

Also, have you let the mgmt folks know about this new check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I know this will cause issues with containerregistry and storage from testing it on both. I will reach out to the storage team to see if they want me to default it on. I have not let mgmt team know about it, but will reach out.

1 change: 1 addition & 0 deletions sdk/storage/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ extends:
safeName: azuremgmtstoragesync
- name: azure-mgmt-storageimportexport
safeName: azuremgmtstorageimportexport
VerifyAutorest: false
CondaArtifacts:
- name: azure-storage
meta_source: meta.yaml
Expand Down