First pass at log functions

This commit is contained in:
Eric Nemchik 2020-07-27 16:20:06 -05:00
parent 9fc054ab16
commit af13245484
6 changed files with 160 additions and 209 deletions

View file

@ -52,9 +52,8 @@ ValidateInput() {
# Validate GITHUB_WORKSPACE #
############################
if [ -z "${GITHUB_WORKSPACE}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_WORKSPACE]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_WORKSPACE}]${NC}"
exit 1
error "Failed to get [GITHUB_WORKSPACE]!${NC}"
fatal "[${GITHUB_WORKSPACE}]${NC}"
else
echo "Successfully found:[GITHUB_WORKSPACE], value:[${GITHUB_WORKSPACE}]"
fi
@ -64,15 +63,14 @@ ValidateInput() {
#######################
if [ -z "${IMAGE_REPO}" ]; then
# No repo was pulled
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [IMAGE_REPO]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${IMAGE_REPO}]${NC}"
exit 1
error "Failed to get [IMAGE_REPO]!${NC}"
fatal "[${IMAGE_REPO}]${NC}"
elif [[ ${IMAGE_REPO} == "github/super-linter" ]]; then
# Found our main repo
echo "Successfully found:[IMAGE_REPO], value:[${IMAGE_REPO}]"
else
# This is a fork and we cant pull vars or any info
echo -e "${NC}${F[Y]}WARN!${NC} No image to cleanup as this is a forked branch, and not being built with current automation!${NC}"
warn "No image to cleanup as this is a forked branch, and not being built with current automation!${NC}"
exit 0
fi
@ -80,9 +78,8 @@ ValidateInput() {
# Validate IMAGE_VERSION #
##########################
if [ -z "${IMAGE_VERSION}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [IMAGE_VERSION]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${IMAGE_VERSION}]${NC}"
exit 1
error "Failed to get [IMAGE_VERSION]!${NC}"
fatal "[${IMAGE_VERSION}]${NC}"
else
echo "Successfully found:[IMAGE_VERSION], value:[${IMAGE_VERSION}]"
fi
@ -91,9 +88,8 @@ ValidateInput() {
# Validate DOCKER_USERNAME #
############################
if [ -z "${DOCKER_USERNAME}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKER_USERNAME]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${DOCKER_USERNAME}]${NC}"
exit 1
error "Failed to get [DOCKER_USERNAME]!${NC}"
fatal "[${DOCKER_USERNAME}]${NC}"
else
echo "Successfully found:[DOCKER_USERNAME], value:[${DOCKER_USERNAME}]"
fi
@ -102,9 +98,8 @@ ValidateInput() {
# Validate DOCKER_PASSWORD #
############################
if [ -z "${DOCKER_PASSWORD}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKER_PASSWORD]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${DOCKER_PASSWORD}]${NC}"
exit 1
error "Failed to get [DOCKER_PASSWORD]!${NC}"
fatal "[${DOCKER_PASSWORD}]${NC}"
else
echo "Successfully found:[DOCKER_PASSWORD], value:[********]"
fi
@ -121,10 +116,9 @@ ValidateInput() {
#############################################
# Image is 'latest' and we will not destroy #
#############################################
echo "Image Tag is set to:[latest]..."
echo "We will never destroy latest..."
echo "Bye!"
exit 1
error "Image Tag is set to:[latest]..."
error "We will never destroy latest..."
fatal "Bye!"
fi
}
################################################################################
@ -154,9 +148,8 @@ LoginToDocker() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# ERROR
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to authenticate to DockerHub!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${LOGIN_CMD}]${NC}"
exit 1
error "Failed to authenticate to DockerHub!${NC}"
fatal "[${LOGIN_CMD}]${NC}"
else
# SUCCESS
echo "Successfully authenticated to DockerHub!"
@ -193,9 +186,8 @@ RemoveImage() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# ERROR
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to gain token from DockerHub!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${TOKEN}]${NC}"
exit 1
error "Failed to gain token from DockerHub!${NC}"
fatal "[${TOKEN}]${NC}"
else
# SUCCESS
echo "Successfully gained auth token from DockerHub!"
@ -218,9 +210,8 @@ RemoveImage() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# ERROR
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to remove tag from DockerHub!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${REMOVE_CMD}]${NC}"
exit 1
error "Failed to remove tag from DockerHub!${NC}"
fatal "[${REMOVE_CMD}]${NC}"
else
# SUCCESS
echo "Successfully [removed] Docker image tag:[${IMAGE_VERSION}] from DockerHub!"

View file

@ -53,8 +53,8 @@ CheckGHEPid()
# Check the shell for errors #
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to sleep!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${SLEEP_CMD}]${NC}"
error "Failed to sleep!${NC}"
error "[${SLEEP_CMD}]${NC}"
echo "Will try to call apply as last effort..."
####################################
# Call config apply as last effort #
@ -117,8 +117,8 @@ CheckGHEProcess()
# Check the shell for errors #
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to sleep!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${SLEEP_CMD}]${NC}"
error "Failed to sleep!${NC}"
error "[${SLEEP_CMD}]${NC}"
echo "Will try to call apply as last effort..."
####################################
# Call config apply as last effort #
@ -161,12 +161,11 @@ RunConfigApply()
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# Errors
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to run config apply command!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${APPLY_CMD}]${NC}"
exit 1
error "Failed to run config apply command!${NC}"
fatal "[${APPLY_CMD}]${NC}"
else
# Success
echo -e "${NC}${F[B]}Successfully ran ${F[C]}${GHE_APPLY_COMMAND}${NC}"
notice "Successfully ran ${F[C]}${GHE_APPLY_COMMAND}${NC}"
fi
}
################################################################################

View file

@ -58,22 +58,20 @@ ValidateInput() {
# Validate GITHUB_WORKSPACE #
#############################
if [ -z "${GITHUB_WORKSPACE}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_WORKSPACE]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_WORKSPACE}]${NC}"
exit 1
error "Failed to get [GITHUB_WORKSPACE]!${NC}"
fatal "[${GITHUB_WORKSPACE}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]${NC}"
notice "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]${NC}"
fi
#####################
# Validate REGISTRY #
#####################
if [ -z "${REGISTRY}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [REGISTRY]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${REGISTRY}]${NC}"
exit 1
error "Failed to get [REGISTRY]!${NC}"
fatal "[${REGISTRY}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[REGISTRY]${F[B]}, value:${F[W]}[${REGISTRY}]${NC}"
notice "Successfully found:${F[W]}[REGISTRY]${F[B]}, value:${F[W]}[${REGISTRY}]${NC}"
fi
#####################################################
@ -84,22 +82,20 @@ ValidateInput() {
# Validate GPR_USERNAME #
#########################
if [ -z "${GPR_USERNAME}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GPR_USERNAME]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GPR_USERNAME}]${NC}"
exit 1
error "Failed to get [GPR_USERNAME]!${NC}"
fatal "[${GPR_USERNAME}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[GPR_USERNAME]${F[B]}, value:${F[W]}[${GPR_USERNAME}]${NC}"
notice "Successfully found:${F[W]}[GPR_USERNAME]${F[B]}, value:${F[W]}[${GPR_USERNAME}]${NC}"
fi
######################
# Validate GPR_TOKEN #
######################
if [ -z "${GPR_TOKEN}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GPR_TOKEN]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GPR_TOKEN}]${NC}"
exit 1
error "Failed to get [GPR_TOKEN]!${NC}"
fatal "[${GPR_TOKEN}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[GPR_TOKEN]${F[B]}, value:${F[W]}[********]${NC}"
notice "Successfully found:${F[W]}[GPR_TOKEN]${F[B]}, value:${F[W]}[********]${NC}"
fi
########################################
# See if we need values for Ducker hub #
@ -109,41 +105,37 @@ ValidateInput() {
# Validate DOCKER_USERNAME #
############################
if [ -z "${DOCKER_USERNAME}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKER_USERNAME]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${DOCKER_USERNAME}]${NC}"
exit 1
error "Failed to get [DOCKER_USERNAME]!${NC}"
fatal "[${DOCKER_USERNAME}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[DOCKER_USERNAME]${F[B]}, value:${F[W]}[${DOCKER_USERNAME}]${NC}"
notice "Successfully found:${F[W]}[DOCKER_USERNAME]${F[B]}, value:${F[W]}[${DOCKER_USERNAME}]${NC}"
fi
############################
# Validate DOCKER_PASSWORD #
############################
if [ -z "${DOCKER_PASSWORD}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKER_PASSWORD]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${DOCKER_PASSWORD}]${NC}"
exit 1
error "Failed to get [DOCKER_PASSWORD]!${NC}"
fatal "[${DOCKER_PASSWORD}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[DOCKER_PASSWORD]${F[B]}, value:${F[B]}[********]${NC}"
notice "Successfully found:${F[W]}[DOCKER_PASSWORD]${F[B]}, value:${F[B]}[********]${NC}"
fi
###########################################
# We were not passed a registry to update #
###########################################
else
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find a valid registry!${NC}"
echo "Registry:[${REGISTRY}]"
exit 1
error "Failed to find a valid registry!${NC}"
fatal "Registry:[${REGISTRY}]"
fi
#######################
# Validate IMAGE_REPO #
#######################
if [ -z "${IMAGE_REPO}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [IMAGE_REPO]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${IMAGE_REPO}]${NC}"
exit 1
error "Failed to get [IMAGE_REPO]!${NC}"
fatal "[${IMAGE_REPO}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[IMAGE_REPO]${F[B]}, value:${F[W]}[${IMAGE_REPO}]${NC}"
notice "Successfully found:${F[W]}[IMAGE_REPO]${F[B]}, value:${F[W]}[${IMAGE_REPO}]${NC}"
###############################################
# Need to see if GPR registry and update name #
###############################################
@ -158,7 +150,7 @@ ValidateInput() {
# Validate IMAGE_VERSION #
##########################
if [ -z "${IMAGE_VERSION}" ]; then
echo -e "${NC}${F[Y]}WARN!${NC} Failed to get [IMAGE_VERSION]!${NC}"
warn "Failed to get [IMAGE_VERSION]!${NC}"
echo "Pulling from Branch Name..."
##############################
# Get the name of the branch #
@ -174,9 +166,8 @@ ValidateInput() {
# Check the shell for errors #
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get branch name!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${BRANCH_NAME}]${NC}"
exit 1
error "Failed to get branch name!${NC}"
fatal "[${BRANCH_NAME}]${NC}"
fi
##################################
@ -190,7 +181,7 @@ ValidateInput() {
IMAGE_VERSION="${BRANCH_NAME}"
echo "Tag:[${IMAGE_VERSION}]"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[IMAGE_VERSION]${F[B]}, value:${F[W]}[${IMAGE_VERSION}]${NC}"
notice "Successfully found:${F[W]}[IMAGE_VERSION]${F[B]}, value:${F[W]}[${IMAGE_VERSION}]${NC}"
fi
##################################
@ -221,11 +212,10 @@ ValidateInput() {
# Validate DOCKERFILE_PATH #
############################
if [ -z "${DOCKERFILE_PATH}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKERFILE_PATH]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${DOCKERFILE_PATH}]${NC}"
exit 1
error "Failed to get [DOCKERFILE_PATH]!${NC}"
fatal "[${DOCKERFILE_PATH}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[DOCKERFILE_PATH]${F[B]}, value:${F[W]}[${DOCKERFILE_PATH}]${NC}"
notice "Successfully found:${F[W]}[DOCKERFILE_PATH]${F[B]}, value:${F[W]}[${DOCKERFILE_PATH}]${NC}"
fi
}
################################################################################
@ -263,12 +253,11 @@ Authenticate() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# ERROR
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to authenticate to ${NAME}!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${LOGIN_CMD}]${NC}"
exit 1
else
error "Failed to authenticate to ${NAME}!${NC}"
fatal "[${LOGIN_CMD}]${NC}"
fatal else
# SUCCESS
echo -e "${NC}${F[B]}Successfully authenticated to ${F[C]}${NAME}${F[B]}!${NC}"
notice "Successfully authenticated to ${F[C]}${NAME}${F[B]}!${NC}"
fi
}
################################################################################
@ -288,10 +277,9 @@ BuildImage() {
################################
if [ ! -f "${DOCKERFILE_PATH}" ]; then
# No file found
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to find Dockerfile at:[${DOCKERFILE_PATH}]${NC}"
echo "Please make sure you give full path!"
echo "Example:[/configs/Dockerfile] or [Dockerfile] if at root directory"
exit 1
error "failed to find Dockerfile at:[${DOCKERFILE_PATH}]${NC}"
error "Please make sure you give full path!"
fatal "Example:[/configs/Dockerfile] or [Dockerfile] if at root directory"
fi
###################
@ -309,11 +297,10 @@ BuildImage() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# ERROR
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to [build] Dockerfile!${NC}"
exit 1
fatal "failed to [build] Dockerfile!${NC}"
else
# SUCCESS
echo -e "${NC}${F[B]}Successfully Built image!${NC}"
notice "Successfully Built image!${NC}"
fi
########################################################
@ -333,11 +320,10 @@ BuildImage() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# ERROR
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to [tag] Dockerfile!${NC}"
exit 1
fatal "failed to [tag] Dockerfile!${NC}"
else
# SUCCESS
echo -e "${NC}${F[B]}Successfully tagged image!${NC}"
notice "Successfully tagged image!${NC}"
fi
fi
}
@ -368,11 +354,10 @@ UploadImage() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# ERROR
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to [upload] Dockerfile!${NC}"
exit 1
fatal "failed to [upload] Dockerfile!${NC}"
else
# SUCCESS
echo -e "${NC}${F[B]}Successfully Uploaded Docker image:${F[W]}[${IMAGE_VERSION}]${F[B]} to ${F[C]}${REGISTRY}${F[B]}!${NC}"
notice "Successfully Uploaded Docker image:${F[W]}[${IMAGE_VERSION}]${F[B]} to ${F[C]}${REGISTRY}${F[B]}!${NC}"
fi
#########################
@ -391,9 +376,8 @@ UploadImage() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# ERROR
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get information about built Image!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GET_INFO_CMD}]${NC}"
exit 1
error "Failed to get information about built Image!${NC}"
fatal "[${GET_INFO_CMD}]${NC}"
else
################
# Get the data #
@ -434,11 +418,10 @@ UploadImage() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# ERROR
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to [upload] MAJOR_TAG:[${MAJOR_TAG}] Dockerfile!${NC}"
exit 1
fatal "failed to [upload] MAJOR_TAG:[${MAJOR_TAG}] Dockerfile!${NC}"
else
# SUCCESS
echo -e "${NC}${F[B]}Successfully Uploaded TAG:${F[W]}[${MAJOR_TAG}]${F[B]} of Docker image to ${F[C]}${REGISTRY}${F[B]}!${NC}"
notice "Successfully Uploaded TAG:${F[W]}[${MAJOR_TAG}]${F[B]} of Docker image to ${F[C]}${REGISTRY}${F[B]}!${NC}"
fi
fi
}
@ -488,9 +471,8 @@ else
#########
# ERROR #
#########
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Registry not set correctly!${NC}"
echo "Registry:[${REGISTRY}]"
exit 1
error "Registry not set correctly!${NC}"
fatal "Registry:[${REGISTRY}]"
fi
####################

View file

@ -41,8 +41,7 @@ function BuildFileList() {
if [ ${ERROR_CODE} -ne 0 ]; then
# Error
echo "Failed to switch to ${DEFAULT_BRANCH} branch to get files changed!"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${SWITCH_CMD}]${NC}"
exit 1
fatal "[${SWITCH_CMD}]${NC}"
fi
################
@ -69,9 +68,8 @@ function BuildFileList() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# Error
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to gain a list of all files changed!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${RAW_FILE_ARRAY[*]}]${NC}"
exit 1
error "Failed to gain a list of all files changed!${NC}"
fatal "[${RAW_FILE_ARRAY[*]}]${NC}"
fi
################################################
@ -472,7 +470,7 @@ function BuildFileList() {
#######################
# It is a bash script #
#######################
echo -e "${NC}${F[Y]}WARN!${NC} Found bash script without extension:[.sh]${NC}"
warn "Found bash script without extension:[.sh]${NC}"
echo "Please update file with proper extensions."
################################
# Append the file to the array #
@ -486,7 +484,7 @@ function BuildFileList() {
#######################
# It is a Ruby script #
#######################
echo -e "${NC}${F[Y]}WARN!${NC} Found ruby script without extension:[.rb]${NC}"
warn "Found ruby script without extension:[.rb]${NC}"
echo "Please update file with proper extensions."
################################
# Append the file to the array #
@ -500,7 +498,7 @@ function BuildFileList() {
############################
# Extension was not found! #
############################
echo -e "${NC}${F[Y]} - WARN!${NC} Failed to get filetype for:[${FILE}]!${NC}"
warn "Failed to get filetype for:[${FILE}]!${NC}"
##########################################################
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
@ -526,9 +524,8 @@ function BuildFileList() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# Error
echo "Failed to switch back to branch!"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${SWITCH2_CMD}]${NC}"
exit 1
error "Failed to switch back to branch!"
fatal "[${SWITCH2_CMD}]${NC}"
fi
################
@ -536,5 +533,5 @@ function BuildFileList() {
################
echo ""
echo "----------------------------------------------"
echo -e "${NC}${F[B]}Successfully gathered list of files...${NC}"
notice "Successfully gathered list of files...${NC}"
}

View file

@ -386,12 +386,12 @@ GetLinterVersions() {
# Check the shell for errors #
##############################
if [ ${ERROR_CODE} -ne 0 ] || [ -z "${GET_VERSION_CMD[*]}" ]; then
echo -e "${NC}[${LINTER}]: ${F[Y]}WARN!${NC} Failed to get version info for:${NC}"
warn "[${LINTER}]: Failed to get version info for:${NC}"
else
##########################
# Print the version info #
##########################
echo -e "${NC}${F[B]}Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD[*]}${NC}"
notice "Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD[*]}${NC}"
fi
done
@ -474,9 +474,8 @@ GetStandardRules() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# ERROR
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to gain list of ENV vars to load!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GET_ENV_ARRAY[*]}]${NC}"
exit 1
error "Failed to gain list of ENV vars to load!${NC}"
fatal "[${GET_ENV_ARRAY[*]}]${NC}"
fi
##########################
@ -691,8 +690,7 @@ GetGitHubVars() {
fi
if [ ! -d "${GITHUB_WORKSPACE}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC} Provided volume is not a directory!${NC}"
exit 1
fatal "Provided volume is not a directory!${NC}"
fi
echo "Linting all files in mapped directory:[${DEFAULT_WORKSPACE}]"
@ -711,33 +709,30 @@ GetGitHubVars() {
# Validate we have a value #
############################
if [ -z "${GITHUB_SHA}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_SHA]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_SHA}]${NC}"
exit 1
error "Failed to get [GITHUB_SHA]!${NC}"
fatal "[${GITHUB_SHA}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]${NC}"
notice "Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[${GITHUB_SHA}]${NC}"
fi
############################
# Validate we have a value #
############################
if [ -z "${GITHUB_WORKSPACE}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_WORKSPACE]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_WORKSPACE}]${NC}"
exit 1
error "Failed to get [GITHUB_WORKSPACE]!${NC}"
fatal "[${GITHUB_WORKSPACE}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]${NC}"
notice "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]${NC}"
fi
############################
# Validate we have a value #
############################
if [ -z "${GITHUB_EVENT_PATH}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_EVENT_PATH]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_EVENT_PATH}]${NC}"
exit 1
error "Failed to get [GITHUB_EVENT_PATH]!${NC}"
fatal "[${GITHUB_EVENT_PATH}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}${NC}"
notice "Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[${GITHUB_EVENT_PATH}]${F[B]}${NC}"
fi
##################################################
@ -753,11 +748,10 @@ GetGitHubVars() {
# Validate we have a value #
############################
if [ -z "${GITHUB_ORG}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_ORG]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_ORG}]${NC}"
exit 1
error "Failed to get [GITHUB_ORG]!${NC}"
fatal "[${GITHUB_ORG}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_ORG]${F[B]}, value:${F[W]}[${GITHUB_ORG}]${NC}"
notice "Successfully found:${F[W]}[GITHUB_ORG]${F[B]}, value:${F[W]}[${GITHUB_ORG}]${NC}"
fi
#######################
@ -769,11 +763,10 @@ GetGitHubVars() {
# Validate we have a value #
############################
if [ -z "${GITHUB_REPO}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_REPO]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_REPO}]${NC}"
exit 1
error "Failed to get [GITHUB_REPO]!${NC}"
fatal "[${GITHUB_REPO}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_REPO]${F[B]}, value:${F[W]}[${GITHUB_REPO}]${NC}"
notice "Successfully found:${F[W]}[GITHUB_REPO]${F[B]}, value:${F[W]}[${GITHUB_REPO}]${NC}"
fi
fi
@ -781,16 +774,16 @@ GetGitHubVars() {
# Validate we have a value #
############################
if [ -z "${GITHUB_TOKEN}" ] && [[ ${RUN_LOCAL} == "false" ]]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_TOKEN]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_TOKEN}]${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!${NC}"
error "Failed to get [GITHUB_TOKEN]!${NC}"
error "[${GITHUB_TOKEN}]${NC}"
error "Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!${NC}"
################################################################################
# Need to set MULTI_STATUS to false as we cant hit API endpoints without token #
################################################################################
MULTI_STATUS='false'
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_TOKEN]${NC}"
notice "Successfully found:${F[W]}[GITHUB_TOKEN]${NC}"
fi
###############################
@ -806,22 +799,20 @@ GetGitHubVars() {
# Validate we have a value #
############################
if [ -z "${GITHUB_REPOSITORY}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_REPOSITORY]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_REPOSITORY}]${NC}"
exit 1
error "Failed to get [GITHUB_REPOSITORY]!${NC}"
fatal "[${GITHUB_REPOSITORY}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]${NC}"
notice "Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]${NC}"
fi
############################
# Validate we have a value #
############################
if [ -z "${GITHUB_RUN_ID}" ]; then
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_RUN_ID]!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_RUN_ID}]${NC}"
exit 1
error "Failed to get [GITHUB_RUN_ID]!${NC}"
fatal "[${GITHUB_RUN_ID}]${NC}"
else
echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]${NC}"
notice "Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]${NC}"
fi
fi
}
@ -833,16 +824,14 @@ function ValidatePowershellModules() {
if [[ ${VALIDATE_PSSA_MODULE} == "PSScriptAnalyzer" ]]; then
VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1)
else
# Failed to find module
exit 1
fatal "Failed to find module."
fi
#########################################
# validate we found the script analyzer #
#########################################
if [[ ${VALIDATE_PSSA_CMD} != "Invoke-ScriptAnalyzer" ]]; then
# Failed to find module
exit 1
fatal "Failed to find module."
fi
#######################
@ -855,14 +844,13 @@ function ValidatePowershellModules() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# Failed
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]${NC}"
exit 1
error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!${NC}"
fatal "[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]${NC}"
else
# Success
if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then
echo -e "${NC}${F[B]}Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system${NC}"
echo -e "${NC}${F[B]}Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system${NC}"
notice "Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system${NC}"
notice "Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system${NC}"
fi
fi
}
@ -944,7 +932,7 @@ Reports() {
# Prints for warnings if found #
################################
for TEST in "${WARNING_ARRAY_TEST[@]}"; do
echo -e "${NC}${F[Y]}WARN!${NC} Expected file to compare with was not found for ${TEST}${NC}"
warn "Expected file to compare with was not found for ${TEST}${NC}"
done
}
@ -981,7 +969,7 @@ Footer() {
###################
# Print the goods #
###################
echo -e "${NC}${B[R]}${F[W]}ERRORS FOUND${NC} in ${LANGUAGE}:[${!ERROR_COUNTER}]${NC}"
error "ERRORS FOUND${NC} in ${LANGUAGE}:[${!ERROR_COUNTER}]${NC}"
#########################################
# Create status API for Failed language #
@ -1000,7 +988,7 @@ Footer() {
# Exit with 0 if errors disabled #
##################################
if [ "${DISABLE_ERRORS}" == "true" ]; then
echo -e "${NC}${F[Y]}WARN!${NC} Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[${DISABLE_ERRORS}]${NC}"
warn "Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[${DISABLE_ERRORS}]${NC}"
exit 0
fi
@ -1014,8 +1002,7 @@ Footer() {
# Check if error was found
if [ "${!ERRORS_FOUND_LANGUAGE}" -ne 0 ]; then
# Failed exit
echo -e "${NC}${F[R]}Exiting with errors found!${NC}"
exit 1
fatal "Exiting with errors found!${NC}"
fi
done
@ -1023,7 +1010,7 @@ Footer() {
# Footer prints Exit 0 #
########################
echo ""
echo -e "${NC}${F[G]}All file(s) linted successfully with no errors detected${NC}"
notice "All file(s) linted successfully with no errors detected${NC}"
echo "----------------------------------------------"
echo ""
# Successful exit
@ -1057,9 +1044,8 @@ Header
##############################################################
if [ -n "${OUTPUT_FORMAT}" ]; then
if [ -d "${REPORT_OUTPUT_FOLDER}" ] ; then
echo "ERROR! Found ${REPORT_OUTPUT_FOLDER}"
echo "Please remove the folder and try again."
exit 1
error "ERROR! Found ${REPORT_OUTPUT_FOLDER}"
fatal "Please remove the folder and try again."
fi
fi

View file

@ -49,13 +49,12 @@ function LintCodebase() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# Failed
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find [${LINTER_NAME}] in system!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${VALIDATE_INSTALL_CMD}]${NC}"
exit 1
error "Failed to find [${LINTER_NAME}] in system!${NC}"
fatal "[${VALIDATE_INSTALL_CMD}]${NC}"
else
# Success
if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then
echo -e "${NC}${F[B]}Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]${NC}"
notice "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]${NC}"
fi
fi
@ -226,9 +225,9 @@ function LintCodebase() {
#########
# Error #
#########
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Found errors in [${LINTER_NAME}] linter!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${LINT_CMD}]${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC} Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}"
error "Found errors in [${LINTER_NAME}] linter!${NC}"
error "[${LINT_CMD}]${NC}"
error "Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}"
# Increment the error count
(("ERRORS_FOUND_${FILE_TYPE}++"))
@ -243,7 +242,7 @@ function LintCodebase() {
###########
# Success #
###########
echo -e "${NC}${F[B]} - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}"
notice " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}"
#######################################################
# Store the linting as a temporary file in TAP format #
@ -302,12 +301,11 @@ function TestCodebase() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# Failed
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find [${LINTER_NAME}] in system!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${VALIDATE_INSTALL_CMD}]${NC}"
exit 1
error "Failed to find [${LINTER_NAME}] in system!${NC}"
fatal "[${VALIDATE_INSTALL_CMD}]${NC}"
else
# Success
echo -e "${NC}${F[B]}Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]${NC}"
notice "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]${NC}"
fi
##########################
@ -454,16 +452,16 @@ function TestCodebase() {
#########
# Error #
#########
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Found errors in [${LINTER_NAME}] linter!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${LINT_CMD}]${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC} Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}"
error "Found errors in [${LINTER_NAME}] linter!${NC}"
error "[${LINT_CMD}]${NC}"
error "Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}"
# Increment the error count
(("ERRORS_FOUND_${FILE_TYPE}++"))
else
###########
# Success #
###########
echo -e "${NC}${F[B]} - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}"
notice " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}"
fi
#######################################################
# Store the linting as a temporary file in TAP format #
@ -482,18 +480,18 @@ function TestCodebase() {
#########
# Error #
#########
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Found errors in [${LINTER_NAME}] linter!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} This file should have failed test case!${NC}"
echo -e "${NC}${B[R]}${F[W]}Command run:${NC}[\$${LINT_CMD}]${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${LINT_CMD}]${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC} Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}"
error "Found errors in [${LINTER_NAME}] linter!${NC}"
error "This file should have failed test case!${NC}"
error "Command run:${NC}[\$${LINT_CMD}]${NC}"
error "[${LINT_CMD}]${NC}"
error "Linter CMD:[${LINTER_COMMAND} ${FILE}]${NC}"
# Increment the error count
(("ERRORS_FOUND_${FILE_TYPE}++"))
else
###########
# Success #
###########
echo -e "${NC}${F[B]} - File:${F[W]}[${FILE_NAME}]${F[B]} failed test case with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}"
notice " - File:${F[W]}[${FILE_NAME}]${F[B]} failed test case with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}"
fi
#######################################################
# Store the linting as a temporary file in TAP format #
@ -523,16 +521,16 @@ function TestCodebase() {
#############################################
# We failed to compare the reporting output #
#############################################
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to assert TAP output:[${LINTER_NAME}]${NC}"!
error "Failed to assert TAP output:[${LINTER_NAME}]${NC}"!
echo "Please validate the asserts!"
cat "${TMPFILE}"
exit 1
else
# Success
echo -e "${NC}${F[B]}Successfully validation in the expected TAP format for ${F[W]}[${LINTER_NAME}]${NC}"
notice "Successfully validation in the expected TAP format for ${F[W]}[${LINTER_NAME}]${NC}"
fi
else
echo -e "${NC}${F[Y]}WARN!${NC} No TAP expected file found at:[${EXPECTED_FILE}]${NC}"
warn "No TAP expected file found at:[${EXPECTED_FILE}]${NC}"
echo "skipping report assertions"
#####################################
# Append the file type to the array #
@ -548,9 +546,8 @@ function TestCodebase() {
#################################################
# We failed to find files and no tests were ran #
#################################################
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find any tests ran for the Linter:[${LINTER_NAME}]${NC}"!
echo "Please validate logic or that tests exist!"
exit 1
error "Failed to find any tests ran for the Linter:[${LINTER_NAME}]${NC}"!
fatal "Please validate logic or that tests exist!"
fi
}
################################################################################
@ -658,14 +655,13 @@ function LintAnsibleFiles() {
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# Failed
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find ${LINTER_NAME} in system!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${VALIDATE_INSTALL_CMD}]${NC}"
exit 1
error "Failed to find ${LINTER_NAME} in system!${NC}"
fatal "[${VALIDATE_INSTALL_CMD}]${NC}"
else
# Success
if [[ ${ACTIONS_RUNNER_DEBUG} == "true" ]]; then
# Success
echo -e "${NC}${F[B]}Successfully found binary in system${NC}"
notice "Successfully found binary in system${NC}"
echo "Location:[${VALIDATE_INSTALL_CMD}]"
fi
fi
@ -777,8 +773,8 @@ function LintAnsibleFiles() {
#########
# Error #
#########
echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Found errors in [${LINTER_NAME}] linter!${NC}"
echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${LINT_CMD}]${NC}"
error "Found errors in [${LINTER_NAME}] linter!${NC}"
error "[${LINT_CMD}]${NC}"
# Increment error count
((ERRORS_FOUND_ANSIBLE++))
@ -794,7 +790,7 @@ function LintAnsibleFiles() {
###########
# Success #
###########
echo -e "${NC}${F[B]} - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}"
notice " - File:${F[W]}[${FILE_NAME}]${F[B]} was linted with ${F[W]}[${LINTER_NAME}]${F[B]} successfully${NC}"
#######################################################
# Store the linting as a temporary file in TAP format #
@ -820,7 +816,7 @@ function LintAnsibleFiles() {
########################
# No Ansible dir found #
########################
echo -e "${NC}${F[Y]}WARN!${NC} No Ansible base directory found at:[${ANSIBLE_DIRECTORY}]${NC}"
warn "No Ansible base directory found at:[${ANSIBLE_DIRECTORY}]${NC}"
echo "skipping ansible lint"
fi
fi