Skip to content

Commit

Permalink
[auto release] upload test proxy assets.json (Azure#31403)
Browse files Browse the repository at this point in the history
* upload recording files

* fix

* update

* update branch

* update

* update

* test

* update

* update

* update

* update

* update

* remove unused code

* update

---------

Co-authored-by: msyyc <[email protected]>
Co-authored-by: Yuchao Yan <[email protected]>
  • Loading branch information
3 people authored Aug 7, 2023
1 parent 3a6c7f4 commit e1683f5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 45 deletions.
8 changes: 4 additions & 4 deletions scripts/auto_release/PythonSdkLiveTest.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Live Test For Python SDK

name: $(BASE_BRANCH)
name: AUTO RELEASE

trigger:
branches:
Expand Down Expand Up @@ -36,7 +36,7 @@ jobs:
python scripts/dev_setup.py -p azure-core
cd ..
git config --global user.email "PythonSdkPipelines"
git config --global user.name "PythonSdkPipelines"
git config --global user.name "$(USR_NAME)"
# clone(REPO: https://github.com/Azure/azure-sdk-for-python.git, USR_NAME: Azure, USR_TOKEN: xxxxxxxxxxxxx)
mkdir azure-sdk-for-python
Expand Down Expand Up @@ -90,14 +90,14 @@ jobs:
export AZURE_CLIENT_SECRET=$(ENV-CLIENT-SECRET)
export AZURE_SUBSCRIPTION_ID=$(ENV-SUBSCRIPTION-ID)
export ISSUE_LINK=$(ISSUE_LINK)
export BASE_BRANCH=$(BASE_BRANCH)
export SCRIPT_PATH=$script_path
export AZURESDK_BOT_TOKEN=$(azuresdk-github-pat)
export GIT_TOKEN=$(azuresdk-github-pat)
export STORAGE_CONN_STR=$(storage-conn-str)
export STORAGE_ENDPOINT=$(storage-endpoint)
export PYTHON_TAG=$(PYTHON_TAG)
export DEBUG_SDK_BRANCH=$(DEBUG_SDK_BRANCH)
export TARGET_DATE=$(TARGET_DATE)
export TEST_FOLDER=$(TEST_FOLDER)
# run
cd azure-sdk-for-python
Expand Down
76 changes: 35 additions & 41 deletions scripts/auto_release/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,25 @@ class CodegenTestPR:
def __init__(self):
self.issue_link = os.getenv('ISSUE_LINK', '')
self.pipeline_link = os.getenv('PIPELINE_LINK', '')
self.bot_token = os.getenv('AZURESDK_BOT_TOKEN')
self.bot_token = os.getenv('GIT_TOKEN')
self.spec_readme = os.getenv('SPEC_README', '')
self.spec_repo = os.getenv('SPEC_REPO', '')
self.conn_str = os.getenv('STORAGE_CONN_STR')
self.storage_endpoint = os.getenv('STORAGE_ENDPOINT').strip('/')
self.target_date = os.getenv('TARGET_DATE', '')
self.test_folder = os.getenv('TEST_FOLDER', '')

self.package_name = ''
self.package_name = '' # 'dns' of 'sdk/compute/azure-mgmt-dns'
self.new_branch = ''
self.sdk_folder = '' # 'compute' in 'sdk/compute/azure-mgmt-dns'
self.sdk_folder = '' # 'compute' of 'sdk/compute/azure-mgmt-dns'
self.autorest_result = ''
self.next_version = ''
self.test_result = ''
self.pr_number = 0
self.container_name = ''
self.private_package_link = [] # List[str]
self.tag_is_stable = False
self.has_test = False
self.check_package_size_result = [] # List[str]

@property
Expand Down Expand Up @@ -221,40 +223,10 @@ def prepare_branch_with_readme(self):
self.get_sdk_folder_with_autorest_result()
self.create_new_branch()

def get_package_name_with_branch(self) -> (str, str):
origin_base_branch = os.getenv('BASE_BRANCH')
# e.g. AzureSDKAutomation:sdkAuto/track2_azure-mgmt-network or azclibot:t2-network-2022-01-05-26928
branch_info = origin_base_branch.split(':')
split_str = 'azure-mgmt-'
if 'azure-mgmt-' in branch_info[1]:
self.package_name = branch_info[1].split(split_str)[-1]
else:
self.package_name = branch_info[1].split('-')[1]

return branch_info[0], branch_info[1]

def create_new_branch(self):
self.new_branch = f't2-{self.package_name}-{current_time()}-{str(time.time())[-5:]}'
print_check(f'git checkout -b {self.new_branch}')

def create_branch_with_base_branch(self, github_usr: str, base_branch: str):
# checkout base branch
print_exec(f'git remote add {github_usr} https://github.com/{github_usr}/azure-sdk-for-python.git')
print_check(f'git fetch {github_usr} {base_branch}')
print_check(f'git checkout {github_usr}/{base_branch}')

# create new branch
self.create_new_branch()

def prepare_branch_with_base_branch(self):
github_usr, base_branch = self.get_package_name_with_branch()
self.create_branch_with_base_branch(github_usr, base_branch)
self.get_sdk_folder_with_package_name()

def get_sdk_folder_with_package_name(self):
folder_info = glob(f'sdk/*/azure-mgmt-{self.package_name}')[0]
self.sdk_folder = Path(folder_info).parts[1]

def check_sdk_readme(self):
sdk_readme = str(Path(f'sdk/{self.sdk_folder}/azure-mgmt-{self.package_name}/README.md'))

Expand Down Expand Up @@ -453,12 +425,16 @@ def install_package_locally(self):
def prepare_test_env(self):
self.install_package_locally()
set_test_env_var()

@staticmethod
def is_live_test()-> bool:
return str(os.getenv("AZURE_TEST_RUN_LIVE")).lower() == "true"

@return_origin_path
def run_test_proc(self):
# run test
os.chdir(self.sdk_code_path())
test_mode = "Live test" if os.getenv("AZURE_TEST_RUN_LIVE") else "Recording test"
test_mode = "Live test" if self.is_live_test() else "Recording test"
succeeded_result = f'{test_mode} success'
failed_result = f'{test_mode} fail, detailed info is in pipeline log(search keyword FAILED)!!!'
try:
Expand All @@ -476,18 +452,26 @@ def run_test_proc(self):
else:
log(f'{test_mode} run done, do not find failure !!!')
self.test_result = succeeded_result

self.has_test = True

@staticmethod
def clean_test_env():
for item in ("SSL_CERT_DIR", "REQUESTS_CA_BUNDLE"):
if os.getenv(item):
os.environ.pop(item)

@return_origin_path
def upload_recording_files(self):
if self.is_live_test() and self.has_test:
os.chdir(self.sdk_code_path())
print_exec("python ../../../scripts/manage_recordings.py push")

def run_test(self):
self.prepare_test_env()
self.run_test_proc()
self.clean_test_env()

self.upload_recording_files()

def create_pr_proc(self):
api = GhApi(owner='Azure', repo='azure-sdk-for-python', token=self.bot_token)
Expand Down Expand Up @@ -589,12 +573,16 @@ def issue_comment(self):
self.zero_version_policy()
self.ask_check_policy()

def create_pr(self):
# commit all code
@staticmethod
def commit_code():
print_exec('git add sdk/')
print_exec('git commit -m \"code and test\"')
print_check('git push origin HEAD -f')

def create_pr(self):
# commit all code
self.commit_code()

# create PR
self.create_pr_proc()

Expand All @@ -607,12 +595,18 @@ def run(self):
self.check_file()
self.run_test()
self.create_pr()
else:
self.sdk_folder = self.spec_readme.split('/')[0]
self.package_name = self.spec_readme.split('/')[-1].split('-')[-1]
self.checkout_branch("DEBUG_SDK_BRANCH", "azure-sdk-for-python")
elif self.test_folder:
self.sdk_folder = self.test_folder.split('/')[0]
self.package_name = self.test_folder.split('/')[-1].split('-')[-1]
env_var = os.getenv("DEBUG_SDK_BRANCH", "")
branch = env_var.split(":")[-1]

print_check(f'git checkout {branch}')
self.run_test()

# commit all code
self.commit_code()


if __name__ == '__main__':
main_logger = logging.getLogger()
Expand Down

0 comments on commit e1683f5

Please sign in to comment.