-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PSCE-256 - Add create-cd GitHub Action (#68)
* feat: adds create-cd GitHub action with updated documentation Signed-off-by: Jennifer Power <[email protected]> * fix: fixes action.yml and updates README for create-cd Signed-off-by: Jennifer Power <[email protected]> * fix: fixes create-cd entrypoint typo Signed-off-by: Jennifer Power <[email protected]> * docs: updates REAMDE.md with information about the create-cd action Signed-off-by: Jennifer Power <[email protected]> * build(deps): Bumps pydantic to 1.10.3 Signed-off-by: Jennifer Power <[email protected]> * docs: updates custom rules dir snippet in rules-transform README.md Signed-off-by: Jennifer Power <[email protected]> --------- Signed-off-by: Jennifer Power <[email protected]>
- Loading branch information
Showing
12 changed files
with
534 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# trestlebot Create Component Definition Action | ||
|
||
## Basic Configuration | ||
|
||
```yaml | ||
|
||
name: Example Workflow | ||
... | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Run trestlebot | ||
id: trestlebot | ||
uses: RedHatProductSecurity/trestle-bot/actions/create-cd@main | ||
with: | ||
markdown_path: "markdown/components" | ||
profile_name: "profile" | ||
component_definition_name: "component-definition" | ||
component_title: "My Component Title" | ||
component_description: "My Component Description" | ||
``` | ||
## Inputs and Outputs | ||
Checkout [`action.yml`](./action.yml) for a full list of supported inputs and outputs. | ||
|
||
### Additional information on workflow inputs | ||
|
||
- `markdown_path`: This is the location for Markdown generated by the `trestle author <model>-generate` commands. | ||
|
||
## Action Behavior | ||
|
||
The purpose of this action is to create a new component definition 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 create a new component definition 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. | ||
|
||
```yaml | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Run trestlebot | ||
id: trestlebot | ||
uses: RedHatProductSecurity/trestle-bot/actions/create-cd@main | ||
with: | ||
markdown_path: "markdown/components" | ||
profile_name: "profile" | ||
component_definition_name: "component-definition" | ||
component_title: "My Component Title" | ||
component_description: "My Component Description" | ||
branch: "another-branch" | ||
``` | ||
|
||
- If the `target_branch` field is set, a pull request will be made using the `target_branch` as the base branch and `branch` as the head branch. | ||
|
||
```yaml | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Run trestlebot | ||
id: trestlebot | ||
uses: RedHatProductSecurity/trestle-bot/actions/create-cd@main | ||
with: | ||
markdown_path: "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 }} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
name: "trestle-bot-create-cd" | ||
author: "Red Hat Product Security" | ||
description: "An action for component definition bootstrapping" | ||
|
||
inputs: | ||
markdown_path: | ||
description: Path relative to the repository path to create markdown files. See action README.md for more information. | ||
required: true | ||
profile_name: | ||
description: Name of the Trestle profile to use for the component definition | ||
required: true | ||
component_definition_name: | ||
description: Name of the component definition to create | ||
required: true | ||
component_title: | ||
description: Name of the component to create | ||
required: true | ||
component_type: | ||
description: Type of the component to create | ||
required: false | ||
default: "service" | ||
component_description: | ||
description: Description of the component to create | ||
required: true | ||
filter_by_profile: | ||
description: Name of the profile in the workspace to filter controls by | ||
required: false | ||
github_token: | ||
description: "GitHub token used to make authenticated API requests" | ||
required: false | ||
commit_message: | ||
description: Commit message | ||
required: false | ||
default: "Sync automatic updates" | ||
pull_request_title: | ||
description: Custom pull request title | ||
required: false | ||
default: "Automatic updates from trestlebot" | ||
branch: | ||
description: Name of the Git branch to which modifications should be pushed. Required if Action is used on the `pull_request` event. | ||
required: false | ||
default: ${{ github.ref_name }} | ||
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: | ||
description: Comma separated file pattern list used for `git add`. For example `component-definitions/*,*json`. Defaults to (`.`) | ||
required: false | ||
default: '.' | ||
repository: | ||
description: Local file path to the git repository. Defaults to the current directory (`.`) | ||
required: false | ||
default: '.' | ||
commit_user_name: | ||
description: Name used for the commit user | ||
required: false | ||
default: github-actions[bot] | ||
commit_user_email: | ||
description: Email address used for the commit user | ||
required: false | ||
default: 41898282+github-actions[bot]@users.noreply.github.com | ||
commit_author_name: | ||
description: Name used for the commit author. Defaults to the username of whoever triggered this workflow run. | ||
required: false | ||
default: ${{ github.actor }} | ||
commit_author_email: | ||
description: Email address used for the commit author. Defaults to the email of whoever triggered this workflow run. | ||
required: false | ||
default: ${{ github.actor }}@users.noreply.github.com | ||
verbose: | ||
description: Enable verbose logging | ||
required: false | ||
default: "false" | ||
|
||
outputs: | ||
changes: | ||
description: Value is "true" if changes were committed back to the repository. | ||
commit: | ||
description: Full hash of the created commit. Only present if the "changes" output is "true". | ||
pr_number: | ||
description: Number of the submitted pull request. Only present if a pull request is submitted. | ||
|
||
runs: | ||
using: "docker" | ||
image: "../../Dockerfile" | ||
entrypoint: "/create-cd-entrypoint.sh" | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.github_token }} | ||
|
||
branding: | ||
icon: "check" | ||
color: "green" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
# Manage newest git versions (related to CVE https://github.blog/2022-04-12-git-security-vulnerability-announced/) | ||
# | ||
if [ -z ${GITHUB_WORKSPACE+x} ]; then | ||
echo "Setting git safe.directory default: /github/workspace ..." | ||
git config --global --add safe.directory /github/workspace | ||
else | ||
echo "Setting git safe.directory GITHUB_WORKSPACE: $GITHUB_WORKSPACE ..." | ||
git config --global --add safe.directory "$GITHUB_WORKSPACE" | ||
fi | ||
|
||
if [ -z ${INPUT_REPOSITORY+x} ]; then | ||
echo "Skipping setting working directory as safe directory" | ||
else | ||
echo "Setting git safe.directory default: $INPUT_REPOSITORY ..." | ||
git config --global --add safe.directory "$INPUT_REPOSITORY" | ||
fi | ||
|
||
# Initialize the command variable | ||
command="trestlebot-create-cd \ | ||
--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}\" \ | ||
--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}\" \ | ||
--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}\" \ | ||
--target-branch=\"${INPUT_TARGET_BRANCH}\"" | ||
|
||
# Conditionally include flags | ||
if [[ ${INPUT_VERBOSE} == true ]]; then | ||
command+=" --verbose" | ||
fi | ||
|
||
# Only set the token value when is a target branch so pull requests can be created | ||
if [[ -n ${INPUT_TARGET_BRANCH} ]]; then | ||
if [[ -z ${GITHUB_TOKEN} ]]; then | ||
echo "Set the GITHUB_TOKEN env variable." | ||
exit 1 | ||
fi | ||
|
||
command+=" --with-token - <<<\"${GITHUB_TOKEN}\"" | ||
fi | ||
|
||
exec 3>&1 | ||
output=$(eval "$command" > >(tee /dev/fd/3) 2>&1) | ||
|
||
commit=$(echo "$output" | grep "Commit Hash:" | sed 's/.*: //') | ||
|
||
if [ -n "$commit" ]; then | ||
echo "changes=true" >> "$GITHUB_OUTPUT" | ||
echo "commit=$commit" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "changes=false" >> "$GITHUB_OUTPUT" | ||
fi | ||
|
||
pr_number=$(echo "$output" | grep "Pull Request Number:" | sed 's/.*: //') | ||
|
||
if [ -n "$pr_number" ]; then | ||
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.