diff --git a/.mega-linter.yml b/.mega-linter.yml index 0198cf7..1a0ee0d 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -10,4 +10,4 @@ ENABLE_LINTERS: - MARKDOWN_MARKDOWNLINT - MAKEFILE_CHECKMAKE -REPOSITORY_KICS_DISABLE_ERRORS_IF_LESS_THAN: 3 \ No newline at end of file +REPOSITORY_KICS_DISABLE_ERRORS_IF_LESS_THAN: 4 \ No newline at end of file diff --git a/Containerfile b/Containerfile index e1190a6..d324160 100644 --- a/Containerfile +++ b/Containerfile @@ -21,6 +21,8 @@ COPY --from=build /demo /demo WORKDIR /demo +USER root + RUN ./scripts/install.sh install_demo_utils -USER guest +USER 1001 \ No newline at end of file diff --git a/scripts/auto-commit-push.sh b/scripts/auto-commit-push.sh index 73cd36d..d1e13b2 100644 --- a/scripts/auto-commit-push.sh +++ b/scripts/auto-commit-push.sh @@ -12,9 +12,9 @@ function clone_repo() { # Function to commit changes locally in git function local_commit () { local COMMIT_MESSAGE="${1:-"chore: automatic content update"}" - local COMMIT_USER="${2:-"github-actions[bot]"}" - local COMMIT_EMAIL="${3:-"github-actions@github.com"}" - local COMMIT_AUTHOR="${4:-"github-actions[bot] "}" + local COMMIT_AUTHOR="${2:-"github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"}" + local COMMIT_USER="${3:-"github-actions[bot]"}" + local COMMIT_EMAIL="${4:-"41898282+github-actions[bot]@users.noreply.github.com"}" git -c user.name="$COMMIT_USER" -c user.email="$COMMIT_EMAIL" \ commit -m "$COMMIT_MESSAGE" --author "$COMMIT_AUTHOR" @@ -39,9 +39,9 @@ function push_to_remote() { # Function to create a new branch and GitHub pull request function create_branch_pull_request() { - local PR_TITLE="${1:-"chore: sync OSCAL content"}" - local PR_BODY="${2:-"chore: automatic content update"}" - local BRANCH="${3:?"branch is required"}" + local BRANCH="${1:?"branch is required"}" + local PR_TITLE="${2:-"chore: sync OSCAL content"}" + local PR_BODY="${3:-"chore: automatic content update"}" push_to_remote "$BRANCH" gh pr create -t "$PR_TITLE" -b "$PR_BODY" -B "main" -H "$BRANCH" --draft } diff --git a/scripts/trestle.sh b/scripts/trestle.sh index 804ded8..dc21c2e 100755 --- a/scripts/trestle.sh +++ b/scripts/trestle.sh @@ -4,7 +4,6 @@ TRESTLE_IMAGE="localhost:5000/trestle-demo" TRESTLE_IMAGE_TAG="latest" TRESTLE_CMD_IMAGE="trestle" -PANDOC_CMD_IMAGE="/demo/bin/pandoc" PYTHON_CMD_IMAGE="python" CONTAINER_CMD=$(command -pv podman || command -pv docker) @@ -14,14 +13,14 @@ if [ "$TRESTLE_IMAGE_EXISTS" == "0" ]; then # the trestle image exists, use it by creating wrapper functions function trestle { - ARGS=$@ - CMD="$CONTAINER_CMD run -it --rm -w /demo/trestle-workspace -v $(pwd):/demo/trestle-workspace $TRESTLE_IMAGE:$TRESTLE_IMAGE_TAG $TRESTLE_CMD_IMAGE $@" + ARGS=$* + CMD="$CONTAINER_CMD run -it --rm -w /demo/trestle-workspace -v $(pwd):/demo/trestle-workspace $TRESTLE_IMAGE:$TRESTLE_IMAGE_TAG $TRESTLE_CMD_IMAGE $ARGS" bash -c "$CMD" } function python { - ARGS=$@ - CMD="$CONTAINER_CMD run -it --rm -w /demo/trestle-workspace -v $(pwd):/demo/trestle-workspace $TRESTLE_IMAGE:$TRESTLE_IMAGE_TAG $PYTHON_CMD_IMAGE $@" + ARGS=$* + CMD="$CONTAINER_CMD run -it --rm -w /demo/trestle-workspace -v $(pwd):/demo/trestle-workspace $TRESTLE_IMAGE:$TRESTLE_IMAGE_TAG $PYTHON_CMD_IMAGE $ARGS" bash -c "$CMD" } fi diff --git a/scripts/update-from-upstream.sh b/scripts/update-from-upstream.sh index d674eab..0088c52 100644 --- a/scripts/update-from-upstream.sh +++ b/scripts/update-from-upstream.sh @@ -25,13 +25,15 @@ function main() { DEFAULT_INCLUDE_DIRS=() BRANCH="" REPO_URL="" + AUTHOR="" patterns=() # Parse command line options - while getopts ":b:r:p:i:" opt; do + while getopts ":b:r:a:p:i:" opt; do case $opt in b) BRANCH="$OPTARG";; r) REPO_URL="$OPTARG";; + a) AUTHOR="$OPTARG";; p) patterns+=("$OPTARG");; i) include_dirs+=("$OPTARG");; \?) echo "Invalid option -$OPTARG" >&2; exit 1;; @@ -40,7 +42,7 @@ function main() { # Check if required arguments are provided if [ -z "$BRANCH" ] || [ -z "$REPO_URL" ] || [ ${#patterns[@]} -eq 0 ]; then - echo "Usage: update-from-upstream.sh -b branch -r repo_url -p pattern1 -p pattern2 ... [-i include_dir1] [-i include_dir2] ..." + echo "Usage: update-from-upstream.sh -b branch -r repo_url -a author -p pattern1 -p pattern2 ... [-i include_dir1] [-i include_dir2] ..." exit 1 fi @@ -83,8 +85,8 @@ function main() { add_files "${patterns[@]}" if [ -n "$(git status --untracked-files=no --porcelain)" ]; then - local_commit "$COMMIT_BODY" - create_branch_pull_request "$COMMIT_TITLE" "$COMMIT_BODY" "autoupdate_$GITHUB_RUN_ID" + local_commit "$COMMIT_BODY" "$AUTHOR" + create_branch_pull_request "autoupdate_$GITHUB_RUN_ID" "$COMMIT_TITLE" "$COMMIT_BODY" else run_log 0 "Nothing to commit." fi diff --git a/scripts/update-push.sh b/scripts/update-push.sh index 2b3bae6..c9c9696 100644 --- a/scripts/update-push.sh +++ b/scripts/update-push.sh @@ -18,18 +18,20 @@ source "$SCRIPT_DIR/logging.sh" # shellcheck disable=SC1091 source "$SCRIPT_DIR/auto-commit-push.sh" -USAGE="Usage: update-push.sh [-b branch] [-c commit_msg] " +USAGE="Usage: update-push.sh [-b branch] [-c commit_msg] [-a author] " function main() { DEFAULT_COMMIT_MSG="chore: automatic content update" BRANCH="" + AUTHOR="" # Parse command line options - while getopts ":b:c:" opt; do + while getopts ":b:c:a:" opt; do case $opt in b) BRANCH="$OPTARG";; c) commit_msg="$OPTARG";; + a) AUTHOR="$OPTARG";; \?) echo "Invalid option -$OPTARG" >&2; exit 1;; esac done @@ -53,7 +55,7 @@ function main() { add_files "${patterns[@]}" if [ -n "$(git status --untracked-files=no --porcelain)" ]; then - local_commit "$COMMIT_BODY" + local_commit "$COMMIT_BODY" "$AUTHOR" push_to_remote "$BRANCH" else run_log 0 "Nothing to commit." diff --git a/scripts/update.sh b/scripts/update.sh index e9e83a1..a1d4471 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -18,16 +18,18 @@ source "$SCRIPT_DIR/logging.sh" # shellcheck disable=SC1091 source "$SCRIPT_DIR/auto-commit-push.sh" -USAGE="Usage: update.sh [-c commit_msg] " +USAGE="Usage: update.sh [-c commit_msg] [-a author] " function main() { DEFAULT_COMMIT_MSG="chore: automatic content update" + AUTHOR="" # Parse command line options - while getopts ":c:" opt; do + while getopts ":c:a:" opt; do case $opt in c) commit_msg="$OPTARG";; + a) AUTHOR="$OPTARG";; \?) echo "Invalid option -$OPTARG" >&2; exit 1;; esac done @@ -57,8 +59,8 @@ function main() { if [ -z "$(git status --untracked-files=no --porcelain)" ]; then run_log 0 "Nothing to commit" else - local_commit "$COMMIT_BODY" - create_branch_pull_request "$COMMIT_TITLE" "$COMMIT_BODY" "autoupdate_$GITHUB_RUN_ID" + local_commit "$COMMIT_BODY" "$AUTHOR" + create_branch_pull_request "autoupdate_$GITHUB_RUN_ID" "$COMMIT_TITLE" "$COMMIT_BODY" fi fi }