mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-22 16:51:05 -05:00
Merge pull request #529 from github/BetterTests
Adding all codebase scan test
This commit is contained in:
commit
d082f4f6e4
4 changed files with 311 additions and 6 deletions
286
.automation/clean-code-base-for-tests.sh
Executable file
286
.automation/clean-code-base-for-tests.sh
Executable file
|
@ -0,0 +1,286 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
################################################################################
|
||||
############# Clean all code base for additonal testing @admiralawkbar #########
|
||||
################################################################################
|
||||
|
||||
###########
|
||||
# Globals #
|
||||
###########
|
||||
GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace
|
||||
GITHUB_SHA="${GITHUB_SHA}" # Sha used to create this branch
|
||||
TEST_FOLDER='.automation/test' # Folder where test are stored
|
||||
CLEAN_FOLDER='.automation/automation' # Folder to rename to prevent skip
|
||||
|
||||
############################
|
||||
# Source additonal scripts #
|
||||
############################
|
||||
# shellcheck source=/dev/null
|
||||
source "${GITHUB_WORKSPACE}/lib/log.sh" # Source the function script(s)
|
||||
|
||||
################################################################################
|
||||
############################ FUNCTIONS BELOW ###################################
|
||||
################################################################################
|
||||
################################################################################
|
||||
#### Function Header ###########################################################
|
||||
Header() {
|
||||
info "-------------------------------------------------------"
|
||||
info "------- GitHub Clean code base of error tests ---------"
|
||||
info "-------------------------------------------------------"
|
||||
}
|
||||
################################################################################
|
||||
#### Function CleanTestFiles ###################################################
|
||||
CleanTestFiles() {
|
||||
info "-------------------------------------------------------"
|
||||
info "Finding all tests that are supposed to fail... and removing them..."
|
||||
|
||||
##################
|
||||
# Find the files #
|
||||
##################
|
||||
mapfile -t FIND_CMD < <(cd "${GITHUB_WORKSPACE}" || exit 1 ; find "${GITHUB_WORKSPACE}" -type f -name "*_bad_*" 2>&1)
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ $ERROR_CODE -ne 0 ]; then
|
||||
error "ERROR! failed to get list of all files!"
|
||||
fatal "ERROR:[${FIND_CMD[*]}]"
|
||||
fi
|
||||
|
||||
############################################################
|
||||
# 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 #
|
||||
################################
|
||||
REMOVE_FILE_CMD=$(cd "${GITHUB_WORKSPACE}" || exit 1; rm -f "$FILE" 2>&1)
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ $ERROR_CODE -ne 0 ]; then
|
||||
error "ERROR! failed to remove file:[${FILE}]!"
|
||||
fatal "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
################################################################################
|
||||
#### Function CleanTestDockerFiles #############################################
|
||||
CleanTestDockerFiles() {
|
||||
info "-------------------------------------------------------"
|
||||
info "Finding all tests that are supposed to fail for Docker... and removing them..."
|
||||
|
||||
##################
|
||||
# Find the files #
|
||||
##################
|
||||
mapfile -t FIND_CMD < <(cd "${GITHUB_WORKSPACE}" || exit 1 ; find "${GITHUB_WORKSPACE}" -type f -name "*Dockerfile" 2>&1)
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ $ERROR_CODE -ne 0 ]; then
|
||||
error "ERROR! failed to get list of all file for Docker!"
|
||||
fatal "ERROR:[${FIND_CMD[*]}]"
|
||||
fi
|
||||
|
||||
############################################################
|
||||
# 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/docker/bad"** ]]; then
|
||||
################################
|
||||
# Its a test, we can delete it #
|
||||
################################
|
||||
REMOVE_FILE_CMD=$(cd "${GITHUB_WORKSPACE}" || exit 1; rm -f "$FILE" 2>&1)
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ $ERROR_CODE -ne 0 ]; then
|
||||
error "ERROR! failed to remove file:[${FILE}]!"
|
||||
fatal "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
################################################################################
|
||||
#### Function CleanSHAFolder ###################################################
|
||||
CleanSHAFolder() {
|
||||
info "-------------------------------------------------------"
|
||||
info "Cleaning folder named:[${GITHUB_SHA}] if it exists"
|
||||
|
||||
##################
|
||||
# Find the files #
|
||||
##################
|
||||
REMOVE_CMD=$(cd "${GITHUB_WORKSPACE}" || exit 1; sudo rm -rf "${GITHUB_SHA}" 2>&1)
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ $ERROR_CODE -ne 0 ]; then
|
||||
# Error
|
||||
error "ERROR! Failed to remove folder:[${GITHUB_SHA}]!"
|
||||
fatal "ERROR:[${REMOVE_CMD}]"
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function RenameTestFolder #################################################
|
||||
RenameTestFolder() {
|
||||
info "-------------------------------------------------------"
|
||||
info "Need to rename [tests] folder as it will be ignored..."
|
||||
|
||||
#####################
|
||||
# Rename the folder #
|
||||
#####################
|
||||
RENAME_FOLDER_CMD=$(cd "${GITHUB_WORKSPACE}" || exit 1; mv "${TEST_FOLDER}" "${CLEAN_FOLDER}" 2>&1)
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ $ERROR_CODE -ne 0 ]; then
|
||||
error "ERROR! failed to move test folder!"
|
||||
fatal "ERROR:[${RENAME_FOLDER_CMD[*]}]"
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### 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 #
|
||||
##################
|
||||
mapfile -t FIND_CMD < <(cd "${GITHUB_WORKSPACE}" || exit 1 ; find "${GITHUB_WORKSPACE}" -type f -name "*.psd1" 2>&1)
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ $ERROR_CODE -ne 0 ]; then
|
||||
error "ERROR! failed to get list of all file for *.psd1!"
|
||||
fatal "ERROR:[${FIND_CMD[*]}]"
|
||||
fi
|
||||
|
||||
############################################################
|
||||
# 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 #
|
||||
################################
|
||||
REMOVE_FILE_CMD=$(cd "${GITHUB_WORKSPACE}" || exit 1; rm -f "$FILE" 2>&1)
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ $ERROR_CODE -ne 0 ]; then
|
||||
error "ERROR! failed to remove file:[${FILE}]!"
|
||||
fatal "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
################################################################################
|
||||
################################## MAIN ########################################
|
||||
################################################################################
|
||||
|
||||
##########
|
||||
# Header #
|
||||
##########
|
||||
Header
|
||||
|
||||
####################
|
||||
# Clean test files #
|
||||
####################
|
||||
CleanTestFiles
|
||||
|
||||
###############################
|
||||
# Clean the test docker files #
|
||||
###############################
|
||||
CleanTestDockerFiles
|
||||
|
||||
###############################
|
||||
# Remove sha folder if exists #
|
||||
###############################
|
||||
CleanSHAFolder
|
||||
|
||||
##################
|
||||
# Re Name folder #
|
||||
##################
|
||||
RenameTestFolder
|
||||
|
||||
##############################
|
||||
# Clean Powershell templates #
|
||||
##############################
|
||||
CleanPowershell
|
|
@ -1,4 +1,9 @@
|
|||
resource "aws_instance" "good" {
|
||||
ami = "ami-0ff8a91507f77f867"
|
||||
instance_type = "t2.small"
|
||||
ami = "ami-0ff8a91507f77f867"
|
||||
instance_type = "t2.small"
|
||||
associate_public_ip_address = false
|
||||
|
||||
ebs_block_device {
|
||||
encrypted = true
|
||||
}
|
||||
}
|
||||
|
|
20
.github/workflows/deploy-DEV.yml
vendored
20
.github/workflows/deploy-DEV.yml
vendored
|
@ -50,9 +50,23 @@ jobs:
|
|||
shell: bash
|
||||
run: docker build --no-cache -t github/super-linter:${GITHUB_SHA} .
|
||||
|
||||
################################
|
||||
# Run Linter against code base #
|
||||
################################
|
||||
#####################################
|
||||
# Run Linter against Test code base #
|
||||
#####################################
|
||||
- name: Run Test Cases
|
||||
shell: bash
|
||||
run: docker run -e RUN_LOCAL=true -e TEST_CASE_RUN=true -e OUTPUT_FORMAT=tap -e OUTPUT_FOLDER=${GITHUB_SHA} -e OUTPUT_DETAILS=detailed -v ${GITHUB_WORKSPACE}:/tmp/lint github/super-linter:${GITHUB_SHA}
|
||||
|
||||
#########################################
|
||||
# Clean code base to run agaisnt it all #
|
||||
#########################################
|
||||
- name: Clean Test code base for additional testing
|
||||
shell: bash
|
||||
run: .automation/clean-code-base-for-tests.sh
|
||||
|
||||
############################################
|
||||
# Run Linter against ALL cleaned code base #
|
||||
############################################
|
||||
- name: Run against all code base
|
||||
shell: bash
|
||||
run: docker run -e RUN_LOCAL=true -e OUTPUT_DETAILS=detailed -v ${GITHUB_WORKSPACE}:/tmp/lint github/super-linter:${GITHUB_SHA}
|
||||
|
|
|
@ -605,7 +605,7 @@ function RunTestCases() {
|
|||
TestCodebase "STATES" "asl-validator" "asl-validator --json-path" ".*\.\(json\)\$" "states"
|
||||
TestCodebase "SQL" "sql-lint" "sql-lint" ".*\.\(sql\)\$" "sql"
|
||||
TestCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "terraform"
|
||||
TestCodebase "TERRAFORM_TERRASCAN" "terrascan" "terrascan -f " ".*\.\(tf\)\$" "terraform_terrascan"
|
||||
TestCodebase "TERRAFORM_TERRASCAN" "terrascan" "terrascan -f" ".*\.\(tf\)\$" "terraform_terrascan"
|
||||
TestCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(ts\)\$" "typescript"
|
||||
TestCodebase "TYPESCRIPT_STANDARD" "standard" "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin ${TYPESCRIPT_STANDARD_LINTER_RULES}" ".*\.\(ts\)\$" "typescript"
|
||||
TestCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "xml"
|
||||
|
|
Loading…
Reference in a new issue