Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #38 - Adds format option #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
1 change: 1 addition & 0 deletions scripts/local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand Down