Skip to content

Commit

Permalink
chore: update actions with new cli design
Browse files Browse the repository at this point in the history
  • Loading branch information
qduanmu committed Dec 13, 2024
1 parent 6cd4196 commit 487d1d4
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 78 deletions.
18 changes: 9 additions & 9 deletions actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ This document provides instructions and examples for creating and using GitHub A
## Directory Structure

- Actions related to trestle-bot are located in the `actions` directory.
- Actions should correlate an entrypoint under the `trestlebot/entrypoints` directory.
- Actions should correlate an command under the `trestlebot/cli/commands` directory.

## Adding a New Action

Contributors should scope trestle-bot actions to workspace management and checks. To add a new action:

> Prerequisite: An entrypoint was created under the `trestlebot/entrypoints` directory and added to the `pyproject.toml` under `[tool.poetry.scripts]`
> Prerequisite: An entrypoint was created under the `trestlebot/cli` directory and added to the `pyproject.toml` under `[tool.poetry.scripts]`
1. Create a new directory in the `actions` directory.
2. In the new directory, create an `action.yml` file that references the Dockerfile in the root of the repository.
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@v4
- uses: RedHatProductSecurity/trestle-bot/actions/create-cd@main
with:
markdown_path: "markdown/components"
markdown_dir: "markdown/components"
profile_name: "my-profile"
component_definition_name: "my-component-definition"
component_title: "my-component"
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
id: autosync
uses: RedHatProductSecurity/trestle-bot/actions/autosync@main
with:
markdown_path: "md_comp"
markdown_dir: "md_comp"
oscal_model: "compdef"
commit_message: "Autosync component definition content [skip ci]"
# Rule transformation is not idempotent, so you may only want to run this
Expand All @@ -115,7 +115,7 @@ jobs:
id: transform
uses: RedHatProductSecurity/trestle-bot/actions/rules-transform@main
with:
markdown_path: "md_comp"
markdown_dir: "md_comp"
commit_message: "Auto-transform rules [skip ci]"
```

Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
id: autosync
uses: RedHatProductSecurity/trestle-bot/actions/autosync@main
with:
markdown_path: "md_comp"
markdown_dir: "md_comp"
oscal_model: "compdef"
dry_run: true
- uses: dorny/paths-filter@v3
Expand All @@ -162,7 +162,7 @@ jobs:
id: transform
uses: RedHatProductSecurity/trestle-bot/actions/rules-transform@main
with:
markdown_path: "md_comp"
markdown_dir: "md_comp"
dry_run: true
```

