Skip to content

Commit

Permalink
Packaging on Jenkins (#3263)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmazuel authored Sep 4, 2018
1 parent 8b6155f commit e57d6af
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
26 changes: 24 additions & 2 deletions azure-sdk-tools/packaging_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import os
from pathlib import Path
from typing import Dict, Any
from typing import Dict, Any, Optional, List

from jinja2 import Template, PackageLoader, Environment
from .conf import read_conf, build_default_conf, CONF_NAME
Expand Down Expand Up @@ -29,7 +30,28 @@ def build_config(config : Dict[str, Any]) -> Dict[str, str]:
# Return result
return result

def build_packaging(package_name: str, output_folder: str, build_conf: bool = False) -> None:

def build_packaging(output_folder: str, gh_token: Optional[str]=None, jenkins: bool = False, packages: List[str]=None, build_conf: bool = False) -> None:
package_names = set(packages) or set()
if jenkins:
sdk_id = os.environ["ghprbGhRepository"]
pr_number = int(os.environ["ghprbPullId"])

from github import Github
con = Github(gh_token)
repo = con.get_repo(sdk_id)
sdk_pr = repo.get_pull(pr_number)
# "get_files" of Github only download the first 300 files. Might not be enough.
package_names |= {f.filename.split('/')[0] for f in sdk_pr.get_files() if f.filename.startswith("azure")}

if not package_names:
raise ValueError("Was unable to find out the package names.")

for package_name in package_names:
build_packaging_by_package_name(package_name, output_folder, build_conf)


def build_packaging_by_package_name(package_name: str, output_folder: str, build_conf: bool = False) -> None:
_LOGGER.info("Building template %s", package_name)
package_folder = Path(output_folder) / Path(package_name)

Expand Down
17 changes: 15 additions & 2 deletions azure-sdk-tools/packaging_tools/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import logging
import os
import sys

from . import build_packaging
Expand All @@ -23,16 +24,28 @@
parser.add_argument("--build-conf",
dest="build_conf", action="store_true",
help="Build a default TOML file, with package name, fake pretty name, as beta package and no doc page. Do nothing if the file exists, remove manually the file if needed.")
parser.add_argument('package_name', help='The package name.')
parser.add_argument("--jenkins",
dest="jenkins", action="store_true",
help="In Jenkins mode, try to find what to generate from Jenkins env variables. Package names are then optional.")
parser.add_argument('package_names', nargs='*', help='The package name.')

args = parser.parse_args()

main_logger = logging.getLogger()
logging.basicConfig()
main_logger.setLevel(logging.DEBUG if args.debug else logging.INFO)

if not args.package_names and not args.jenkins:
raise ValueError("At least one package name or Jenkins mode is required")

try:
build_packaging(args.package_name, args.output, build_conf=args.build_conf)
build_packaging(
args.output,
os.environ.get("GH_TOKEN", None),
args.jenkins,
args.package_names,
build_conf=args.build_conf
)
except Exception as err:
if args.debug:
_LOGGER.exception(err)
Expand Down

0 comments on commit e57d6af

Please sign in to comment.