diff --git a/action.yaml b/action.yaml index 2e9bd38..a4f3cce 100644 --- a/action.yaml +++ b/action.yaml @@ -21,6 +21,10 @@ 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 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..1c742d7 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" ${INPUT_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 @@ -67,18 +71,19 @@ if [[ -v INPUT_UPLOAD && "${INPUT_UPLOAD}" == "true" ]]; then REGULA_OPTS+=("--upload") fi - if [[ -v DEBUG && -n "${DEBUG}" ]]; then echo ${REGULA_OPTS[@]} $INPUT_PATH 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}" -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} 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}" \