This commit is contained in:
Laurent Mazuel 2018-02-26 10:04:58 -08:00 коммит произвёл Laurent Mazuel
Родитель 050932f308
Коммит 94e560903f
4 изменённых файлов: 105 добавлений и 1 удалений

Просмотреть файл

@ -33,7 +33,8 @@ setup(
},
entry_points = {
'console_scripts': [
'generate_sdk=swaggertosdk.generate_sdk:generate_main'
'generate_sdk=swaggertosdk.generate_sdk:generate_main',
'generate_package=swaggertosdk.generate_package:generate_main',
],
}
)

Просмотреть файл

@ -0,0 +1,46 @@
import argparse
import logging
import os
from swaggertosdk.python_sdk_tools import build_package_from_pr_number
_LOGGER = logging.getLogger(__name__)
def generate_main():
"""Main method"""
parser = argparse.ArgumentParser(
description='Build package.',
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--pr-number', '-p',
dest='pr_number', type=int, required=True,
help='PR number')
parser.add_argument('--repo', '-r',
dest='repo_id', default="Azure/azure-sdk-for-python",
help='Repo id. [default: %(default)s]')
parser.add_argument("-v", "--verbose",
dest="verbose", action="store_true",
help="Verbosity in INFO mode")
parser.add_argument("--debug",
dest="debug", action="store_true",
help="Verbosity in DEBUG mode")
parser.add_argument('--output-folder', '-o',
dest='output_folder', default='.',
help='Output folder for package. [default: %(default)s]')
args = parser.parse_args()
main_logger = logging.getLogger()
if args.verbose or args.debug:
logging.basicConfig()
main_logger.setLevel(logging.DEBUG if args.debug else logging.INFO)
build_package_from_pr_number(
os.environ["GH_TOKEN"],
args.repo_id,
args.pr_number,
args.output_folder
)
if __name__ == "__main__":
generate_main()

Просмотреть файл

@ -0,0 +1,32 @@
"""This file is specific to Azure SDK for Python and should be split somewhere else."""
import logging
from pathlib import Path
import tempfile
from github import Github
from .github_tools import manage_git_folder
from .autorest_tools import execute_simple_command
_LOGGER = logging.getLogger(__name__)
def build_package_from_pr_number(gh_token, sdk_id, pr_number, output_folder):
"""Will clone the given PR branch and vuild the package with the given name."""
con = Github(gh_token)
repo = con.get_repo(sdk_id)
sdk_pr = repo.get_pull(pr_number)
package_names = {f.filename.split('/')[0] for f in sdk_pr.get_files() if f.filename.startswith("azure")}
absolute_output_folder = str(Path(output_folder).resolve())
with tempfile.TemporaryDirectory() as temp_dir, \
manage_git_folder(gh_token, Path(temp_dir) / Path("sdk"), sdk_id, pr_number=pr_number) as sdk_folder:
for package_name in package_names:
_LOGGER.debug("Build {}".format(package_name))
execute_simple_command(
["python", "./build_package.py", "--dest", absolute_output_folder, package_name],
cwd=sdk_folder
)
_LOGGER.debug("Build finished: {}".format(package_name))

Просмотреть файл

@ -0,0 +1,25 @@
from pathlib import Path
from subprocess import CalledProcessError
import tempfile
import pytest
from swaggertosdk.python_sdk_tools import build_package_from_pr_number
def test_build_package_from_pr_number(github_token):
# Should build package azure-mgmt-advisor 1.0.1
with tempfile.TemporaryDirectory() as temp_dir:
build_package_from_pr_number(github_token, "Azure/azure-sdk-for-python", 1974, temp_dir)
temp_dir_path = Path(temp_dir)
files = set(file.relative_to(temp_dir) for file in temp_dir_path.iterdir())
assert files == {
Path("azure_mgmt_advisor-1.0.1-py2.py3-none-any.whl"),
Path("azure-mgmt-advisor-1.0.1.zip")
}
# This PR is broken and can't be built: 2040
with tempfile.TemporaryDirectory() as temp_dir, pytest.raises(CalledProcessError):
build_package_from_pr_number(github_token, "Azure/azure-sdk-for-python", 2040, temp_dir)