#!/bin/bash

mkdir -p ${REPORTS_DIR}
rm -f ${REPORTS_DIR}/*
${SCRIPTS_DIR}/monitorstatus.sh -j ${CI_JOB_NAME} -s fail -r config -l "Job run in local dev"
set -o pipefail
hadolint $APPROVED_REGISTRY $SCAN_DIR/$DOCKERFILE_LOC --failure-threshold warning | tee ${REPORTS_DIR}/${CI_JOB_NAME}.out

if [ "$?" == "0" ]; then
  ${SCRIPTS_DIR}/monitorstatus.sh -j ${CI_JOB_NAME} -s pass -r pass
else
  if [ -s "${REPORTS_DIR}/${CI_JOB_NAME}.out" ]; then
    ${SCRIPTS_DIR}/monitorstatus.sh -j ${CI_JOB_NAME} -r findings -l "${CI_JOB_NAME} process found findings, check job for details"
  fi
  exit 1
fi
