-
Notifications
You must be signed in to change notification settings - Fork 1.5k
{CI} Merge CLI extension release scripts from release-scripts branch to main branch #7273
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
Changes from all commits
2517e69
bc3aed8
f2b7bab
87f519a
8906e0b
b6017d4
2c3d7a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,20 +62,27 @@ def _sync_wheel(ext, updated_indexes, failed_urls, overwrite, temp_dir): | |
| if not overwrite: | ||
| cmd = ['az', 'storage', 'blob', 'exists', '--container-name', f'{STORAGE_CONTAINER}', '--account-name', | ||
| f'{STORAGE_ACCOUNT}', '--name', f'{blob_name}', '--auth-mode', 'login'] | ||
| result = subprocess.run(cmd, check=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per https://docs.python.org/3/library/subprocess.html#subprocess.run,
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I use result = subprocess.run(cmd, check=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT),
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can reproduce on Linux: import subprocess
result = subprocess.run(['az', 'account', 'show'], check=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print(result)
https://docs.python.org/3/library/subprocess.html#popen-constructor
So
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if json.loads(result.stdout)['exists']: | ||
| result = subprocess.run(cmd, capture_output=True) | ||
| if result.stdout and json.loads(result.stdout)['exists']: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
| print("Skipping '{}' as it already exists...".format(whl_file)) | ||
| return | ||
|
|
||
| cmd = ['az', 'storage', 'blob', 'upload', '--container-name', f'{STORAGE_CONTAINER}', '--account-name', | ||
| f'{STORAGE_ACCOUNT}', '--name', f'{blob_name}', '--file', f'{os.path.abspath(whl_path)}', | ||
| '--auth-mode', 'login'] | ||
| result = subprocess.run(cmd, check=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
| print(json.loads(result.stdout)) | ||
| '--auth-mode', 'login', '--overwrite'] | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add --overwrite to support Idempotent operations. |
||
| result = subprocess.run(cmd, capture_output=True) | ||
| if result.returncode != 0: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can leverage https://docs.python.org/3/library/subprocess.html#subprocess.run
|
||
| print(f"Failed to upload '{whl_file}' to the storage account") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The raise does not contain whl_file related information, so I added this line to print |
||
| raise | ||
|
Comment on lines
+75
to
+76
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider raising the error message as an raise Exception(f"Failed to upload '{whl_file}' to the storage account") |
||
| cmd = ['az', 'storage', 'blob', 'url', '--container-name', f'{STORAGE_CONTAINER}', '--account-name', | ||
| f'{STORAGE_ACCOUNT}', '--name', f'{blob_name}', '--auth-mode', 'login'] | ||
| result = subprocess.run(cmd, check=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
| url = json.loads(result.stdout) | ||
| result = subprocess.run(cmd, capture_output=True) | ||
| print(result) | ||
| if result.stdout and result.returncode == 0: | ||
| url = json.loads(result.stdout) | ||
| else: | ||
| print("Failed to get the URL for '{}'".format(whl_file)) | ||
| raise | ||
| updated_index = ext | ||
| updated_index['downloadUrl'] = url | ||
| updated_indexes.append(updated_index) | ||
|
|
@@ -148,9 +155,12 @@ def main(): | |
| # backup the old index.json | ||
| backup_index_name = f'{BLOB_PREFIX}/index.json.sav' if BLOB_PREFIX else 'index.json.sav' | ||
| cmd = ['az', 'storage', 'blob', 'upload', '--container-name', f'{STORAGE_CONTAINER}', '--account-name', | ||
| f'{STORAGE_ACCOUNT}', '--name', f'{backup_index_name}', '--file', f'{os.path.abspath(target_index_path)}', '--auth-mode', 'login'] | ||
| result = subprocess.run(cmd, check=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
| print(json.loads(result.stdout)) | ||
| f'{STORAGE_ACCOUNT}', '--name', f'{backup_index_name}', | ||
| '--file', f'{os.path.abspath(target_index_path)}', '--auth-mode', 'login', '--overwrite'] | ||
| result = subprocess.run(cmd, capture_output=True) | ||
| if result.returncode != 0: | ||
| print(f"Failed to upload '{target_index_path}' to the storage account") | ||
| raise | ||
| # start with an empty index.json to sync all extensions | ||
| initial_index = {"extensions": {}, "formatVersion": "1"} | ||
| open(target_index_path, 'w').write(json.dumps(initial_index, indent=4, sort_keys=True)) | ||
|
|
@@ -174,9 +184,11 @@ def main(): | |
| index_name = f'{BLOB_PREFIX}/index.json' if BLOB_PREFIX else 'index.json' | ||
| cmd = ['az', 'storage', 'blob', 'upload', '--container-name', f'{STORAGE_CONTAINER}', '--account-name', | ||
| f'{STORAGE_ACCOUNT}', '--name', f'{index_name}', '--file', f'{os.path.abspath(target_index_path)}', | ||
| '--auth-mode', 'login'] | ||
| result = subprocess.run(cmd, check=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
| print(json.loads(result.stdout)) | ||
| '--auth-mode', 'login', '--overwrite'] | ||
| result = subprocess.run(cmd, capture_output=True) | ||
| if result.returncode != 0: | ||
| print(f"Failed to upload '{target_index_path}' to the storage account") | ||
| raise | ||
| print("\nSync finished.") | ||
| if updated_indexes: | ||
| print("New extensions available in:") | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I use result = subprocess.run(cmd, check=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT),

The output of result.stdout is like this::
https://dev.azure.com/azclitools/internal/_build/results?buildId=128429&view=logs&j=275f1d19-1bd8-5591-b06b-07d489ea915a&t=3178dee2-26ab-587a-4407-0f5d5c54e1f3&l=82