Skip to content

Commit

Permalink
chore: improve build command output (#627)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Allen <[email protected]>
  • Loading branch information
nicallen authored Feb 8, 2024
1 parent e14eede commit 1feed17
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
28 changes: 23 additions & 5 deletions src/macaron/slsa_analyzer/checks/build_as_code_check.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright (c) 2022 - 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2022 - 2024, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.

"""This module contains the BuildAsCodeCheck class."""

import json
import logging
import os
from typing import Any
Expand Down Expand Up @@ -83,6 +84,21 @@ def __init__(self) -> None:
result_on_skip=CheckResultType.PASSED,
)

def _serialize_command(self, cmd: list[str]) -> str:
"""Convert a list of command-line arguments to a json-encoded string so that it is easily parsable by later consumers.
Parameters
----------
cmd: list[str]
List of command-line arguments.
Returns
-------
str
The list of command-line arguments as a json-encoded string.
"""
return json.dumps(cmd)

def _has_deploy_command(self, commands: list[list[str]], build_tool: BaseBuildTool) -> str:
"""Check if the bash command is a build and deploy command."""
# Account for Python projects having separate tools for packaging and publishing.
Expand Down Expand Up @@ -117,14 +133,16 @@ def _has_deploy_command(self, commands: list[list[str]], build_tool: BaseBuildTo
# If there are no deploy args for this build tool, accept as deploy command.
# TODO: Support multi-argument build keywords, issue #493.
if not build_tool.deploy_arg:
logger.info("No deploy arguments required. Accept %s as deploy command.", str(com))
return str(com)
com_str = self._serialize_command(com)
logger.info("No deploy arguments required. Accept %s as deploy command.", com_str)
return com_str

for word in com[(prog_name_index + 1) :]:
# TODO: allow plugin versions in arguments, e.g., maven-plugin:1.6.8:deploy.
if word in build_tool.deploy_arg:
logger.info("Found deploy command %s.", str(com))
return str(com)
com_str = self._serialize_command(com)
logger.info("Found deploy command %s.", com_str)
return com_str
return ""

def _check_build_tool(
Expand Down
29 changes: 24 additions & 5 deletions src/macaron/slsa_analyzer/checks/build_service_check.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright (c) 2022 - 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2022 - 2024, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.

"""This module contains the BuildServiceCheck class."""

import json
import logging
import os
from typing import Any
Expand Down Expand Up @@ -74,6 +75,21 @@ def __init__(self) -> None:
result_on_skip=CheckResultType.PASSED,
)

def _serialize_command(self, cmd: list[str]) -> str:
"""Convert a list of command-line arguments to a json-encoded string so that it is easily parsable by later consumers.
Parameters
----------
cmd: list[str]
List of command-line arguments.
Returns
-------
str
The list of command-line arguments as a json-encoded string.
"""
return json.dumps(cmd)

def _has_build_command(self, commands: list[list[str]], build_tool: BaseBuildTool) -> str:
"""Check if the bash command is a build command."""
for com in commands:
Expand Down Expand Up @@ -109,13 +125,15 @@ def _has_build_command(self, commands: list[list[str]], build_tool: BaseBuildToo
# If there are no build args for this build tool, accept as build command.
# TODO: Support multi-argument build keywords, issue #493.
if not build_tool.build_arg:
logger.info("No build arguments required. Accept %s as build command.", str(com))
return str(com)
com_str = self._serialize_command(com)
logger.info("No build arguments required. Accept %s as build command.", com_str)
return com_str
for word in com[(prog_name_index + 1) :]:
# TODO: allow plugin versions in arguments, e.g., maven-plugin:1.6.8:package.
if word in build_tool.build_arg:
logger.info("Found build command %s.", str(com))
return str(com)
com_str = self._serialize_command(com)
logger.info("Found build command %s.", com_str)
return com_str
return ""

def _check_build_tool(
Expand Down Expand Up @@ -189,6 +207,7 @@ def _check_build_tool(
BuildServiceFacts(
build_tool_name=build_tool.name,
build_trigger=trigger_link,
build_command=build_cmd,
ci_service_name=ci_service.name,
)
)
Expand Down

0 comments on commit 1feed17

Please sign in to comment.