Skip to content
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
5 changes: 5 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ inputs:
description: 'skip calling the setup-trivy action to install trivy'
required: false
default: 'false'
outputs:
result:
description: "Result of the Trivy scan according to the parameters supplied. One of 'pass', 'fail'"
value: ${{ steps.trivy.outputs.result }}

runs:
using: 'composite'
Expand Down Expand Up @@ -177,6 +181,7 @@ runs:
set_env_var_if_provided "TRIVY_DOCKER_HOST" "${{ inputs.docker-host }}" ""

- name: Run Trivy
id: trivy
shell: bash
run: entrypoint.sh
env:
Expand Down
24 changes: 23 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ if [ "${TRIVY_FORMAT:-}" = "sarif" ]; then
fi
fi

# Ignore TRIVY_EXIT_CODE until formulation of action's output is finalized
export inputExitCode="$TRIVY_EXIT_CODE"
export TRIVY_EXIT_CODE=1

# Run Trivy
cmd=(trivy "$scanType" "$scanRef")
echo "Running Trivy with options: ${cmd[*]}"
Expand All @@ -54,4 +58,22 @@ if [ "${TRIVY_FORMAT:-}" = "github" ]; then
fi
fi

exit $returnCode
# return an output based on result whilst honoring exit-code input
case $inputExitCode$returnCode in
00)
echo "result=pass" >> "$GITHUB_OUTPUT" # No findings
exit 0
;;
10)
echo "result=pass" >> "$GITHUB_OUTPUT" # No findings
exit 0
;;
01)
echo "result=fail" >> "$GITHUB_OUTPUT" # Findings present but TRIVY_EXIT_CODE=0
exit 0
;;
11)
echo "result=fail" >> "$GITHUB_OUTPUT" # Findings present and TRIVY_EXIT_CODE=1
exit 1
;;
esac