Expand Down Expand Up @@ -210,7 +210,7 @@ jobs:
if: steps.trestlebot.outputs.changes == 'true'
uses: RedHatProductSecurity/trestle-bot/actions/autosync@main
with:
markdown_path: "markdown/components"
markdown_dir: "markdown/components"
oscal_model: "compdef"
branch: "sync-upstream-${{ github.run_id }}"
skip_assemble: true
Expand Down Expand Up @@ -244,7 +244,7 @@ jobs:
- name: Autosync
uses: RedHatProductSecurity/trestle-bot/actions/autosync@main
with:
markdown_path: "md_comp"
markdown_dir: "md_comp"
oscal_model: "compdef"
commit_message: "Update content for release [skip ci]"
version: ${{ github.event.inputs.version }}
Expand Down
24 changes: 12 additions & 12 deletions actions/autosync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ name: Example Workflow
id: trestlebot
uses: RedHatProductSecurity/trestle-bot/actions/autosync@main
with:
markdown_path: "markdown/profiles"
markdown_dir: "markdown/profiles"
oscal_model: "profile"
```
Expand All @@ -23,21 +23,21 @@ name: Example Workflow
<!-- START_ACTION_INPUTS -->
| Name | Description | Default | Required |
| --- | --- | --- | --- |
| markdown_path | Path relative to the repository path where the Trestle markdown files are located. See action README.md for more information. | None | True |
| markdown_dir | Path relative to the repository path where the Trestle markdown files are located. See action README.md for more information. | None | True |
| oscal_model | OSCAL Model type to assemble. Values can be catalog, profile, compdef, or ssp. | None | True |
| 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 |
| version | Version of the OSCAL model to set during assembly into JSON. | None | False |
| skip_assemble | Skip assembly task. Defaults to false | false | False |
| skip_regenerate | Skip regenerate task. Defaults to false. | false | False |
| skip_items | Comma-separated glob patterns list of content by trestle name to skip during task execution. For example `profile_x,profile_y*,`. | None | False |
| ssp_index_path | Path relative to the repository path where the ssp index is located. See action README.md for information about the ssp index. | ssp-index.json | False |
| ssp_index_file | Path relative to the repository path where the ssp index is located. See action README.md for information about the ssp index. | ssp-index.json | False |
| commit_message | Custom commit message | Sync automatic updates | False |
| pull_request_title | Custom pull request title | Automatic updates from trestlebot | False |
| branch | Name of the Git branch to which modifications should be pushed. Required if Action is used on the `pull_request` event. | ${{ github.ref_name }} | False |
| target_branch | Target branch (or base branch) to create a pull request against. If unset, no pull request will be created. If set, a pull request will be created using the `branch` field as the head branch. | None | False |
| file_pattern | Comma separated file pattern list used for `git add`. For example `component-definitions/*,*json`. Defaults to (`.`) | . | False |
| repository | Local file path to the git repository with a valid trestle project root relative to the GitHub workspace. | . | False |
| file_patterns | Comma separated file pattern list used for `git add`. For example `component-definitions/*,*json`. Defaults to (`.`) | . | False |
| repo_path | Local file path to the git repository with a valid trestle project root relative to the GitHub workspace. | . | False |
| commit_user_name | Name used for the commit user. | github-actions[bot] | False |
| commit_user_email | Email address used for the commit user | 41898282+github-actions[bot]@users.noreply.github.com | False |
| commit_author_name | Name used for the commit author. Defaults to the username of whoever triggered this workflow run. | ${{ github.actor }} | False |
Expand All @@ -59,8 +59,8 @@ name: Example Workflow

### Additional information on workflow inputs

- `markdown_path`: This is the location for Markdown generated by the `trestle author <model>-generate` commands
- `ssp_index_path`: This is a text file that stores the component definition information by name in trestle with the ssp name. Example below
- `markdown_dir`: This is the location for Markdown generated by the `trestle author <model>-generate` commands
- `ssp_index_file`: This is a text file that stores the component definition information by name in trestle with the ssp name. Example below

```json
"ssp1": {
Expand All @@ -85,7 +85,7 @@ The purpose of this action is to sync JSON and Markdown data with `compliance-tr
id: trestlebot
uses: RedHatProductSecurity/trestle-bot/actions/autosync@main
with:
markdown_path: "markdown/profiles"
markdown_dir: "markdown/profiles"
oscal_model: "profile"
branch: "another-branch"
```
Expand All @@ -99,7 +99,7 @@ The purpose of this action is to sync JSON and Markdown data with `compliance-tr
id: trestlebot
uses: RedHatProductSecurity/trestle-bot/actions/autosync@main
with:
markdown_path: "markdown/profiles"
markdown_dir: "markdown/profiles"
oscal_model: "profile"
branch: "autoupdate-${{ github.run_id }}"
target_branch: "main"
Expand All @@ -117,7 +117,7 @@ This can be helpful if you want to enforce that the content is in sync before it
id: check
uses: RedHatProductSecurity/trestle-bot/actions/autosync@main
with:
markdown_path: "markdown/profiles"
markdown_dir: "markdown/profiles"
oscal_model: "profile"
dry_run: true
# Optional - Set the action to failed if changes are detected.
Expand All @@ -127,7 +127,7 @@ This can be helpful if you want to enforce that the content is in sync before it
with:
script: |
core.setFailed('Changes detected. Manual intervention required.')
```

> Note: Trestle `assemble` or `regenerate` tasks may be skipped if desired using `skip_assemble: true` or `skip_regenerate: true`, respectively.
> Note: Trestle `assemble` or `regenerate` tasks may be skipped if desired using `skip_assemble: true` or `skip_regenerate: true`, respectively.
10 changes: 5 additions & 5 deletions actions/autosync/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ author: "Red Hat Product Security"
description: "An action to perform automatic synchronization of Trestle markdown files to OSCAL."

inputs:
markdown_path:
markdown_dir:
description: Path relative to the repository path where the Trestle markdown files are located. See action README.md for more information.
required: true
oscal_model:
description: OSCAL Model type to assemble. Values can be catalog, profile, compdef, or ssp.
required: true
dry_run:
dry_run:
description: "Runs tasks without pushing changes to the repository."
required: false
default: "false"
Expand All @@ -32,7 +32,7 @@ inputs:
skip_items:
description: "Comma-separated glob patterns list of content by trestle name to skip during task execution. For example `profile_x,profile_y*,`."
required: false
ssp_index_path:
ssp_index_file:
description: Path relative to the repository path where the ssp index is located. See action README.md for information about the ssp index.
required: false
default: "ssp-index.json"
Expand All @@ -51,11 +51,11 @@ inputs:
target_branch:
description: Target branch (or base branch) to create a pull request against. If unset, no pull request will be created. If set, a pull request will be created using the `branch` field as the head branch.
required: false
file_pattern:
file_patterns:
description: Comma separated file pattern list used for `git add`. For example `component-definitions/*,*json`. Defaults to (`.`)
required: false
default: '.'
repository:
repo_path:
description: Local file path to the git repository with a valid trestle project root relative to the GitHub workspace.
required: false
default: '.'
Expand Down
12 changes: 6 additions & 6 deletions actions/autosync/auto-sync-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ source /common.sh
set_git_safe_directory

# Initialize the command variable
command="trestlebot-autosync \
--markdown-path=\"${INPUT_MARKDOWN_PATH}\" \
command="trestlebot autosync \
--markdown-dir=\"${INPUT_MARKDOWN_DIR}\" \
--oscal-model=\"${INPUT_OSCAL_MODEL}\" \
--ssp-index-path=\"${INPUT_SSP_INDEX_PATH}\" \
--ssp-index-file=\"${INPUT_SSP_INDEX_FILE}\" \
--commit-message=\"${INPUT_COMMIT_MESSAGE}\" \
--pull-request-title=\"${INPUT_PULL_REQUEST_TITLE}\" \
--branch=\"${INPUT_BRANCH}\" \
--file-patterns=\"${INPUT_FILE_PATTERN}\" \
--file-patterns=\"${INPUT_FILE_PATTERNS}\" \
--committer-name=\"${INPUT_COMMIT_USER_NAME}\" \
--committer-email=\"${INPUT_COMMIT_USER_EMAIL}\" \
--author-name=\"${INPUT_COMMIT_AUTHOR_NAME}\" \
--author-email=\"${INPUT_COMMIT_AUTHOR_EMAIL}\" \
--working-dir=\"${INPUT_REPOSITORY}\" \
--repo-path=\"${INPUT_REPO_PATH}\" \
--target-branch=\"${INPUT_TARGET_BRANCH}\" \
--skip-items=\"${INPUT_SKIP_ITEMS}\" \
--version=\"${INPUT_VERSION}\""
Expand All @@ -42,4 +42,4 @@ if [[ ${INPUT_VERBOSE} == true ]]; then
command+=" --verbose"
fi

eval "${command}"
eval "${command}"
16 changes: 8 additions & 8 deletions actions/create-cd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name: Example Workflow
id: trestlebot
uses: RedHatProductSecurity/trestle-bot/actions/create-cd@main
with:
markdown_path: "markdown/components"
markdown_dir: "markdown/components"
profile_name: "profile"
component_definition_name: "component-definition"
component_title: "My Component Title"
Expand All @@ -25,7 +25,7 @@ name: Example Workflow
<!-- 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 |
| markdown_dir | Path relative to the repository path to create markdown files. See action README.md for more information. | None | True |
| profile_name | Name of the Trestle profile to use for the component definition | None | True |
| component_definition_name | Name of the component definition to create | None | True |
| component_title | Name of the component to create | None | True |
Expand All @@ -38,8 +38,8 @@ name: Example Workflow
| pull_request_title | Custom pull request title | Automatic updates from trestlebot | False |
| branch | Name of the Git branch to which modifications should be pushed. Required if Action is used on the `pull_request` event. | ${{ github.ref_name }} | False |
| target_branch | Target branch (or base branch) to create a pull request against. If unset, no pull request will be created. If set, a pull request will be created using the `branch` field as the head branch. | None | False |
| file_pattern | Comma separated file pattern list used for `git add`. For example `component-definitions/*,*json`. Defaults to (`.`) | . | False |
| repository | Local file path to the git repository with a valid trestle project root relative to the GitHub workspace. Defaults to the current directory (`.`) | . | False |
| file_patterns | Comma separated file pattern list used for `git add`. For example `component-definitions/*,*json`. Defaults to (`.`) | . | False |
| repo_path | Local file path to the git repository with a valid trestle project root relative to the GitHub workspace. Defaults to the current directory (`.`) | . | False |
| commit_user_name | Name used for the commit user | github-actions[bot] | False |
| commit_user_email | Email address used for the commit user | 41898282+github-actions[bot]@users.noreply.github.com | False |
| commit_author_name | Name used for the commit author. Defaults to the username of whoever triggered this workflow run. | ${{ github.actor }} | False |
Expand All @@ -61,7 +61,7 @@ name: Example Workflow

### Additional information on workflow inputs

- `markdown_path`: This is the location for Markdown generated by the `trestle author <model>-generate` commands.
- `markdown_dir`: This is the location for Markdown generated by the `trestle author <model>-generate` commands.

## Action Behavior

Expand All @@ -76,7 +76,7 @@ The purpose of this action is to create a new component definition and commit ch
id: trestlebot
uses: RedHatProductSecurity/trestle-bot/actions/create-cd@main
with:
markdown_path: "markdown/components"
markdown_dir: "markdown/components"
profile_name: "profile"
component_definition_name: "component-definition"
component_title: "My Component Title"
Expand All @@ -93,12 +93,12 @@ The purpose of this action is to create a new component definition and commit ch
id: trestlebot
uses: RedHatProductSecurity/trestle-bot/actions/create-cd@main
with:
markdown_path: "markdown/components"
markdown_dir: "markdown/components"
profile_name: "profile"
component_definition_name: "component-definition"
component_title: "My Component Title"
component_description: "My Component Description"
branch: "create-cd-${{ github.run_id }}"
target_branch: "main"
github_token: ${{ secret.GITHUB_TOKEN }}
```
```
6 changes: 3 additions & 3 deletions actions/create-cd/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ author: "Red Hat Product Security"
description: "An action for component definition bootstrapping"

inputs:
markdown_path:
markdown_dir:
description: Path relative to the repository path to create markdown files. See action README.md for more information.
required: true
profile_name:
Expand Down Expand Up @@ -49,11 +49,11 @@ inputs:
target_branch:
description: Target branch (or base branch) to create a pull request against. If unset, no pull request will be created. If set, a pull request will be created using the `branch` field as the head branch.
required: false
file_pattern:
file_patterns:
description: Comma separated file pattern list used for `git add`. For example `component-definitions/*,*json`. Defaults to (`.`)
required: false
default: '.'
repository:
repo_path:
description: Local file path to the git repository with a valid trestle project root relative to the GitHub workspace. Defaults to the current directory (`.`)
required: false
default: '.'
Expand Down
10 changes: 5 additions & 5 deletions actions/create-cd/create-cd-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ source /common.sh
set_git_safe_directory

# Initialize the command variable
command="trestlebot-create-cd \
command="trestlebot create compdef \
--profile-name=\"${INPUT_PROFILE_NAME}\" \
--compdef-name=\"${INPUT_COMPONENT_DEFINITION_NAME}\" \
--component-title=\"${INPUT_COMPONENT_TITLE}\" \
--component-description=\"${INPUT_COMPONENT_DESCRIPTION}\" \
--component-definition-type=\"${INPUT_COMPONENT_TYPE}\" \
--markdown-path=\"${INPUT_MARKDOWN_PATH}\" \
--markdown-dir=\"${INPUT_MARKDOWN_DIR}\" \
--commit-message=\"${INPUT_COMMIT_MESSAGE}\" \
--filter-by-profile=\"${INPUT_FILTER_BY_PROFILE}\" \
--pull-request-title=\"${INPUT_PULL_REQUEST_TITLE}\" \
--branch=\"${INPUT_BRANCH}\" \
--file-patterns=\"${INPUT_FILE_PATTERN}\" \
--file-patterns=\"${INPUT_FILE_PATTERNS}\" \
--committer-name=\"${INPUT_COMMIT_USER_NAME}\" \
--committer-email=\"${INPUT_COMMIT_USER_EMAIL}\" \
--author-name=\"${INPUT_COMMIT_AUTHOR_NAME}\" \
--author-email=\"${INPUT_COMMIT_AUTHOR_EMAIL}\" \
--working-dir=\"${INPUT_REPOSITORY}\" \
--repo-path=\"${INPUT_REPO_PATH}\" \
--target-branch=\"${INPUT_TARGET_BRANCH}\""

# Conditionally include flags
Expand All @@ -36,4 +36,4 @@ if [[ ${INPUT_DRY_RUN} == true ]]; then
command+=" --dry-run"
fi

eval "${command}"
eval "${command}"
Loading

0 comments on commit 487d1d4

Please sign in to comment.