Workflow Generator¶
osa_tool.operations.codebase.workflow_generation.workflow_generator
¶
GitHubWorkflowGenerator
¶
Bases: WorkflowGenerator
generate_autopep8(name='Format python code with autopep8', max_line_length=120, aggressive_level=2, branches=['main', 'master'])
¶
Generate a workflow for running autopep8 and commenting on pull requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the workflow. |
'Format python code with autopep8'
|
max_line_length
|
int
|
Maximum line length for autopep8. |
120
|
aggressive_level
|
int
|
Aggressive level for autopep8 (1 or 2). |
2
|
branches
|
List[str]
|
List of branches to trigger the workflow on. |
['main', 'master']
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the generated file. |
generate_black_formatter(name='Black Formatter', job_name='Lint', branches=[], black_options='--check --diff', src='.', use_pyproject=False, version=None, jupyter=False, python_version=None)
¶
Create a GitHub Actions workflow for running the Black code formatter using the official Black action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Workflow name (default: "Black Formatter"). |
'Black Formatter'
|
job_name
|
str
|
Job name inside the workflow (default: "Lint"). |
'Lint'
|
branches
|
List[str]
|
List of branches to trigger on (default: None, triggers on all branches). |
[]
|
black_options
|
str
|
Options to pass to Black formatter. |
'--check --diff'
|
src
|
str
|
Source directory to format. |
'.'
|
use_pyproject
|
bool
|
Whether to use pyproject.toml config. |
False
|
version
|
Optional[str]
|
Specific Black version to use. |
None
|
jupyter
|
bool
|
Whether to format Jupyter notebooks. |
False
|
python_version
|
Optional[str]
|
Python version to setup. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the generated file. |
generate_fix_pep8_command(name='fix-pep8-command', max_line_length=120, aggressive_level=2, repo_access_token=True)
¶
Generate a workflow for fixing PEP8 issues when triggered by a slash command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the workflow. |
'fix-pep8-command'
|
max_line_length
|
int
|
Maximum line length for autopep8. |
120
|
aggressive_level
|
int
|
Aggressive level for autopep8 (1 or 2). |
2
|
repo_access_token
|
bool
|
Whether to use a repository access token. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the generated file. |
generate_pep8(name='PEP 8 Compliance', tool='flake8', python_version='3.10', args='', branches=['main', 'master'])
¶
Generate a workflow for checking PEP 8 compliance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the workflow. |
'PEP 8 Compliance'
|
tool
|
str
|
Tool to use for PEP 8 checking (flake8 or pylint). |
'flake8'
|
python_version
|
str
|
Python version to use. |
'3.10'
|
args
|
str
|
Arguments to pass to the tool. |
''
|
branches
|
List[str]
|
List of branches to trigger the workflow on. |
['main', 'master']
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the generated file. |
generate_pypi_publish(name='PyPI Publish', python_version='3.10', use_poetry=False, trigger_on_tags=True, trigger_on_release=False, manual_trigger=True)
¶
Generate a workflow for publishing to PyPI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the workflow. |
'PyPI Publish'
|
python_version
|
str
|
Python version to use. |
'3.10'
|
use_poetry
|
bool
|
Whether to use Poetry for packaging. |
False
|
trigger_on_tags
|
bool
|
Whether to trigger on tags. |
True
|
trigger_on_release
|
bool
|
Whether to trigger on release. |
False
|
manual_trigger
|
bool
|
Whether to allow manual triggering. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the generated file. |
generate_selected_jobs(settings, plan)
¶
Generate a complete set of workflows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
WorkflowSettings
|
An object containing all workflow generation settings. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: List of paths to generated files. |
generate_slash_command_dispatch(name='Slash Command Dispatch', commands=['fix-pep8'], permission='none')
¶
Generate a workflow for dispatching slash commands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the workflow. |
'Slash Command Dispatch'
|
commands
|
List[str]
|
List of commands to dispatch. |
['fix-pep8']
|
permission
|
str
|
Permission level for the workflow. |
'none'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the generated file. |
generate_unit_test(name='Unit Tests', python_versions=['3.9', '3.10'], os_list=['ubuntu-latest'], dependencies_command='pip install -r requirements.txt', test_command='pytest tests/', branches=[], coverage=True, timeout_minutes=15, codecov_token=False)
¶
Generate a GitHub Actions workflow for running unit tests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the workflow. |
'Unit Tests'
|
python_versions
|
List[str]
|
List of Python versions to test against. |
['3.9', '3.10']
|
os_list
|
List[str]
|
List of operating systems to test on. |
['ubuntu-latest']
|
dependencies_command
|
str
|
Command to install dependencies. |
'pip install -r requirements.txt'
|
test_command
|
str
|
Command to run tests. |
'pytest tests/'
|
branches
|
List[str]
|
List of branches to trigger the workflow on. |
[]
|
coverage
|
bool
|
Whether to include code coverage reporting. |
True
|
timeout_minutes
|
int
|
Maximum time in minutes for the job to run. |
15
|
codecov_token
|
bool
|
Whether to use a Codecov token for uploading coverage. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the generated file. |
load_template(template_name)
¶
Load a template file content as a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_name
|
str
|
Template file name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Contents of the template file. |
GitLabWorkflowGenerator
¶
Bases: WorkflowGenerator
generate_selected_jobs(settings, plan)
¶
Generate a complete set of workflows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
WorkflowSettings
|
An object containing all workflow generation settings. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: List of paths to generated files. |
load_template(template_name)
¶
Load a template file content as a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_name
|
str
|
Template file name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Contents of the template file. |
WorkflowGenerator
¶
Bases: ABC
__init__(output_dir)
¶
Initialize the CICD files generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str
|
Directory where the CICD files will be saved. |
required |
generate_autopep8()
abstractmethod
¶
Generate auto-PEP8 fixing part.
generate_black_formatter()
abstractmethod
¶
Generate black formatter part.
generate_fix_pep8_command()
abstractmethod
¶
Generate part for fixing PEP8 issues.
generate_pep8()
abstractmethod
¶
Generate PEP8 checking part.
generate_pypi_publish()
abstractmethod
¶
Generate PyPI publish part.
generate_selected_jobs(settings, plan)
abstractmethod
¶
Generate selected jobs based on settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
WorkflowSettings
|
CI/CD specific settings extracted from the config. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: List of paths to generated files. |
generate_slash_command_dispatch()
abstractmethod
¶
Generate part for slash command dispatch.
generate_unit_test()
abstractmethod
¶
Generate unit test part.
load_template(template_name)
abstractmethod
¶
Load a template file content as a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_name
|
str
|
Template file name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Contents of the template file. |