2020-08-06 14:16:23 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
############# Clean all code base for additonal testing @admiralawkbar #########
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
###########
|
|
|
|
# Globals #
|
|
|
|
###########
|
2020-11-06 17:10:09 -05:00
|
|
|
((LOG_TRACE = LOG_DEBUG = LOG_VERBOSE = LOG_NOTICE = LOG_WARN = LOG_ERROR = "true")) # Enable all loging
|
2020-10-30 21:27:20 -04:00
|
|
|
export LOG_TRACE LOG_DEBUG LOG_VERBOSE LOG_NOTICE LOG_WARN LOG_ERROR
|
2020-08-06 14:55:44 -04:00
|
|
|
|
|
|
|
############################
|
|
|
|
# Source additonal scripts #
|
|
|
|
############################
|
2020-08-06 14:32:23 -04:00
|
|
|
# shellcheck source=/dev/null
|
2020-11-12 12:27:34 -05:00
|
|
|
source "${GITHUB_WORKSPACE}/lib/functions/log.sh" # Source the function script(s)
|
2020-08-06 14:32:23 -04:00
|
|
|
|
2020-08-06 14:16:23 -04:00
|
|
|
################################################################################
|
|
|
|
############################ FUNCTIONS BELOW ###################################
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
#### Function Header ###########################################################
|
|
|
|
Header() {
|
|
|
|
info "-------------------------------------------------------"
|
|
|
|
info "------- GitHub Clean code base of error tests ---------"
|
|
|
|
info "-------------------------------------------------------"
|
|
|
|
}
|
|
|
|
################################################################################
|
2021-01-12 13:54:00 -05:00
|
|
|
#### Function CheckShellErrors #################################################
|
|
|
|
CheckShellErrors() {
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
|
|
|
error "$1"
|
|
|
|
fatal "$2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
################################################################################
|
2020-08-06 14:16:23 -04:00
|
|
|
#### Function CleanTestFiles ###################################################
|
|
|
|
CleanTestFiles() {
|
|
|
|
info "-------------------------------------------------------"
|
|
|
|
info "Finding all tests that are supposed to fail... and removing them..."
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Find the files #
|
|
|
|
##################
|
2020-11-06 17:10:09 -05:00
|
|
|
mapfile -t FIND_CMD < <(
|
|
|
|
cd "${GITHUB_WORKSPACE}" || exit 1
|
2021-01-04 12:07:57 -05:00
|
|
|
find "${GITHUB_WORKSPACE}" -type f -name "*_bad_*" -o -path "*javascript_prettier*" -name "*javascript_good*" 2>&1
|
2020-11-06 17:10:09 -05:00
|
|
|
)
|
2020-08-06 14:16:23 -04:00
|
|
|
|
2021-01-12 13:54:00 -05:00
|
|
|
CheckShellErrors "ERROR! failed to get list of all files!" "ERROR:[${FIND_CMD[*]}]"
|
2020-08-06 14:16:23 -04:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Get the directory and validate it came from tests folder #
|
|
|
|
############################################################
|
|
|
|
for FILE in "${FIND_CMD[@]}"; do
|
|
|
|
#####################
|
|
|
|
# Get the directory #
|
|
|
|
#####################
|
|
|
|
FILE_DIR=$(dirname "$FILE" 2>&1)
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Check if from the tests folder #
|
|
|
|
##################################
|
|
|
|
if [[ $FILE_DIR == **".automation/test"** ]]; then
|
|
|
|
################################
|
|
|
|
# Its a test, we can delete it #
|
|
|
|
################################
|
2020-11-06 17:10:09 -05:00
|
|
|
REMOVE_FILE_CMD=$(
|
|
|
|
cd "${GITHUB_WORKSPACE}" || exit 1
|
2021-03-24 15:00:23 -04:00
|
|
|
sudo rm -f "$FILE" 2>&1
|
2020-11-06 17:10:09 -05:00
|
|
|
)
|
2020-08-06 14:16:23 -04:00
|
|
|
|
2021-01-12 13:54:00 -05:00
|
|
|
CheckShellErrors "ERROR! failed to remove file:[${FILE}]!" "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
2020-08-06 14:16:23 -04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
#### Function CleanTestDockerFiles #############################################
|
|
|
|
CleanTestDockerFiles() {
|
|
|
|
info "-------------------------------------------------------"
|
|
|
|
info "Finding all tests that are supposed to fail for Docker... and removing them..."
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Find the files #
|
|
|
|
##################
|
2020-11-06 17:10:09 -05:00
|
|
|
mapfile -t FIND_CMD < <(
|
|
|
|
cd "${GITHUB_WORKSPACE}" || exit 1
|
2021-02-23 12:51:34 -05:00
|
|
|
find "${GITHUB_WORKSPACE}" -type f -name "*Dockerfile" -o -name "*.dockerignore" 2>&1
|
2020-11-06 17:10:09 -05:00
|
|
|
)
|
2020-08-06 14:16:23 -04:00
|
|
|
|
2021-01-12 13:54:00 -05:00
|
|
|
CheckShellErrors "ERROR! failed to get list of all file for Docker!" "ERROR:[${FIND_CMD[*]}]"
|
2020-08-06 14:16:23 -04:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Get the directory and validate it came from tests folder #
|
|
|
|
############################################################
|
|
|
|
for FILE in "${FIND_CMD[@]}"; do
|
|
|
|
#####################
|
|
|
|
# Get the directory #
|
|
|
|
#####################
|
|
|
|
FILE_DIR=$(dirname "$FILE" 2>&1)
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Check if from the tests folder #
|
|
|
|
##################################
|
2020-08-17 10:46:14 -04:00
|
|
|
if [[ $FILE_DIR != **".automation/test/docker/good"** ]]; then
|
2020-08-06 14:16:23 -04:00
|
|
|
################################
|
|
|
|
# Its a test, we can delete it #
|
|
|
|
################################
|
2020-11-06 17:10:09 -05:00
|
|
|
REMOVE_FILE_CMD=$(
|
|
|
|
cd "${GITHUB_WORKSPACE}" || exit 1
|
2021-03-24 15:00:23 -04:00
|
|
|
sudo rm -f "$FILE" 2>&1
|
2020-11-06 17:10:09 -05:00
|
|
|
)
|
2020-08-06 14:16:23 -04:00
|
|
|
|
2021-01-12 13:54:00 -05:00
|
|
|
CheckShellErrors "ERROR! failed to remove file:[${FILE}]!" "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
2020-08-06 14:16:23 -04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
################################################################################
|
2020-08-06 16:07:34 -04:00
|
|
|
#### Function CleanSHAFolder ###################################################
|
|
|
|
CleanSHAFolder() {
|
|
|
|
info "-------------------------------------------------------"
|
|
|
|
info "Cleaning folder named:[${GITHUB_SHA}] if it exists"
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Find the files #
|
|
|
|
##################
|
2020-11-06 17:10:09 -05:00
|
|
|
REMOVE_CMD=$(
|
|
|
|
cd "${GITHUB_WORKSPACE}" || exit 1
|
|
|
|
sudo rm -rf "${GITHUB_SHA}" 2>&1
|
|
|
|
)
|
2020-08-06 16:07:34 -04:00
|
|
|
|
2021-01-12 13:54:00 -05:00
|
|
|
CheckShellErrors "ERROR! Failed to remove folder:[${GITHUB_SHA}]!" "ERROR:[${REMOVE_CMD}]"
|
2020-08-06 16:07:34 -04:00
|
|
|
}
|
|
|
|
################################################################################
|
2020-08-07 10:09:40 -04:00
|
|
|
#### Function CleanPowershell ##################################################
|
|
|
|
CleanPowershell() {
|
|
|
|
# Need to remove the .psd1 templates as they are formally parsed,
|
|
|
|
# and will fail with missing modules
|
|
|
|
|
|
|
|
info "-------------------------------------------------------"
|
|
|
|
info "Finding powershell template files... and removing them..."
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Find the files #
|
|
|
|
##################
|
2020-11-06 17:10:09 -05:00
|
|
|
mapfile -t FIND_CMD < <(
|
|
|
|
cd "${GITHUB_WORKSPACE}" || exit 1
|
|
|
|
find "${GITHUB_WORKSPACE}" -type f -name "*.psd1" 2>&1
|
|
|
|
)
|
2020-08-07 10:09:40 -04:00
|
|
|
|
2021-01-12 13:54:00 -05:00
|
|
|
CheckShellErrors "ERROR! failed to get list of all file for *.psd1!" "ERROR:[${FIND_CMD[*]}]"
|
2020-08-07 10:09:40 -04:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
# Get the directory and validate it came from tests folder #
|
|
|
|
############################################################
|
|
|
|
for FILE in "${FIND_CMD[@]}"; do
|
|
|
|
#####################
|
|
|
|
# Get the directory #
|
|
|
|
#####################
|
|
|
|
FILE_DIR=$(dirname "$FILE" 2>&1)
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Check if from the tests folder #
|
|
|
|
##################################
|
|
|
|
if [[ $FILE_DIR == **"TEMPLATES"** ]]; then
|
|
|
|
################################
|
|
|
|
# Its a test, we can delete it #
|
|
|
|
################################
|
2020-11-06 17:10:09 -05:00
|
|
|
REMOVE_FILE_CMD=$(
|
|
|
|
cd "${GITHUB_WORKSPACE}" || exit 1
|
2021-03-24 15:00:23 -04:00
|
|
|
sudo rm -f "$FILE" 2>&1
|
2020-11-06 17:10:09 -05:00
|
|
|
)
|
2020-08-07 10:09:40 -04:00
|
|
|
|
2021-01-12 13:54:00 -05:00
|
|
|
CheckShellErrors "ERROR! failed to remove file:[${FILE}]!" "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
2020-08-07 10:09:40 -04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
################################################################################
|
2020-08-06 14:16:23 -04:00
|
|
|
################################## MAIN ########################################
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
##########
|
|
|
|
# Header #
|
|
|
|
##########
|
|
|
|
Header
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Clean test files #
|
|
|
|
####################
|
|
|
|
CleanTestFiles
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Clean the test docker files #
|
|
|
|
###############################
|
|
|
|
CleanTestDockerFiles
|
|
|
|
|
2020-08-06 16:07:34 -04:00
|
|
|
###############################
|
|
|
|
# Remove sha folder if exists #
|
|
|
|
###############################
|
|
|
|
CleanSHAFolder
|
|
|
|
|
2020-08-07 10:09:40 -04:00
|
|
|
##############################
|
|
|
|
# Clean Powershell templates #
|
|
|
|
##############################
|
|
|
|
CleanPowershell
|