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

Create empty scan results to prevent upload failures #227

Merged
merged 1 commit into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 8 additions & 7 deletions lib/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,14 @@ def report(
html_file = crep_fname.replace(".sarif", ".html")
with io.open(crep_fname, "w") as fileobj:
fileobj.write(serialized_log)
render_html(json.loads(serialized_log), html_file)
if fileobj.name != sys.stdout.name:
LOG.debug(
"SARIF and HTML report written to file: %s, %s 👍",
fileobj.name,
html_file,
)
if tool_name != "empty-scan":
render_html(json.loads(serialized_log), html_file)
if fileobj.name != sys.stdout.name:
LOG.debug(
"SARIF and HTML report written to file: %s, %s 👍",
fileobj.name,
html_file,
)
return serialized_log


Expand Down
15 changes: 10 additions & 5 deletions scan
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,14 @@ def bomgen(src, reports_dir, convert, repo_context):
exec_tool("cdxgen", bom_args, src)


def create_empty_result(src_dir, reports_dir):
# Create empty sarif file to prevent codeql upload action from failing
crep_fname = utils.get_report_file(
"empty-scan", reports_dir, True, ext_name="sarif"
)
convertLib.report("empty-scan", [], src_dir, None, [], [], crep_fname, None)


def should_skip(src_dir, reports_dir, repo_context, scan_mode):
"""
Method to check if a scan should be skipped
Expand All @@ -577,11 +585,7 @@ def should_skip(src_dir, reports_dir, repo_context, scan_mode):
LOG.info(
f"""Scan will be skipped since the build was triggered by a bot '{repo_context.get("invokedBy")}'"""
)
# Create empty sarif file to prevent codeql upload action from failing
crep_fname = utils.get_report_file(
"empty-scan", reports_dir, True, ext_name="sarif"
)
convertLib.report("empty-scan", [], src_dir, None, [], [], crep_fname, None)
create_empty_result(src_dir, reports_dir)
return True
return False

Expand Down Expand Up @@ -700,6 +704,7 @@ def main():
LOG.debug(
"No scan summary was produced - {}, {}".format(sarif_files, agg_fname)
)
create_empty_result(src_dir, reports_dir)


if __name__ == "__main__":
Expand Down