Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion eng/pipelines/templates/steps/verify-autorest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ steps:
- template: /eng/common/pipelines/templates/steps/create-pull-request.yml
parameters:
CommitMsg: "Regenerated code from nightly builds"
PRTitle: "Automated autorest generation"
PRTitle: "Automated autorest generation for ${{ parameters.ServiceDirectory }}"
PRBranchName: 'autorest-${{ parameters.ServiceDirectory }}'
40 changes: 33 additions & 7 deletions scripts/devops_tasks/verify_autorest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
# --------------------------------------------------------------------------------------------

import argparse
import os
import logging
import sys
import json
import os
import requests

from common_tasks import run_check_call

Expand Down Expand Up @@ -54,7 +55,31 @@ def find_swagger_folders(directory):
return ret


def check_diff(folder):
def check_for_open_pr(service_directory):
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need to do this if your branch name is consistent. As the create-pull-request template will not create an additional PR against a given branch if one already exists. That is how we generally handle this case in other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is great to know, I can close this PR entirely then

# Return True if there is an OPEN PR of the format ""Automated autorest generation for {service_directory}""
# Return False otherwise

pr_title = "Automated autorest generation for {}".format(service_directory)

page_size = 50
page_number = 1
request_url = "https://api.github.com/repos/Azure/azure-sdk-for-python/pulls?state=open&per_page={}&page={}"

s = requests.session()
response = s.get(request_url.format(page_size, page_number))
while "next" in response.links:
body = response.content.decode("utf-8")
body = json.loads(body)
for link in body:
if link["title"] == pr_title:
return True

next_page = response.links["next"]["url"]
response = s.get(next_page)
return False


def check_diff(folder, service_dir):
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The git diff is for users to be able to inspect which files are different in the pipeline on a failure.

Copy link
Member

Choose a reason for hiding this comment

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

OK if that is interesting for other cases that is fine. However I'd encourage you to do those type of command line calls inline script blocks in the yml file, unless you feel folks would want to run them locally as well.

This is perhaps my preference for using a shell scripting language (script/bash/pwsh) when running command line tools as opposed to wrapping them in process calls in a higher level language like python. Just something to keep in mind not something that is necessarily actionable. :)

# We don't care about changes to txt files (dev_requirements change)
run_check_call(["git", "status"], sdk_dir, always_exit=False)

Expand Down Expand Up @@ -87,9 +112,10 @@ def check_diff(folder):
if result:
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 not check_for_open_pr(service_dir):
raise ValueError(
"Found difference between re-generated code and current commit. Please re-generate with the latest autorest."
)


if __name__ == "__main__":
Expand All @@ -105,4 +131,4 @@ def check_diff(folder):

if len(folders):
for folder in folders:
check_diff(folder)
check_diff(folder, args.service_directory)