Skip to content

Commit

Permalink
feat: adds markdown generation to the rules transform entrypoint
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Modifies the existing behavior of the rules transform
entrypoint

Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Jul 24, 2024
1 parent b2cf138 commit c1b16b9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
7 changes: 6 additions & 1 deletion actions/rules-transform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ name: Example Workflow
- name: Run trestlebot
id: trestlebot
uses: RedHatProductSecurity/trestle-bot/actions/rules-transform@main
with:
markdown_path: "markdown/components"

```
With custom rules directory:
Expand All @@ -24,6 +27,7 @@ With custom rules directory:
id: trestlebot
uses: RedHatProductSecurity/trestle-bot/actions/rules-transform@main
with:
markdown_path: "markdown/components"
rules_view_path: "custom-rules-dir/"
```
Expand All @@ -32,6 +36,7 @@ With custom rules directory:
<!-- START_ACTION_INPUTS -->
| Name | Description | Default | Required |
| --- | --- | --- | --- |
| markdown_path | Path relative to the repository path to create markdown files. See action README.md for more information. | None | True |
| rules_view_path | Path relative to the repository path where the Trestle rules view files are located. Defaults to `rules/`. | rules/ | False |
| dry_run | Runs tasks without pushing changes to the repository. | false | False |
| github_token | "GitHub token used to make authenticated API requests. Note: You should use a defined secret like "secrets.GITHUB_TOKEN" in your workflow file, do not hardcode the token." | None | False |
Expand Down Expand Up @@ -63,7 +68,7 @@ With custom rules directory:

## Action Behavior

The purpose of this action is to sync the rules view data in YAML to OSCAL with `compliance-trestle` and commit changes back to the branch or submit a pull request (if desired). Below are the main use-cases/workflows available:
The purpose of this action is to sync the rules view data in YAML to OSCAL with `compliance-trestle` and generation corresponding Markdown and commit changes back to the branch or submit a pull request (if desired). Below are the main use-cases/workflows available:

- The default behavior of this action is to run the rules transformation and commit the changes back to the branch the workflow ran from ( `github.ref_name` ). The branch can be changed by setting the field `branch`. If no changes exist or the changes do not exist with the file pattern set, no changes will be made and the action will exit successfully.

Expand Down
5 changes: 4 additions & 1 deletion actions/rules-transform/action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: "trestle-bot-rules-transform"
author: "Red Hat Product Security"
description: "A rules transform action to convert trestle rules in YAML format to OSCAL"
description: "A rules transform action to convert trestle rules in YAML format to OSCAL and propagates changes to Markdown."

inputs:
markdown_path:
description: Path relative to the repository path to create markdown files. See action README.md for more information.
required: true
rules_view_path:
description: Path relative to the repository path where the Trestle rules view files are located. Defaults to `rules/`.
required: false
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/test_e2e_compdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"success/happy path",
{
"branch": "test",
"markdown-path": "md_comp",
"rules-view-path": RULES_VIEW_DIR,
"committer-name": "test",
"committer-email": "[email protected]",
Expand All @@ -46,6 +47,7 @@
{
"branch": "test",
"rules-view-path": RULES_VIEW_DIR,
"markdown-path": "md_comp",
"committer-name": "test",
"committer-email": "test",
"skip-items": test_comp_name,
Expand Down Expand Up @@ -82,6 +84,7 @@ def test_rules_transform_e2e(
tmp_repo_path, test_comp_name, ComponentDefinition, FileContentType.JSON
)
assert comp_path.exists()
assert tmp_repo_path.joinpath("md_comp").exists()
assert f"input: {test_comp_name}.csv" in response_stdout
branch = command_args["branch"]
assert f"Changes pushed to {branch} successfully." in response_stdout
Expand Down
21 changes: 18 additions & 3 deletions trestlebot/entrypoints/rule_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
import sys
from typing import List

from trestlebot.const import SUCCESS_EXIT_CODE
from trestlebot.const import RULES_VIEW_DIR, SUCCESS_EXIT_CODE
from trestlebot.entrypoints.entrypoint_base import (
EntrypointBase,
comma_sep_to_list,
handle_exception,
)
from trestlebot.entrypoints.log import set_log_level_from_args
from trestlebot.tasks.authored.compdef import AuthoredComponentDefinition
from trestlebot.tasks.base_task import ModelFilter, TaskBase
from trestlebot.tasks.regenerate_task import RegenerateTask
from trestlebot.tasks.rule_transform_task import RuleTransformTask
from trestlebot.transformers.yaml_transformer import ToRulesYAMLTransformer

Expand All @@ -36,10 +38,17 @@ def __init__(self, parser: argparse.ArgumentParser) -> None:
def setup_rules_transformation_arguments(self) -> None:
"""Setup arguments for the rule transformer entrypoint."""
self.parser.add_argument(
"--rules-view-path",
"--markdown-path",
required=True,
type=str,
help="Path to create markdown files in.",
)
self.parser.add_argument(
"--rules-view-path",
required=False,
type=str,
help="Path to top-level rules-view directory",
default=RULES_VIEW_DIR,
)
self.parser.add_argument(
"--skip-items",
Expand Down Expand Up @@ -68,7 +77,13 @@ def run(self, args: argparse.Namespace) -> None:
rule_transformer=transformer,
model_filter=model_filter,
)
pre_tasks: List[TaskBase] = [rule_transform_task]
regenerate_task: RegenerateTask = RegenerateTask(
markdown_dir=args.markdown_path,
authored_object=AuthoredComponentDefinition(args.working_dir),
model_filter=model_filter,
)

pre_tasks: List[TaskBase] = [rule_transform_task, regenerate_task]

super().run_base(args, pre_tasks)
except Exception as e:
Expand Down

0 comments on commit c1b16b9

Please sign in to comment.