Skip to content
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

{CI} Fix extension release scripts #7275

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2517e69
update
wangzelin007 Feb 7, 2024
bc3aed8
update
wangzelin007 Feb 7, 2024
f2b7bab
update
wangzelin007 Feb 7, 2024
87f519a
update
wangzelin007 Feb 7, 2024
8906e0b
update
wangzelin007 Feb 7, 2024
b6017d4
Update update_ext_cmd_tree.py
wangzelin007 Feb 7, 2024
2c3d7a3
Update update_ext_cmd_tree.py
wangzelin007 Feb 7, 2024
5de410e
update
wangzelin007 Feb 8, 2024
0c3bb06
Merge branch 'main' into release-scripts
wangzelin007 Feb 8, 2024
bfe5ed1
update
wangzelin007 Feb 8, 2024
8a844b7
Update sync_extensions.py
wangzelin007 Feb 8, 2024
29f00c6
Update util.py
wangzelin007 Feb 8, 2024
148eaf3
Merge branch 'main' into release-scripts
wangzelin007 Apr 8, 2024
e8c767a
Update util.py
wangzelin007 May 31, 2024
212f082
Update util.py
wangzelin007 May 31, 2024
08f3b0a
Create build_all_ext.sh
wangzelin007 May 31, 2024
bb4a4e2
Revert "Create build_all_ext.sh"
wangzelin007 Jun 3, 2024
218ca95
Update build_ext_cmd_tree.sh
wangzelin007 Oct 15, 2024
690b7ce
Update build_ext_cmd_tree.sh
wangzelin007 Oct 15, 2024
e8572a7
Update build_ext_cmd_tree.sh
wangzelin007 Oct 15, 2024
7447487
Update build_ext_cmd_tree.sh
wangzelin007 Oct 15, 2024
868a7b2
Update build_ext_cmd_tree.sh
wangzelin007 Oct 15, 2024
80a3c1c
Update build_ext_cmd_tree.sh
wangzelin007 Oct 16, 2024
6ac4465
Update build_ext_cmd_tree.sh
wangzelin007 Oct 17, 2024
9beaa14
Update build_ext_cmd_tree.sh
wangzelin007 Oct 17, 2024
8578db6
Merge branch 'main' into release-scripts
wangzelin007 Nov 18, 2024
ac63598
generate command tree for ml
wangzelin007 Dec 20, 2024
50d18b4
Merge branch 'main' into release-scripts
wangzelin007 Dec 20, 2024
6d0db41
Merge branch 'main' into release-scripts
wangzelin007 Dec 20, 2024
9c84141
generate command tree for ml
wangzelin007 Dec 23, 2024
eac3fb4
generate command tree for ml
wangzelin007 Dec 24, 2024
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
Prev Previous commit
Next Next commit
update
  • Loading branch information
wangzelin007 committed Feb 8, 2024
commit bfe5ed16adcada6ff4095cfa508a0480a0257dad
34 changes: 12 additions & 22 deletions scripts/ci/sync_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import json
import subprocess

from util import run_az_cmd

DEFAULT_TARGET_INDEX_URL = os.getenv('AZURE_EXTENSION_TARGET_INDEX_URL')
STORAGE_ACCOUNT = os.getenv('AZURE_EXTENSION_TARGET_STORAGE_ACCOUNT')
STORAGE_CONTAINER = os.getenv('AZURE_EXTENSION_TARGET_STORAGE_CONTAINER')
Expand Down Expand Up @@ -48,7 +50,6 @@ def download_file(url, file_path):
if chunk: # ignore keep-alive new chunks
f.write(chunk)


def _sync_wheel(ext, updated_indexes, failed_urls, overwrite, temp_dir):
download_url = ext['downloadUrl']
whl_file = download_url.split('/')[-1]
Expand All @@ -62,29 +63,22 @@ 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']
try:
result = subprocess.run(cmd, capture_output=True, check=True)
except subprocess.CalledProcessError as ex:
raise Exception(f"Failed to check if '{blob_name}' exists in the storage") from ex
message = f"Checking if '{blob_name}' exists in the storage"
result = run_az_cmd(cmd, message=message, raise_error=True)
if json.loads(result.stdout)['exists']:
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', '--overwrite']
try:
subprocess.run(cmd, capture_output=True, check=True)
except subprocess.CalledProcessError as ex:
raise Exception(f"Failed to upload '{blob_name}' to the storage") from ex
message = f"uploading '{blob_name}' to the storage"
run_az_cmd(cmd, message=message, raise_error=True)

cmd = ['az', 'storage', 'blob', 'url', '--container-name', f'{STORAGE_CONTAINER}', '--account-name',
f'{STORAGE_ACCOUNT}', '--name', f'{blob_name}', '--auth-mode', 'login']
try:
result = subprocess.run(cmd, capture_output=True, check=True)
url = json.loads(result.stdout)
except subprocess.CalledProcessError as ex:
raise Exception(f"Failed to get the URL for '{blob_name}'") from ex
message = f"Getting the URL for '{blob_name}'"
result = run_az_cmd(cmd, message=message, raise_error=True)

