|  | 
| 1 |  | -#/usr/bin/env bash | 
|  | 1 | +#!/usr/bin/env bash | 
| 2 | 2 | 
 | 
| 3 | 3 | set -euo pipefail | 
| 4 | 4 | 
 | 
| 5 |  | -spdx_ext="sbom.spdx.json" | 
| 6 |  | -cyclonedx_ext="sbom.cyclonedx.json" | 
| 7 |  | -cve_json_ext="cve-report.json" | 
| 8 |  | -cve_sarif_ext="cve-report.sarif" | 
| 9 |  | -cis_json_ext="cis-report.json" | 
|  | 5 | +readonly spdx_ext="sbom.spdx.json" | 
|  | 6 | +readonly cyclonedx_ext="sbom.cyclonedx.json" | 
|  | 7 | +readonly cve_json_ext="cve-report.json" | 
|  | 8 | +readonly cve_sarif_ext="cve-report.sarif" | 
|  | 9 | +readonly cis_json_ext="cis-report.json" | 
| 10 | 10 | 
 | 
| 11 | 11 | global_severity_cutoff='critical' | 
| 12 | 12 | global_enforce_build_failure='false' | 
| 13 | 13 | 
 | 
| 14 |  | - | 
| 15 |  | -if ([[ ${IMAGE} != '' ]] && [[ ${DIR} != '' ]]) || ([[ ${IMAGE} != '' ]] && [[ ${FILE} != '' ]]) || ([[ ${DIR} != '' ]] && [[ ${FILE} != '' ]]); then | 
|  | 14 | +if [[ -n ${IMAGE} && -n ${DIR} ]] || [[ -n ${IMAGE} && -n ${FILE} ]] || [[ -n ${DIR} && -n ${FILE} ]]; then | 
| 16 | 15 |     echo '::error ::Input fields "image", "dir" and "file" are mutually exlcusive' | 
| 17 | 16 |     exit 1 | 
| 18 | 17 | fi | 
| 19 | 18 | 
 | 
| 20 |  | -if [[ ${IMAGE} == '' ]] && [[ ${DIR} == '' ]] && [[ ${FILE} == '' ]]; then | 
|  | 19 | +if [[ -z ${IMAGE} && -z ${DIR} && -z ${FILE} ]]; then | 
| 21 | 20 |     echo '::error ::Specify one of "image", "dir" and "file" inputs fields' | 
| 22 | 21 |     exit 1 | 
| 23 | 22 | fi | 
| 24 | 23 | 
 | 
| 25 | 24 | # OCI archive should be passed as image instead of file | 
| 26 |  | -if [[ ${IMAGE} != '' ]] && [[ ${TAG} != '' ]]; then | 
| 27 |  | -    echo "scan_image=${IMAGE}:${TAG}" >> $GITHUB_OUTPUT | 
| 28 |  | -elif [[ ${IMAGE} != '' ]]; then | 
| 29 |  | -    echo "scan_image=${IMAGE}" >> $GITHUB_OUTPUT | 
|  | 25 | +if [[ -n ${IMAGE} ]]; then | 
|  | 26 | +    if [[ -n ${TAG} ]]; then | 
|  | 27 | +        echo "scan_image=${IMAGE}:${TAG}" >> $GITHUB_OUTPUT | 
|  | 28 | +    else | 
|  | 29 | +        echo "scan_image=${IMAGE}" >> $GITHUB_OUTPUT | 
|  | 30 | +    fi | 
| 30 | 31 | fi | 
| 31 | 32 | 
 | 
| 32 |  | -if [[ ${DIR} != '' ]]; then | 
|  | 33 | +if [[ -n ${DIR} ]]; then | 
| 33 | 34 |     echo "scan_dir=${DIR}" >> $GITHUB_OUTPUT | 
| 34 | 35 | fi | 
| 35 | 36 | 
 | 
| 36 |  | -if [[ ${FILE} != '' ]]; then | 
|  | 37 | +if [[ -n ${FILE} ]]; then | 
| 37 | 38 |     echo "scan_file=${FILE}" >> $GITHUB_OUTPUT | 
| 38 | 39 | fi | 
| 39 | 40 | 
 | 
| 40 |  | -if [[ ${ASSET_PREFIX} != '' ]]; then | 
|  | 41 | +if [[ -n ${ASSET_PREFIX} ]]; then | 
| 41 | 42 |     echo "sbom_spdx_file=${ASSET_PREFIX##*/}-${spdx_ext}" >> $GITHUB_OUTPUT | 
| 42 | 43 |     echo "sbom_cyclonedx_file=${ASSET_PREFIX##*/}-${cyclonedx_ext}" >> $GITHUB_OUTPUT | 
| 43 | 44 |     echo "grype_json_file=${ASSET_PREFIX##*/}-${cve_json_ext}" >> $GITHUB_OUTPUT | 
|  | 
| 51 | 52 |     echo "cis_json_file=${cis_json_ext}" >> $GITHUB_OUTPUT | 
| 52 | 53 | fi | 
| 53 | 54 | 
 | 
| 54 |  | -if [[ ${global_severity_cutoff} != '' ]]; then | 
|  | 55 | +if [[ -n ${global_severity_cutoff} ]]; then | 
| 55 | 56 |     echo "global_severity_cutoff=${global_severity_cutoff}" >> $GITHUB_OUTPUT | 
| 56 | 57 | else | 
| 57 | 58 |     echo '::error ::set global_severity_cutoff in $0' | 
| 58 | 59 |     exit 1 | 
| 59 | 60 | fi | 
| 60 | 61 | 
 | 
| 61 |  | -if [[ ${global_enforce_build_failure} != '' ]]; then | 
|  | 62 | +if [[ -n ${global_enforce_build_failure} ]]; then | 
| 62 | 63 |     echo "global_enforce_build_failure=${global_enforce_build_failure}" >> $GITHUB_OUTPUT | 
| 63 | 64 | else | 
| 64 | 65 |     echo '::error ::set global_enforce_build_failure in $0' | 
|  | 
0 commit comments