From 5b2009a5f2993d7ead6e41854b9849d7f326417d Mon Sep 17 00:00:00 2001 From: Lee Hull Date: Fri, 15 Mar 2024 17:29:48 -0400 Subject: [PATCH 1/4] Added format option --- action.yaml | 5 +++++ entrypoint.sh | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/action.yaml b/action.yaml index 2e9bd38..20d2d15 100644 --- a/action.yaml +++ b/action.yaml @@ -21,6 +21,11 @@ inputs: description: | Rule IDs or names to exclude. This can be a space or newline-separated list. required: false + format: + description: | + Set the output format + required: false + default: json include: description: | Custom rule and configuration paths passed in to the Regula interpreter. This can diff --git a/entrypoint.sh b/entrypoint.sh index ced1aa3..3208ea5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -25,6 +25,10 @@ for EXCLUDE in ${INPUT_EXCLUDE:-}; do REGULA_OPTS+=("--exclude" ${EXCLUDE}) done +if [[ -v INPUT_FORMAT && -n "${INPUT_FORMAT}" ]]; then + REGULA_OPTS+=("--format" ${FORMAT}) +fi + for REGO_PATH in ${INPUT_REGO_PATHS:-} ${INPUT_INCLUDE:-}; do # Ignore old location of regula rules for backwards compatibility if [[ "${REGO_PATH}" == "/opt/regula/rules" ]]; then @@ -73,7 +77,7 @@ if [[ -v DEBUG && -n "${DEBUG}" ]]; then fi EXIT_CODE=0 -REGULA_OUTPUT=$(cd "$GITHUB_WORKSPACE" && regula run -f json ${REGULA_OPTS[@]} $INPUT_PATH) || +REGULA_OUTPUT=$(cd "$GITHUB_WORKSPACE" && regula run ${REGULA_OPTS[@]} $INPUT_PATH) || EXIT_CODE=$? echo "${REGULA_OUTPUT}" From 296b92c22932480f4027d478abcda691a335efd6 Mon Sep 17 00:00:00 2001 From: Lee Hull Date: Fri, 15 Mar 2024 17:34:04 -0400 Subject: [PATCH 2/4] Fixed format --- entrypoint.sh | 2 +- scripts/local.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3208ea5..5451472 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -26,7 +26,7 @@ for EXCLUDE in ${INPUT_EXCLUDE:-}; do done if [[ -v INPUT_FORMAT && -n "${INPUT_FORMAT}" ]]; then - REGULA_OPTS+=("--format" ${FORMAT}) + REGULA_OPTS+=("--format" ${INPUT_FORMAT}) fi for REGO_PATH in ${INPUT_REGO_PATHS:-} ${INPUT_INCLUDE:-}; do diff --git a/scripts/local.sh b/scripts/local.sh index 46a5c06..bb9e423 100755 --- a/scripts/local.sh +++ b/scripts/local.sh @@ -32,6 +32,7 @@ docker run --rm \ -e "INPUT_CONFIG=${CONFIG}" \ -e "INPUT_ENVIRONMENT_ID=${ENVIRONMENT_ID}" \ -e "INPUT_EXCLUDE=${EXCLUDE}" \ + -e "INPUT_FORMAT=${FORMAT}" \ -e "INPUT_INCLUDE=${INCLUDE}" \ -e "INPUT_INPUT_TYPE=${INPUT_TYPE}" \ -e "INPUT_USER_ONLY=${USER_ONLY:-false}" \ From a7893b37eaaa4526de0c5147e89c5d4bf03863e5 Mon Sep 17 00:00:00 2001 From: Lee Hull Date: Fri, 15 Mar 2024 17:38:30 -0400 Subject: [PATCH 3/4] ignore json output if not json --- entrypoint.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 5451472..803d42c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -81,8 +81,10 @@ REGULA_OUTPUT=$(cd "$GITHUB_WORKSPACE" && regula run ${REGULA_OPTS[@]} $INPUT_PA EXIT_CODE=$? echo "${REGULA_OUTPUT}" -RULES_PASSED="$(jq -r '.summary.rule_results.PASS' <<<"$REGULA_OUTPUT")" -RULES_FAILED="$(jq -r '.summary.rule_results.FAIL' <<<"$REGULA_OUTPUT")" -echo "rules_passed=$RULES_PASSED" >>$GITHUB_OUTPUT -echo "rules_failed=$RULES_FAILED" >>$GITHUB_OUTPUT +if [[ "${INPUT_FORMAT}" == "json" ]]; then + RULES_PASSED="$(jq -r '.summary.rule_results.PASS' <<<"$REGULA_OUTPUT")" + RULES_FAILED="$(jq -r '.summary.rule_results.FAIL' <<<"$REGULA_OUTPUT")" + echo "rules_passed=$RULES_PASSED" >>$GITHUB_OUTPUT + echo "rules_failed=$RULES_FAILED" >>$GITHUB_OUTPUT +fi exit ${EXIT_CODE} From 9a72033a76e9321ae7293894eda224b08607354f Mon Sep 17 00:00:00 2001 From: Lee Hull Date: Fri, 15 Mar 2024 17:39:45 -0400 Subject: [PATCH 4/4] Removed json default to allow config to read format --- action.yaml | 1 - entrypoint.sh | 1 - 2 files changed, 2 deletions(-) diff --git a/action.yaml b/action.yaml index 20d2d15..a4f3cce 100644 --- a/action.yaml +++ b/action.yaml @@ -25,7 +25,6 @@ inputs: description: | Set the output format required: false - default: json include: description: | Custom rule and configuration paths passed in to the Regula interpreter. This can diff --git a/entrypoint.sh b/entrypoint.sh index 803d42c..1c742d7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -71,7 +71,6 @@ if [[ -v INPUT_UPLOAD && "${INPUT_UPLOAD}" == "true" ]]; then REGULA_OPTS+=("--upload") fi - if [[ -v DEBUG && -n "${DEBUG}" ]]; then echo ${REGULA_OPTS[@]} $INPUT_PATH fi