macaron.parsers package
Subpackages
Submodules
macaron.parsers.actionparser module
This module contains the parser for GitHub Actions Workflow files.
- macaron.parsers.actionparser.parse(workflow_path)
Parse the GitHub Actions workflow YAML file.
- Parameters:
workflow_path (str) – Path to the GitHub Actions.
- Returns:
The parsed workflow.
- Return type:
Workflow
- Raises:
ParseError – When parsing fails with errors.
- macaron.parsers.actionparser.get_run_step(step)
Get the parsed GitHub Action run step for inlined shell scripts.
If the run step cannot be validated this function returns None.
- Parameters:
step (Step) – The parsed step object.
- Returns:
The inlined run script or None if the run step cannot be validated.
- Return type:
str | None
- macaron.parsers.actionparser.get_step_input(step, key)
Get an input value from a GitHub Action step.
If the input value cannot be found or the step inputs cannot be validated this function returns None.
macaron.parsers.bashparser module
This module is a Python wrapper for the compiled bashparser binary.
The bashparser Go module is based on the github.com/mvdan/sh
Go module and is distributed
together with Macaron as a compiled binary.
See Also https://github.com/mvdan/sh.
- class macaron.parsers.bashparser.BashScriptType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
This class is used for different bash script types.
- NONE = 'None'
- INLINE = 'inline'
- FILE = 'file'
- class macaron.parsers.bashparser.BashNode(name, node_type, source_path, parsed_step_obj, parsed_bash_obj, **kwargs)
Bases:
BaseNode
This class represents a callgraph node for bash commands.
- __init__(name, node_type, source_path, parsed_step_obj, parsed_bash_obj, **kwargs)
Initialize instance.
- Parameters:
name (str) – Name of the bash script file or the step name if the script is inlined.
node_type (BashScriptType) – The type of the script.
source_path (str) – The path of the script.
parsed_step_obj (Step | None) – The parsed step object.
parsed_bash_obj (dict) – The parsed bash script object.
- macaron.parsers.bashparser.parse_file(file_path, macaron_path=None)
Parse a bash script file.
- Parameters:
- Returns:
The parsed bash script in JSON (dict) format.
- Return type:
- Raises:
ParseError – When parsing fails with errors.
- macaron.parsers.bashparser.parse(bash_content, macaron_path=None)
Parse a bash script’s content.
- Parameters:
- Returns:
The parsed bash script in JSON (dict) format.
- Return type:
- Raises:
ParseError – When parsing fails with errors.
- macaron.parsers.bashparser.create_bash_node(name, node_id, node_type, source_path, ci_step_ast, repo_path, caller, recursion_depth, macaron_path=None)
Create a callgraph node for a bash script.
A bash node can have the following types:
BashScriptType.INLINE
when it is inlined in a CI workflow.BashScriptType.FILE
when it is a bash script file.
- Parameters:
name (str) – A name to be used as the identifier of the node.
node_id (str | None) – The node ID if defined.
node_type (BashScriptType) – The type of the node.
source_path (str) – The file that contains the bash script.
ci_step_ast (Step | None) – The AST of the CI step that runs a bash script.
repo_path (str) – The path to the target repo.
caller (BaseNode) – The caller node.
recursion_depth (int) – The number of times this function is called recursively.
macaron_path=None – The path to the Macaron module.
- Returns:
A bash node object.
- Return type:
- Raises:
CallGraphError – When unable to create a bash node.
macaron.parsers.github_workflow_model module
- class macaron.parsers.github_workflow_model.On
Bases:
TypedDict
-
pull_request:
NotRequired
[Ref1
]
-
pull_request_target:
NotRequired
[Ref1
]
-
push:
NotRequired
[Ref1
]
-
workflow_call:
NotRequired
[WorkflowCall
]
-
workflow_dispatch:
NotRequired
[WorkflowDispatch
]
-
schedule:
NotRequired
[list
[ScheduleItem
]]
-
pull_request:
- class macaron.parsers.github_workflow_model.Container
Bases:
TypedDict
-
credentials:
NotRequired
[Credentials
]
-
credentials:
- class macaron.parsers.github_workflow_model.ReusableWorkflowCallJob
Bases:
dict
-
strategy:
NotRequired
[Strategy
]
-
strategy:
- class macaron.parsers.github_workflow_model.Identified(id, obj)
Bases:
Generic
[T
]- __init__(id, obj)
- macaron.parsers.github_workflow_model.is_normal_job(job)
- Return type:
TypeGuard
[NormalJob
]
- macaron.parsers.github_workflow_model.is_reusable_workflow_call_job(job)
- Return type:
TypeGuard
[ReusableWorkflowCallJob
]
- macaron.parsers.github_workflow_model.is_run_step(step)
- Return type:
TypeGuard
[Step5
]
- macaron.parsers.github_workflow_model.is_action_step(step)
- Return type:
TypeGuard
[Step4
]