Skip to content

Commit 99ff573

Browse files
author
Nicolas Kraiouchkine
committed
Add support for additional files and certificates
1 parent 0f4067b commit 99ff573

File tree

4 files changed

+604
-133
lines changed

4 files changed

+604
-133
lines changed

codeql_bundle/cli.py

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from typing import List, Optional
1515
import sys
1616
import logging
17+
import os
1718

1819
logger = logging.getLogger(__name__)
1920

@@ -40,7 +41,9 @@
4041
type=click.Path(exists=True, path_type=Path),
4142
default=Path.cwd(),
4243
)
43-
@click.option('--no-precompile', '-nc', is_flag=True, help="Do not pre-compile the bundle.")
44+
@click.option(
45+
"--no-precompile", "-nc", is_flag=True, help="Do not pre-compile the bundle."
46+
)
4447
@click.option(
4548
"-l",
4649
"--log",
@@ -50,8 +53,25 @@
5053
),
5154
default="WARNING",
5255
)
53-
@click.option("-p", "--platform", multiple=True, type=click.Choice(["linux64", "osx64", "win64"], case_sensitive=False), help="Target platform for the bundle")
54-
@click.option("-c", "--code-scanning-config", type=click.Path(exists=True, path_type=Path), help="Path to a Code Scanning configuration file that will be the default for the bundle")
56+
@click.option(
57+
"-p",
58+
"--platform",
59+
multiple=True,
60+
type=click.Choice(["linux64", "osx64", "win64"], case_sensitive=False),
61+
help="Target platform for the bundle",
62+
)
63+
@click.option(
64+
"-c",
65+
"--code-scanning-config",
66+
type=click.Path(exists=True, path_type=Path),
67+
help="Path to a Code Scanning configuration file that will be the default for the bundle",
68+
)
69+
@click.option(
70+
"-a",
71+
"--additional-data-config",
72+
type=click.Path(exists=True, path_type=Path),
73+
help="Path to a JSON file specifying additional data to install into the bundle",
74+
)
5575
@click.argument("packs", nargs=-1, required=True)
5676
def main(
5777
bundle_path: Path,
@@ -61,6 +81,7 @@ def main(
6181
loglevel: str,
6282
platform: List[str],
6383
code_scanning_config: Optional[Path],
84+
additional_data_config: Optional[Path],
6485
packs: List[str],
6586
) -> None:
6687

@@ -75,6 +96,8 @@ def main(
7596
level=getattr(logging, loglevel.upper()),
7697
)
7798

99+
workspace = Path(os.path.abspath(workspace))
100+
78101
if workspace.name == "codeql-workspace.yml":
79102
workspace = workspace.parent
80103

@@ -84,10 +107,15 @@ def main(
84107

85108
try:
86109
bundle = CustomBundle(bundle_path, workspace)
87-
# options for custom bundle
110+
# options for custom bundle
88111
bundle.disable_precompilation = no_precompile
89112

90-
unsupported_platforms = list(filter(lambda p: not bundle.supports_platform(BundlePlatform.from_string(p)), platform))
113+
unsupported_platforms = list(
114+
filter(
115+
lambda p: not bundle.supports_platform(BundlePlatform.from_string(p)),
116+
platform,
117+
)
118+
)
91119
if len(unsupported_platforms) > 0:
92120
logger.fatal(
93121
f"The provided bundle supports the platform(s) {', '.join(map(str, bundle.platforms))}, but doesn't support the following platform(s): {', '.join(unsupported_platforms)}"
@@ -113,7 +141,6 @@ def main(
113141
else:
114142
selected_packs = packs_in_workspace
115143

116-
117144
missing_packs = set(packs) - {pack.config.name for pack in selected_packs}
118145
if len(missing_packs) > 0:
119146
logger.fatal(
@@ -125,8 +152,15 @@ def main(
125152
f"Adding the pack(s) {','.join(map(lambda p: p.config.name, selected_packs))} and its workspace dependencies to the custom bundle."
126153
)
127154
bundle.add_packs(*selected_packs)
155+
if additional_data_config:
156+
logger.info(
157+
f"Installing additions specified in the config file {additional_data_config} to the custom bundle."
158+
)
159+
bundle.add_files_and_certs(additional_data_config, workspace)
128160
if code_scanning_config:
129-
logger.info(f"Adding the Code Scanning configuration file {code_scanning_config} to the custom bundle.")
161+
logger.info(
162+
f"Adding the Code Scanning configuration file {code_scanning_config} to the custom bundle."
163+
)
130164
bundle.add_code_scanning_config(code_scanning_config)
131165
logger.info(f"Bundling custom bundle(s) at {output}")
132166
platforms = set(map(BundlePlatform.from_string, platform))

0 commit comments

Comments
 (0)