updated_index = ext
updated_index['downloadUrl'] = url
Expand Down Expand Up @@ -160,10 +154,8 @@ def main():
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', '--overwrite']
try:
subprocess.run(cmd, capture_output=True, check=True)
except subprocess.CalledProcessError as ex:
raise Exception(f"Failed to upload '{backup_index_name}' to the storage account") from ex
message = f"Uploading '{backup_index_name}' to the storage"
run_az_cmd(cmd, message=message, raise_error=True)

# start with an empty index.json to sync all extensions
initial_index = {"extensions": {}, "formatVersion": "1"}
Expand All @@ -189,10 +181,8 @@ def main():
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', '--overwrite']
try:
subprocess.run(cmd, capture_output=True, check=True)
except subprocess.CalledProcessError as ex:
raise Exception(f"Failed to upload '{index_name}' to the storage account") from ex
message = f"Uploading '{index_name}' to the storage"
run_az_cmd(cmd, message=message, raise_error=True)

print("\nSync finished.")
if updated_indexes:
Expand Down
17 changes: 7 additions & 10 deletions scripts/ci/update_ext_cmd_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import filecmp
import json
import os
import subprocess
import sys

from azure.cli.core import get_default_cli
from azure.cli.core._session import Session
from azure.cli.core.commands import _load_extension_command_loader
from azure.cli.core.extension import get_extension_modname, get_extension_path
from sync_extensions import download_file
from util import run_az_cmd

STORAGE_ACCOUNT = os.getenv('AZURE_EXTENSION_CMD_TREE_STORAGE_ACCOUNT')
STORAGE_CONTAINER = os.getenv('AZURE_EXTENSION_CMD_TREE_STORAGE_CONTAINER')
Expand Down Expand Up @@ -83,18 +84,14 @@ def upload_cmd_tree():
cmd = ['az', 'storage', 'blob', 'upload', '--container-name', f'{STORAGE_CONTAINER}', '--account-name',
f'{STORAGE_ACCOUNT}', '--name', f'{blob_file_name}', '--file', f'{file_path}', '--auth-mode', 'login',
'--overwrite']
try:
subprocess.run(cmd, capture_output=True, check=True)
except subprocess.CalledProcessError as ex:
raise Exception(f"Failed to upload '{blob_file_name}' to the storage account") from ex
message = f"Uploading '{blob_file_name}' to the storage"
run_az_cmd(cmd, message=message, raise_error=True)

cmd = ['az', 'storage', 'blob', 'url', '--container-name', f'{STORAGE_CONTAINER}', '--account-name',
f'{STORAGE_ACCOUNT}', '--name', f'{blob_file_name}', '--auth-mode', 'login']
try:
result = subprocess.run(cmd, capture_output=True, check=True)
url = json.loads(result.stdout)
except subprocess.CalledProcessError as ex:
raise Exception(f"Failed to get the URL for '{blob_file_name}'") from ex
message = f"Getting the URL for '{blob_file_name}'"
result = run_az_cmd(cmd, message=message, raise_error=True)
url = json.loads(result.stdout)

download_file_path = os.path.expanduser(os.path.join('~', '.azure', downloaded_file_name))
download_file(url, download_file_path)
Expand Down
29 changes: 24 additions & 5 deletions scripts/ci/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import json
import logging
import os
import re
import shlex
import json
import subprocess
import zipfile

from subprocess import check_output

logger = logging.getLogger(__name__)

# copy from wheel==0.30.0
Expand Down Expand Up @@ -136,7 +135,7 @@ def diff_code(start, end):

# If running in Travis CI, only run tests for edited extensions
commit_range = os.environ.get('TRAVIS_COMMIT_RANGE')
if commit_range and not check_output(
if commit_range and not subprocess.check_output(
['git', '--no-pager', 'diff', '--name-only', commit_range, '--', src_d_full]):
continue

Expand All @@ -154,7 +153,7 @@ def diff_code(start, end):
else:
cmd = cmd_tpl.format(start=start, end=end,
code_dir=src_d_full)
if not check_output(shlex.split(cmd)):
if not subprocess.check_output(shlex.split(cmd)):
continue

diff_ref.append((pkg_name, src_d_full))
Expand All @@ -163,3 +162,23 @@ def diff_code(start, end):
f'end: {end}, '
f'diff_ref: {diff_ref}.')
return diff_ref

def run_az_cmd(cmd, message=False, raise_error=True):
"""
:param cmd: The entire command line to run.
:param message: A custom message to print, or True (bool) to use a default.
:param raise_error: Whether to raise an exception if the command fails.
"""
# use default message if custom not provided
if message is True:
print(f'Running: {cmd}')

if message:
print(f'{message}')

try:
result = subprocess.run(cmd, capture_output=True, check=True)
except subprocess.CalledProcessError as ex:
if raise_error:
raise Exception(f"Failed to run command: {cmd}") from ex
return result