2020-06-23 12:02:45 -04:00
#!/usr/bin/env bash
2019-10-21 10:12:50 -04:00
################################################################################
2020-02-03 11:27:40 -05:00
################################################################################
2020-06-24 12:47:47 -04:00
########### Super-Linter (Lint all the code) @admiralawkbar ####################
2020-02-03 11:27:40 -05:00
################################################################################
2019-10-21 10:12:50 -04:00
################################################################################
2020-06-29 10:55:59 -04:00
#########################
# Source Function Files #
#########################
2020-06-30 10:56:15 -04:00
# shellcheck source=/dev/null
2020-07-01 17:40:40 -04:00
source /action/lib/termColors.sh # Source the function script(s)
2020-07-01 15:00:05 -04:00
# shellcheck source=/dev/null
2020-07-01 17:40:40 -04:00
source /action/lib/buildFileList.sh # Source the function script(s)
2020-06-30 10:56:15 -04:00
# shellcheck source=/dev/null
2020-07-01 17:40:40 -04:00
source /action/lib/validation.sh # Source the function script(s)
2020-06-30 10:56:15 -04:00
# shellcheck source=/dev/null
2020-07-01 17:40:40 -04:00
source /action/lib/worker.sh # Source the function script(s)
2020-06-29 10:55:59 -04:00
2019-10-21 10:12:50 -04:00
###########
2019-10-21 12:05:55 -04:00
# GLOBALS #
2019-10-21 10:12:50 -04:00
###########
2019-10-21 15:12:37 -04:00
# Default Vars
2020-07-02 17:31:16 -04:00
DEFAULT_RULES_LOCATION = '/action/lib/.automation' # Default rules files location
LINTER_RULES_PATH = " ${ LINTER_RULES_PATH :- .github/linters } " # Linter Path Directory
2019-10-21 15:12:37 -04:00
# YAML Vars
2020-07-02 17:31:16 -04:00
YAML_FILE_NAME = '.yaml-lint.yml' # Name of the file
YAML_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $YAML_FILE_NAME " # Path to the yaml lint rules
2019-10-21 15:12:37 -04:00
# MD Vars
2020-07-02 17:31:16 -04:00
MD_FILE_NAME = '.markdown-lint.yml' # Name of the file
MD_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $MD_FILE_NAME " # Path to the markdown lint rules
2019-10-21 15:12:37 -04:00
# Python Vars
2020-07-02 17:31:16 -04:00
PYTHON_FILE_NAME = '.python-lint' # Name of the file
PYTHON_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $PYTHON_FILE_NAME " # Path to the python lint rules
2020-06-19 12:41:19 -04:00
# Cloudformation Vars
2020-07-02 17:31:16 -04:00
CFN_FILE_NAME = '.cfnlintrc.yml' # Name of the file
CFN_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $CFN_FILE_NAME " # Path to the cloudformation lint rules
2019-10-21 15:12:37 -04:00
# Ruby Vars
2020-07-02 17:31:16 -04:00
RUBY_FILE_NAME = " ${ RUBY_CONFIG_FILE :- .ruby-lint.yml } " # Name of the file
RUBY_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $RUBY_FILE_NAME " # Path to the ruby lint rules
2019-10-21 15:12:37 -04:00
# Coffee Vars
2020-07-02 17:31:16 -04:00
COFFEE_FILE_NAME = '.coffee-lint.json' # Name of the file
COFFEESCRIPT_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $COFFEE_FILE_NAME " # Path to the coffeescript lint rules
2019-11-06 16:45:44 -05:00
# Javascript Vars
2020-06-26 12:49:41 -04:00
JAVASCRIPT_FILE_NAME = " ${ JAVASCRIPT_ES_CONFIG_FILE :- .eslintrc.yml } " # Name of the file
2019-11-06 16:45:44 -05:00
JAVASCRIPT_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $JAVASCRIPT_FILE_NAME " # Path to the Javascript lint rules
2020-04-02 13:42:07 -04:00
JAVASCRIPT_STANDARD_LINTER_RULES = '' # ENV string to pass when running js standard
2020-06-21 00:00:46 -04:00
# Typescript Vars
2020-06-26 12:49:41 -04:00
TYPESCRIPT_FILE_NAME = " ${ TYPESCRIPT_ES_CONFIG_FILE :- .eslintrc.yml } " # Name of the file
2020-04-02 13:42:07 -04:00
TYPESCRIPT_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $TYPESCRIPT_FILE_NAME " # Path to the Typescript lint rules
TYPESCRIPT_STANDARD_LINTER_RULES = '' # ENV string to pass when running js standard
2019-10-22 13:21:42 -04:00
# Ansible Vars
2020-07-02 17:31:16 -04:00
ANSIBLE_FILE_NAME = '.ansible-lint.yml' # Name of the file
ANSIBLE_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $ANSIBLE_FILE_NAME " # Path to the Ansible lint rules
2020-01-10 14:33:28 -05:00
# Docker Vars
2020-07-02 17:31:16 -04:00
DOCKER_FILE_NAME = '.dockerfilelintrc' # Name of the file
DOCKER_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $DOCKER_FILE_NAME " # Path to the Docker lint rules
2020-02-28 10:51:29 -05:00
# Golang Vars
2020-07-02 17:31:16 -04:00
GO_FILE_NAME = '.golangci.yml' # Name of the file
GO_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $GO_FILE_NAME " # Path to the Go lint rules
2020-03-11 15:18:21 -04:00
# Terraform Vars
2020-07-02 17:31:16 -04:00
TERRAFORM_FILE_NAME = '.tflint.hcl' # Name of the file
TERRAFORM_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $TERRAFORM_FILE_NAME " # Path to the Terraform lint rules
2020-06-19 12:13:13 -04:00
# Powershell Vars
2020-07-01 17:40:40 -04:00
POWERSHELL_FILE_NAME = '.powershell-psscriptanalyzer.psd1' # Name of the file
POWERSHELL_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $POWERSHELL_FILE_NAME " # Path to the Powershell lint rules
2020-07-02 17:31:16 -04:00
# Azure Resource Manager Vars
ARM_FILE_NAME = '.arm-ttk.psd1' # Name of the file
ARM_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $ARM_FILE_NAME " # Path to the ARM lint rules
2020-06-18 19:40:41 -04:00
# CSS Vars
2020-07-02 17:31:16 -04:00
CSS_FILE_NAME = '.stylelintrc.json' # Name of the file
CSS_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $CSS_FILE_NAME " # Path to the CSS lint rules
2020-06-25 02:13:19 -04:00
# OpenAPI Vars
2020-07-02 17:31:16 -04:00
OPENAPI_FILE_NAME = '.openapirc.yml' # Name of the file
OPENAPI_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $OPENAPI_FILE_NAME " # Path to the OpenAPI lint rules
2020-06-28 07:07:51 -04:00
# Protocol Buffers Vars
PROTOBUF_FILE_NAME = '.protolintrc.yml' # Name of the file
2020-07-02 17:31:16 -04:00
PROTOBUF_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $PROTOBUF_FILE_NAME " # Path to the Protocol Buffers lint rules
2020-06-19 14:30:28 -04:00
# Clojure Vars
2020-07-02 17:31:16 -04:00
CLOJURE_FILE_NAME = '.clj-kondo/config.edn' # Name of the file
CLOJURE_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $CLOJURE_FILE_NAME " # Path to the Clojure lint rules
2020-07-06 04:17:20 -04:00
# Dart Vars
2020-07-07 00:42:29 -04:00
DART_FILE_NAME = 'analysis_options.yaml' # Name of the file
2020-07-06 14:11:35 -04:00
DART_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $DART_FILE_NAME " # Path to the DART lint rules
2020-07-04 18:14:27 -04:00
# HTML Vars
2020-07-06 10:00:52 -04:00
HTML_FILE_NAME = '.htmlhintrc' # Name of the file
HTML_LINTER_RULES = " $DEFAULT_RULES_LOCATION / $HTML_FILE_NAME " # Path to the CSS lint rules
2020-06-18 19:40:41 -04:00
2020-01-08 14:34:05 -05:00
#######################################
# Linter array for information prints #
#######################################
LINTER_ARRAY = ( "jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
2020-07-05 22:21:13 -04:00
"pylint" "perl" "raku" "rubocop" "coffeelint" "eslint" "standard"
2020-07-02 18:30:57 -04:00
"ansible-lint" "dockerfilelint" "golangci-lint" "tflint"
2020-07-02 17:31:16 -04:00
"stylelint" "dotenv-linter" "pwsh" "arm-ttk" "ktlint" "protolint" "clj-kondo"
2020-07-06 14:11:35 -04:00
"spectral" "cfn-lint" "dart" "htmlhint" )
2020-06-29 15:24:00 -04:00
2020-04-27 15:13:12 -04:00
#############################
# Language array for prints #
#############################
2020-07-05 22:21:13 -04:00
LANGUAGE_ARRAY = ( 'YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RAKU' 'PHP' 'RUBY' 'PYTHON'
2020-07-07 09:30:16 -04:00
'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES' 'JSX' 'TSX'
2020-06-22 16:33:54 -04:00
'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM'
2020-07-06 10:00:52 -04:00
'CSS' 'ENV' 'POWERSHELL' 'ARM' 'KOTLIN' 'PROTOBUF' 'CLOJURE' 'OPENAPI'
2020-07-06 14:11:35 -04:00
'CFN' 'DART' 'HTML' )
2020-04-27 15:13:12 -04:00
2019-10-21 15:12:37 -04:00
###################
# GitHub ENV Vars #
###################
2020-07-01 17:40:40 -04:00
GITHUB_SHA = " ${ GITHUB_SHA } " # GitHub sha from the commit
GITHUB_EVENT_PATH = " ${ GITHUB_EVENT_PATH } " # Github Event Path
GITHUB_WORKSPACE = " ${ GITHUB_WORKSPACE } " # Github Workspace
2020-07-20 15:07:56 -04:00
GITHUB_TOKEN = " ${ GITHUB_TOKEN } " # GitHub Token passed from environment
GITHUB_REPOSITORY = " ${ GITHUB_REPOSITORY } " # GitHub Org/Repo passed from system
GITHUB_RUN_ID = " ${ GITHUB_RUN_ID } " # GitHub RUn ID to point to logs
2020-07-01 17:40:40 -04:00
DEFAULT_BRANCH = " ${ DEFAULT_BRANCH :- master } " # Default Git Branch to use (master by default)
2020-07-20 15:07:56 -04:00
MULTI_STATUS = " ${ MULTI_STATUS :- true } " # Multiple status are created for each check ran
2020-07-01 17:40:40 -04:00
ANSIBLE_DIRECTORY = " ${ ANSIBLE_DIRECTORY } " # Ansible Directory
VALIDATE_ALL_CODEBASE = " ${ VALIDATE_ALL_CODEBASE } " # Boolean to validate all files
2020-07-20 15:07:56 -04:00
VALIDATE_ANSIBLE = " ${ VALIDATE_ANSIBLE } " # Boolean to validate language
VALIDATE_ARM = " ${ VALIDATE_ARM } " # Boolean to validate language
VALIDATE_BASH = " ${ VALIDATE_BASH } " # Boolean to validate language
VALIDATE_CLOUDFORMATION = " ${ VALIDATE_CLOUDFORMATION } " # Boolean to validate language
VALIDATE_CLOJURE = " ${ VALIDATE_CLOJURE } " # Boolean to validate language
VALIDATE_COFFEE = " ${ VALIDATE_COFFEE } " # Boolean to validate language
VALIDATE_CSS = " ${ VALIDATE_CSS } " # Boolean to validate language
VALIDATE_DART = " ${ VALIDATE_DART } " # Boolean to validate language
VALIDATE_DOCKER = " ${ VALIDATE_DOCKER } " # Boolean to validate language
VALIDATE_EDITORCONFIG = " ${ VALIDATE_EDITORCONFIG } " # Boolean to validate files with editorconfig
VALIDATE_ENV = " ${ VALIDATE_ENV } " # Boolean to validate language
VALIDATE_GO = " ${ VALIDATE_GO } " # Boolean to validate language
VALIDATE_HTML = " ${ VALIDATE_HTML } " # Boolean to validate language
VALIDATE_JAVASCRIPT_ES = " ${ VALIDATE_JAVASCRIPT_ES } " # Boolean to validate language
VALIDATE_JAVASCRIPT_STANDARD = " ${ VALIDATE_JAVASCRIPT_STANDARD } " # Boolean to validate language
2020-07-01 17:40:40 -04:00
VALIDATE_JSON = " ${ VALIDATE_JSON } " # Boolean to validate language
2020-07-20 15:07:56 -04:00
VALIDATE_JSX = " ${ VALIDATE_JSX } " # Boolean to validate language
VALIDATE_KOTLIN = " ${ VALIDATE_KOTLIN } " # Boolean to validate language
2020-07-01 17:40:40 -04:00
VALIDATE_MD = " ${ VALIDATE_MD } " # Boolean to validate language
2020-07-20 15:07:56 -04:00
VALIDATE_OPENAPI = " ${ VALIDATE_OPENAPI } " # Boolean to validate language
2020-07-01 17:40:40 -04:00
VALIDATE_PERL = " ${ VALIDATE_PERL } " # Boolean to validate language
VALIDATE_PHP = " ${ VALIDATE_PHP } " # Boolean to validate language
2020-07-20 15:07:56 -04:00
VALIDATE_POWERSHELL = " ${ VALIDATE_POWERSHELL } " # Boolean to validate language
2020-07-01 17:40:40 -04:00
VALIDATE_PYTHON = " ${ VALIDATE_PYTHON } " # Boolean to validate language
2020-07-20 15:07:56 -04:00
VALIDATE_RAKU = " ${ VALIDATE_RAKU } " # Boolean to validate language
2020-07-01 17:40:40 -04:00
VALIDATE_RUBY = " ${ VALIDATE_RUBY } " # Boolean to validate language
2020-07-20 15:07:56 -04:00
VALIDATE_TERRAFORM = " ${ VALIDATE_TERRAFORM } " # Boolean to validate language
VALIDATE_TSX = " ${ VALIDATE_TSX } " # Boolean to validate language
2020-07-01 17:40:40 -04:00
VALIDATE_TYPESCRIPT_ES = " ${ VALIDATE_TYPESCRIPT_ES } " # Boolean to validate language
VALIDATE_TYPESCRIPT_STANDARD = " ${ VALIDATE_TYPESCRIPT_STANDARD } " # Boolean to validate language
2020-07-20 15:07:56 -04:00
VALIDATE_XML = " ${ VALIDATE_XML } " # Boolean to validate language
VALIDATE_YAML = " ${ VALIDATE_YAML } " # Boolean to validate language
2020-07-01 17:40:40 -04:00
TEST_CASE_RUN = " ${ TEST_CASE_RUN } " # Boolean to validate only test cases
DISABLE_ERRORS = " ${ DISABLE_ERRORS } " # Boolean to enable warning-only output without throwing errors
2020-02-03 15:54:43 -05:00
##############
# Debug Vars #
##############
2020-07-01 17:40:40 -04:00
RUN_LOCAL = " ${ RUN_LOCAL } " # Boolean to see if we are running locally
ACTIONS_RUNNER_DEBUG = " ${ ACTIONS_RUNNER_DEBUG :- false } " # Boolean to see even more info (debug)
2019-10-25 12:29:31 -04:00
################
# Default Vars #
################
2020-07-01 17:40:40 -04:00
DEFAULT_VALIDATE_ALL_CODEBASE = 'true' # Default value for validate all files
DEFAULT_WORKSPACE = " ${ DEFAULT_WORKSPACE :- /tmp/lint } " # Default workspace if running locally
DEFAULT_RUN_LOCAL = 'false' # Default value for debugging locally
DEFAULT_TEST_CASE_RUN = 'false' # Flag to tell code to run only test cases
DEFAULT_IFS = " $IFS " # Get the Default IFS for updating
2020-06-29 11:34:23 -04:00
###############################################################
# Default Vars that are called in Subs and need to be ignored #
###############################################################
2020-07-01 17:40:40 -04:00
DEFAULT_DISABLE_ERRORS = 'false' # Default to enabling errors
echo " ${ DEFAULT_DISABLE_ERRORS } " > /dev/null 2>& 1 || true # Workaround SC2034
RAW_FILE_ARRAY = ( ) # Array of all files that were changed
echo " ${ RAW_FILE_ARRAY [*] } " > /dev/null 2>& 1 || true # Workaround SC2034
READ_ONLY_CHANGE_FLAG = 0 # Flag set to 1 if files changed are not txt or md
echo " ${ READ_ONLY_CHANGE_FLAG } " > /dev/null 2>& 1 || true # Workaround SC2034
TEST_CASE_FOLDER = '.automation/test' # Folder for test cases we should always ignore
echo " ${ TEST_CASE_FOLDER } " > /dev/null 2>& 1 || true # Workaround SC2034
DEFAULT_ANSIBLE_DIRECTORY = " $GITHUB_WORKSPACE /ansible " # Default Ansible Directory
2020-06-30 10:56:15 -04:00
echo " ${ DEFAULT_ANSIBLE_DIRECTORY } " > /dev/null 2>& 1 || true # Workaround SC2034
2020-07-19 15:26:20 -04:00
WARNING_ARRAY_TEST = ( ) # Array of warning linters that did not have an expected test result.
echo " ${ WARNING_ARRAY_TEST [*] } " > /dev/null 2>& 1 || true # Workaround SC2034
2019-10-21 12:05:55 -04:00
2020-06-23 10:25:12 -04:00
##############
# Format #
##############
OUTPUT_FORMAT = " ${ OUTPUT_FORMAT } " # Output format to be generated. Default none
OUTPUT_FOLDER = " ${ OUTPUT_FOLDER :- super -linter.report } " # Folder where the reports are generated. Default super-linter.report
2020-07-06 13:06:58 -04:00
OUTPUT_DETAILS = " ${ OUTPUT_DETAILS :- simpler } " # What level of details. (simpler or detailed). Default simpler
2020-06-23 10:25:12 -04:00
REPORT_OUTPUT_FOLDER = " ${ DEFAULT_WORKSPACE } / ${ OUTPUT_FOLDER } "
2019-10-25 15:22:57 -04:00
##########################
# Array of changed files #
##########################
2020-07-20 15:07:56 -04:00
FILE_ARRAY_ARM = ( ) # Array of files to check
2020-07-01 17:40:40 -04:00
FILE_ARRAY_BASH = ( ) # Array of files to check
FILE_ARRAY_CFN = ( ) # Array of files to check
2020-07-20 15:07:56 -04:00
FILE_ARRAY_CLOJURE = ( ) # Array of files to check
2020-07-01 17:40:40 -04:00
FILE_ARRAY_COFFEESCRIPT = ( ) # Array of files to check
2020-07-20 15:07:56 -04:00
FILE_ARRAY_CSS = ( ) # Array of files to check
FILE_ARRAY_DART = ( ) # Array of files to check
FILE_ARRAY_DOCKER = ( ) # Array of files to check
FILE_ARRAY_ENV = ( ) # Array of files to check
FILE_ARRAY_GO = ( ) # Array of files to check
FILE_ARRAY_HTML = ( ) # Array of files to check
2020-07-01 17:40:40 -04:00
FILE_ARRAY_JAVASCRIPT_ES = ( ) # Array of files to check
FILE_ARRAY_JAVASCRIPT_STANDARD = ( ) # Array of files to check
2020-07-20 15:07:56 -04:00
FILE_ARRAY_JSON = ( ) # Array of files to check
2020-07-07 11:02:56 -04:00
FILE_ARRAY_JSX = ( ) # Array of files to check
2020-07-20 15:07:56 -04:00
FILE_ARRAY_KOTLIN = ( ) # Array of files to check
FILE_ARRAY_MD = ( ) # Array of files to check
FILE_ARRAY_OPENAPI = ( ) # Array of files to check
FILE_ARRAY_PERL = ( ) # Array of files to check
FILE_ARRAY_PHP = ( ) # Array of files to check
FILE_ARRAY_POWERSHELL = ( ) # Array of files to check
FILE_ARRAY_PROTOBUF = ( ) # Array of files to check
FILE_ARRAY_PYTHON = ( ) # Array of files to check
FILE_ARRAY_RAKU = ( ) # Array of files to check
FILE_ARRAY_RUBY = ( ) # Array of files to check
FILE_ARRAY_TERRAFORM = ( ) # Array of files to check
2020-07-07 11:02:56 -04:00
FILE_ARRAY_TSX = ( ) # Array of files to check
2020-07-01 17:40:40 -04:00
FILE_ARRAY_TYPESCRIPT_ES = ( ) # Array of files to check
FILE_ARRAY_TYPESCRIPT_STANDARD = ( ) # Array of files to check
2020-07-20 15:07:56 -04:00
FILE_ARRAY_XML = ( ) # Array of files to check
FILE_ARRAY_YML = ( ) # Array of files to check
2019-10-25 15:22:57 -04:00
2019-10-21 12:05:55 -04:00
############
# Counters #
############
2020-07-20 15:07:56 -04:00
ERRORS_FOUND_ANSIBLE = 0 # Count of errors found
ERRORS_FOUND_ARM = 0 # Count of errors found
2020-07-01 17:40:40 -04:00
ERRORS_FOUND_BASH = 0 # Count of errors found
ERRORS_FOUND_CFN = 0 # Count of errors found
2020-07-20 15:07:56 -04:00
ERRORS_FOUND_CLOJURE = 0 # Count of errors found
ERRORS_FOUND_CSS = 0 # Count of errors found
2020-07-01 17:40:40 -04:00
ERRORS_FOUND_COFFEESCRIPT = 0 # Count of errors found
2020-07-20 15:07:56 -04:00
ERRORS_FOUND_DART = 0 # Count of errors found
ERRORS_FOUND_DOCKER = 0 # Count of errors found
ERRORS_FOUND_ENV = 0 # Count of errors found
ERRORS_FOUND_GO = 0 # Count of errors found
ERRORS_FOUND_HTML = 0 # Count of errors found
2020-07-01 17:40:40 -04:00
ERRORS_FOUND_JAVASCRIPT_STANDARD = 0 # Count of errors found
ERRORS_FOUND_JAVASCRIPT_ES = 0 # Count of errors found
2020-07-20 15:07:56 -04:00
ERRORS_FOUND_JSON = 0 # Count of errors found
2020-07-07 11:25:31 -04:00
ERRORS_FOUND_JSX = 0 # Count of errors found
2020-07-20 15:07:56 -04:00
ERRORS_FOUND_KOTLIN = 0 # Count of errors found
ERRORS_FOUND_MARKDOWN = 0 # Count of errors found
ERRORS_FOUND_OPENAPI = 0 # Count of errors found
ERRORS_FOUND_PERL = 0 # Count of errors found
ERRORS_FOUND_PHP = 0 # Count of errors found
ERRORS_FOUND_POWERSHELL = 0 # Count of errors found
ERRORS_FOUND_PROTOBUF = 0 # Count of errors found
ERRORS_FOUND_PYTHON = 0 # Count of errors found
ERRORS_FOUND_RAKU = 0 # Count of errors found
ERRORS_FOUND_RUBY = 0 # Count of errors found
ERRORS_FOUND_TERRAFORM = 0 # Count of errors found
2020-07-07 11:25:31 -04:00
ERRORS_FOUND_TSX = 0 # Count of errors found
2020-07-01 17:40:40 -04:00
ERRORS_FOUND_TYPESCRIPT_STANDARD = 0 # Count of errors found
ERRORS_FOUND_TYPESCRIPT_ES = 0 # Count of errors found
2020-07-20 15:07:56 -04:00
ERRORS_FOUND_XML = 0 # Count of errors found
ERRORS_FOUND_YML = 0 # Count of errors found
2019-10-21 15:12:37 -04:00
2019-10-21 10:12:50 -04:00
################################################################################
2019-10-21 12:05:55 -04:00
########################## FUNCTIONS BELOW #####################################
2019-10-21 10:12:50 -04:00
################################################################################
################################################################################
2019-10-21 12:05:55 -04:00
#### Function Header ###########################################################
2020-07-01 17:40:40 -04:00
Header( ) {
2020-05-06 11:03:06 -04:00
###############################
# Give them the possum action #
###############################
2020-05-06 11:27:45 -04:00
/bin/bash /action/lib/possum.sh
2020-05-06 11:03:06 -04:00
##########
# Prints #
##########
2019-10-21 12:05:55 -04:00
echo ""
echo "---------------------------------------------"
2020-06-19 01:44:26 -04:00
echo "--- GitHub Actions Multi Language Linter ----"
2019-10-21 12:05:55 -04:00
echo "---------------------------------------------"
echo ""
2020-01-08 14:34:05 -05:00
echo "---------------------------------------------"
echo "The Super-Linter source code can be found at:"
echo " - https://github.com/github/super-linter"
echo "---------------------------------------------"
2019-10-21 12:05:55 -04:00
}
################################################################################
2020-01-08 14:34:05 -05:00
#### Function GetLinterVersions ################################################
2020-07-01 17:40:40 -04:00
GetLinterVersions( ) {
2020-01-08 14:34:05 -05:00
#########################
# Print version headers #
#########################
echo ""
echo "---------------------------------------------"
echo "Linter Version Info:"
##########################################################
# Go through the array of linters and print version info #
##########################################################
2020-07-01 17:40:40 -04:00
for LINTER in " ${ LINTER_ARRAY [@] } " ; do
2020-01-08 14:34:05 -05:00
###################
# Get the version #
###################
2020-07-02 17:31:16 -04:00
if [ [ " $LINTER " = = "arm-ttk" ] ] ; then
2020-07-06 09:18:09 -04:00
# Need specific command for ARM
2020-07-03 07:40:44 -04:00
mapfile -t GET_VERSION_CMD < <( grep -iE 'version' " $ARM_TTK_PSD1 " | xargs 2>& 1)
2020-07-02 17:31:16 -04:00
elif [ [ " $LINTER " = = "protolint" ] ] ; then
2020-07-06 09:18:09 -04:00
# Need specific command for Protolint
2020-07-02 17:31:16 -04:00
mapfile -t GET_VERSION_CMD < <( echo "--version not supported" )
else
2020-07-06 09:18:09 -04:00
# Standard version command
2020-07-02 17:31:16 -04:00
mapfile -t GET_VERSION_CMD < <( " $LINTER " --version 2>& 1)
fi
2020-01-08 14:34:05 -05:00
#######################
# Load the error code #
#######################
ERROR_CODE = $?
##############################
# Check the shell for errors #
##############################
2020-06-20 13:51:24 -04:00
if [ $ERROR_CODE -ne 0 ] || [ -z " ${ GET_VERSION_CMD [*] } " ] ; then
2020-07-03 08:51:00 -04:00
echo -e " ${ NC } [ $LINTER ]: ${ F [Y] } WARN! ${ NC } Failed to get version info for: ${ NC } "
2020-01-08 14:34:05 -05:00
else
##########################
# Print the version info #
##########################
2020-07-03 08:51:00 -04:00
echo -e " ${ NC } ${ F [B] } Successfully found version for ${ F [W] } [ $LINTER ] ${ F [B] } : ${ F [W] } ${ GET_VERSION_CMD [*] } ${ NC } "
2020-01-08 14:34:05 -05:00
fi
done
2020-07-06 09:18:09 -04:00
2020-07-02 17:31:16 -04:00
#########################
# Print version footers #
#########################
echo "---------------------------------------------"
echo ""
2020-01-08 14:34:05 -05:00
}
################################################################################
2019-10-21 12:05:55 -04:00
#### Function GetLinterRules ###################################################
2020-07-01 17:40:40 -04:00
GetLinterRules( ) {
2019-10-21 12:05:55 -04:00
# Need to validate the rules files exist
2020-02-03 11:27:40 -05:00
################
# Pull in vars #
################
2020-07-01 17:40:40 -04:00
LANGUAGE_NAME = " $1 " # Name of the language were looking for
2020-07-01 10:45:55 -04:00
#######################################################
# Need to create the variables for the real variables #
#######################################################
LANGUAGE_FILE_NAME = " ${ LANGUAGE_NAME } _FILE_NAME "
LANGUAGE_LINTER_RULES = " ${ LANGUAGE_NAME } _LINTER_RULES "
2020-02-03 11:27:40 -05:00
#####################################
# Validate we have the linter rules #
#####################################
2020-07-01 14:38:40 -04:00
if [ -f " $GITHUB_WORKSPACE / $LINTER_RULES_PATH / ${ !LANGUAGE_FILE_NAME } " ] ; then
2020-04-27 13:21:38 -04:00
echo "----------------------------------------------"
2020-07-01 14:38:40 -04:00
echo " User provided file:[ ${ !LANGUAGE_FILE_NAME } ], setting rules file... "
2019-10-22 13:21:42 -04:00
2020-07-01 10:45:55 -04:00
########################################
# Update the path to the file location #
########################################
2020-07-06 14:12:13 -04:00
eval " ${ LANGUAGE_LINTER_RULES } = $GITHUB_WORKSPACE / $LINTER_RULES_PATH / ${ !LANGUAGE_FILE_NAME } "
2019-10-23 10:51:13 -04:00
else
2020-02-03 11:27:40 -05:00
########################################################
# No user default provided, using the template default #
########################################################
2020-07-01 17:40:40 -04:00
if [ [ $ACTIONS_RUNNER_DEBUG = = "true" ] ] ; then
2020-07-01 14:38:40 -04:00
echo " -> Codebase does NOT have file:[ $LINTER_RULES_PATH / ${ !LANGUAGE_FILE_NAME } ], using Default rules at:[ ${ !LANGUAGE_LINTER_RULES } ] "
2020-04-27 13:21:38 -04:00
fi
2019-10-22 13:21:42 -04:00
fi
2020-02-03 11:27:40 -05:00
}
################################################################################
#### Function GetStandardRules #################################################
2020-07-01 17:40:40 -04:00
GetStandardRules( ) {
2020-04-02 13:42:07 -04:00
################
# Pull In Vars #
################
LINTER = " $1 " # Type: javascript | typescript
2020-02-03 11:27:40 -05:00
#########################################################################
# Need to get the ENV vars from the linter rules to run in command line #
#########################################################################
# Copy orig IFS to var
ORIG_IFS = " $IFS "
# Set the IFS to newline
IFS = $'\n'
2019-11-06 16:45:44 -05:00
2020-02-03 11:27:40 -05:00
#########################################
# Get list of all environment variables #
#########################################
# Only env vars that are marked as true
2020-04-02 13:42:07 -04:00
GET_ENV_ARRAY = ( )
2020-07-01 17:40:40 -04:00
if [ [ $LINTER = = "javascript" ] ] ; then
2020-06-22 09:59:31 -04:00
mapfile -t GET_ENV_ARRAY < <( yq .env " $JAVASCRIPT_LINTER_RULES " | grep true )
2020-07-01 17:40:40 -04:00
elif [ [ $LINTER = = "typescript" ] ] ; then
2020-06-22 09:59:31 -04:00
mapfile -t GET_ENV_ARRAY < <( yq .env " $TYPESCRIPT_LINTER_RULES " | grep true )
2020-04-02 13:42:07 -04:00
fi
2019-11-06 16:45:44 -05:00
2020-02-03 11:27:40 -05:00
#######################
# Load the error code #
#######################
ERROR_CODE = $?
2019-11-06 16:45:44 -05:00
2020-02-03 11:27:40 -05:00
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -ne 0 ] ; then
# ERROR
2020-07-01 16:47:24 -04:00
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 } "
2020-02-03 11:27:40 -05:00
exit 1
2019-11-06 16:45:44 -05:00
fi
2020-01-10 14:33:28 -05:00
2020-02-03 11:27:40 -05:00
##########################
# Set IFS back to normal #
##########################
# Set IFS back to Orig
IFS = " $ORIG_IFS "
2020-01-10 14:33:28 -05:00
2020-02-03 11:27:40 -05:00
######################
# Set the env string #
######################
ENV_STRING = ''
2020-01-10 14:33:28 -05:00
2020-02-03 11:27:40 -05:00
#############################
# Pull out the envs to load #
#############################
2020-07-01 17:40:40 -04:00
for ENV in " ${ GET_ENV_ARRAY [@] } " ; do
2020-02-03 11:27:40 -05:00
#############################
# remove spaces from return #
#############################
ENV = " $( echo -e " ${ ENV } " | tr -d '[:space:]' ) "
################################
# Get the env to add to string #
################################
ENV = " $( echo " ${ ENV } " | cut -d'"' -f2) "
# echo "ENV:[$ENV]"
ENV_STRING += " --env ${ ENV } "
done
2020-01-10 14:33:28 -05:00
2020-06-21 00:03:30 -04:00
#########################################
# Remove trailing and ending whitespace #
#########################################
2020-07-01 17:40:40 -04:00
if [ [ $LINTER = = "javascript" ] ] ; then
2020-04-02 13:42:07 -04:00
JAVASCRIPT_STANDARD_LINTER_RULES = " $( echo -e " ${ ENV_STRING } " | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' ) "
2020-07-01 17:40:40 -04:00
elif [ [ $LINTER = = "typescript" ] ] ; then
2020-04-02 13:42:07 -04:00
TYPESCRIPT_STANDARD_LINTER_RULES = " $( echo -e " ${ ENV_STRING } " | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' ) "
fi
2019-10-21 12:05:55 -04:00
}
2020-06-25 02:13:19 -04:00
################################################################################
#### Function DetectOpenAPIFile ################################################
2020-07-01 17:40:40 -04:00
DetectOpenAPIFile( ) {
2020-06-26 09:26:36 -04:00
################
# Pull in vars #
################
FILE = " $1 "
###############################
# Check the file for keywords #
###############################
2020-07-01 15:48:40 -04:00
grep -E '"openapi":|"swagger":|^openapi:|^swagger:' " $FILE " > /dev/null
2020-06-26 09:26:36 -04:00
#######################
# Load the error code #
#######################
ERROR_CODE = $?
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -eq 0 ] ; then
########################
# Found string in file #
########################
2020-07-01 17:40:40 -04:00
return 0
2020-06-25 02:13:19 -04:00
else
2020-06-26 09:26:36 -04:00
###################
# No string match #
###################
2020-07-01 17:40:40 -04:00
return 1
2020-06-25 02:13:19 -04:00
fi
}
2020-06-29 15:38:24 -04:00
################################################################################
2020-07-06 09:18:09 -04:00
#### Function DetectARMFile ####################################################
2020-07-06 09:29:36 -04:00
DetectARMFile( ) {
2020-07-02 17:31:16 -04:00
################
# Pull in vars #
################
2020-07-06 09:18:09 -04:00
FILE = " $1 " # Name of the file/path we are validating
2020-07-02 17:31:16 -04:00
###############################
# Check the file for keywords #
###############################
2020-07-03 07:40:44 -04:00
grep -E 'schema.management.azure.com' " $FILE " > /dev/null
2020-07-02 17:31:16 -04:00
#######################
# Load the error code #
#######################
ERROR_CODE = $?
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -eq 0 ] ; then
########################
# Found string in file #
########################
2020-07-06 09:18:09 -04:00
return 0
2020-07-02 17:31:16 -04:00
else
###################
# No string match #
###################
2020-07-06 09:18:09 -04:00
return 1
2020-07-02 17:31:16 -04:00
fi
}
################################################################################
2020-06-19 12:41:19 -04:00
#### Function DetectCloudFormationFile #########################################
2020-07-01 17:40:40 -04:00
DetectCloudFormationFile( ) {
2020-06-29 15:49:20 -04:00
################
# Pull in Vars #
################
FILE = " $1 " # File that we need to validate
2020-06-29 15:38:24 -04:00
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-formats.html
2020-06-26 15:43:44 -04:00
# AWSTemplateFormatVersion is optional
2020-06-29 15:49:20 -04:00
#######################################
# Check if file has AWS Template info #
#######################################
if grep 'AWSTemplateFormatVersion' " $FILE " > /dev/null; then
# Found it
2020-06-19 12:41:19 -04:00
return 0
fi
2020-06-29 15:49:20 -04:00
###################################################
# Check if file has AWSTemplateFormatVersion info #
###################################################
if shyaml --quiet get-type AWSTemplateFormatVersion > /dev/null < " $FILE " ; then
# Found it
2020-06-26 15:43:44 -04:00
return 0
fi
2020-06-29 15:49:20 -04:00
###############################
# check if file has resources #
###############################
if jq -e 'has("Resources")' > /dev/null 2>& 1 < " $FILE " ; then
# Check if AWS Alexa or custom
2020-07-01 17:40:40 -04:00
if jq ".Resources[].Type" 2> /dev/null | grep -q -E "(AWS|Alexa|Custom)" < " $FILE " ; then
2020-06-29 15:49:20 -04:00
# Found it
2020-06-26 15:43:44 -04:00
return 0
fi
fi
2020-06-29 15:49:20 -04:00
################################
# See if it contains resources #
################################
2020-06-30 11:30:12 -04:00
if shyaml values-0 Resources 2> /dev/null | grep -q -E "Type: (AWS|Alexa|Custom)" < " $FILE " ; then
2020-06-29 15:49:20 -04:00
# Found it
2020-06-26 15:43:44 -04:00
return 0
fi
2020-06-29 15:49:20 -04:00
##########################################
# No identifiers of a CFN template found #
##########################################
2020-06-26 15:43:44 -04:00
return 1
2020-06-19 12:41:19 -04:00
}
2020-01-09 17:08:01 -05:00
################################################################################
2019-10-21 15:12:37 -04:00
#### Function GetGitHubVars ####################################################
2020-07-01 17:40:40 -04:00
GetGitHubVars( ) {
2019-10-21 15:12:37 -04:00
##########
# Prints #
##########
echo "--------------------------------------------"
echo "Gathering GitHub information..."
2020-02-04 12:49:07 -05:00
###############################
# Get the Run test cases flag #
###############################
if [ -z " $TEST_CASE_RUN " ] ; then
##################################
# No flag passed, set to default #
##################################
TEST_CASE_RUN = " $DEFAULT_TEST_CASE_RUN "
fi
###############################
# Convert string to lowercase #
###############################
TEST_CASE_RUN = $( echo " $TEST_CASE_RUN " | awk '{print tolower($0)}' )
2020-01-09 11:29:18 -05:00
##########################
# Get the run local flag #
##########################
if [ -z " $RUN_LOCAL " ] ; then
##################################
# No flag passed, set to default #
##################################
RUN_LOCAL = " $DEFAULT_RUN_LOCAL "
2019-10-21 15:12:37 -04:00
fi
2020-01-09 11:29:18 -05:00
###############################
# Convert string to lowercase #
###############################
RUN_LOCAL = $( echo " $RUN_LOCAL " | awk '{print tolower($0)}' )
2020-02-04 12:49:07 -05:00
2020-01-09 11:29:18 -05:00
#################################
# Check if were running locally #
#################################
2020-07-01 17:40:40 -04:00
if [ [ $RUN_LOCAL != "false" ] ] ; then
2020-01-09 11:29:18 -05:00
##########################################
# We are running locally for a debug run #
##########################################
echo "NOTE: ENV VAR [RUN_LOCAL] has been set to:[true]"
echo "bypassing GitHub Actions variables..."
2020-06-19 13:31:53 -04:00
############################
# Set the GITHUB_WORKSPACE #
############################
if [ -z " $GITHUB_WORKSPACE " ] ; then
GITHUB_WORKSPACE = " $DEFAULT_WORKSPACE "
fi
2020-06-29 10:55:59 -04:00
2020-07-06 17:57:30 -04:00
if [ ! -d " $GITHUB_WORKSPACE " ] ; then
echo -e " ${ NC } ${ B [R] } ${ F [W] } ERROR: ${ NC } Provided volume is not a directory! ${ NC } "
exit 1
fi
2020-01-09 11:29:18 -05:00
echo " Linting all files in mapped directory:[ $DEFAULT_WORKSPACE ] "
# No need to touch or set the GITHUB_SHA
# No need to touch or set the GITHUB_EVENT_PATH
# No need to touch or set the GITHUB_ORG
# No need to touch or set the GITHUB_REPO
#################################
# Set the VALIDATE_ALL_CODEBASE #
#################################
VALIDATE_ALL_CODEBASE = " $DEFAULT_VALIDATE_ALL_CODEBASE "
2019-10-21 15:12:37 -04:00
else
2020-01-09 11:29:18 -05:00
############################
# Validate we have a value #
############################
if [ -z " $GITHUB_SHA " ] ; then
2020-07-01 16:47:24 -04:00
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 } "
2020-01-09 11:29:18 -05:00
exit 1
else
2020-07-01 16:40:24 -04:00
echo -e " ${ NC } ${ F [B] } Successfully found: ${ F [W] } [GITHUB_SHA] ${ F [B] } , value: ${ F [W] } [ $GITHUB_SHA ] ${ NC } "
2020-01-09 11:29:18 -05:00
fi
2019-10-21 15:12:37 -04:00
2020-01-09 11:29:18 -05:00
############################
# Validate we have a value #
############################
if [ -z " $GITHUB_WORKSPACE " ] ; then
2020-07-01 16:47:24 -04:00
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 } "
2020-01-09 11:29:18 -05:00
exit 1
else
2020-07-01 16:40:24 -04:00
echo -e " ${ NC } ${ F [B] } Successfully found: ${ F [W] } [GITHUB_WORKSPACE] ${ F [B] } , value: ${ F [W] } [ $GITHUB_WORKSPACE ] ${ NC } "
2020-01-09 11:29:18 -05:00
fi
2019-10-21 15:12:37 -04:00
2020-01-09 11:29:18 -05:00
############################
# Validate we have a value #
############################
if [ -z " $GITHUB_EVENT_PATH " ] ; then
2020-07-01 16:47:24 -04:00
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 } "
2020-01-09 11:29:18 -05:00
exit 1
else
2020-07-01 16:47:24 -04:00
echo -e " ${ NC } ${ F [B] } Successfully found: ${ F [W] } [GITHUB_EVENT_PATH] ${ F [B] } , value: ${ F [W] } [ $GITHUB_EVENT_PATH ] ${ F [B] } ${ NC } "
2020-01-09 11:29:18 -05:00
fi
2019-10-21 15:12:37 -04:00
2020-01-09 11:29:18 -05:00
##################################################
# Need to pull the GitHub Vars from the env file #
##################################################
######################
# Get the GitHub Org #
######################
2020-07-01 17:40:40 -04:00
GITHUB_ORG = $( jq -r '.repository.owner.login' < " $GITHUB_EVENT_PATH " )
2020-01-09 11:29:18 -05:00
############################
# Validate we have a value #
############################
if [ -z " $GITHUB_ORG " ] ; then
2020-07-01 16:47:24 -04:00
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 } "
2020-01-09 11:29:18 -05:00
exit 1
else
2020-07-01 16:40:24 -04:00
echo -e " ${ NC } ${ F [B] } Successfully found: ${ F [W] } [GITHUB_ORG] ${ F [B] } , value: ${ F [W] } [ $GITHUB_ORG ] ${ NC } "
2020-01-09 11:29:18 -05:00
fi
#######################
# Get the GitHub Repo #
#######################
2020-07-01 17:40:40 -04:00
GITHUB_REPO = $( jq -r '.repository.name' < " $GITHUB_EVENT_PATH " )
2020-01-09 11:29:18 -05:00
############################
# Validate we have a value #
############################
if [ -z " $GITHUB_REPO " ] ; then
2020-07-01 16:47:24 -04:00
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 } "
2020-01-09 11:29:18 -05:00
exit 1
else
2020-07-01 16:40:24 -04:00
echo -e " ${ NC } ${ F [B] } Successfully found: ${ F [W] } [GITHUB_REPO] ${ F [B] } , value: ${ F [W] } [ $GITHUB_REPO ] ${ NC } "
2020-01-09 11:29:18 -05:00
fi
2019-10-21 15:12:37 -04:00
fi
2020-07-20 15:07:56 -04:00
############################
# Validate we have a value #
############################
if [ -z " $GITHUB_TOKEN " ] ; 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 } "
else
echo -e " ${ NC } ${ F [B] } Successfully found: ${ F [W] } [GITHUB_TOKEN] ${ NC } "
fi
###############################
# Convert string to lowercase #
###############################
MULTI_STATUS = $( echo " $MULTI_STATUS " | awk '{print tolower($0)}' )
#######################################################################
# Check to see if the multi status is set, and we have a token to use #
#######################################################################
if [ " $MULTI_STATUS " = = "true" ] && [ -n " $GITHUB_TOKEN " ] ; then
############################
# 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
else
echo -e " ${ NC } ${ F [B] } 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
else
echo -e " ${ NC } ${ F [B] } Successfully found: ${ F [W] } [GITHUB_RUN_ID] ${ F [B] } , value: ${ F [W] } [ $GITHUB_RUN_ID ] ${ NC } "
fi
fi
2020-04-27 13:21:38 -04:00
}
################################################################################
2020-07-01 08:49:17 -04:00
#### Function ValidatePowershellModules ########################################
2020-07-01 17:40:40 -04:00
function ValidatePowershellModules( ) {
2020-07-01 08:49:17 -04:00
VALIDATE_PSSA_MODULE = $( pwsh -c "(Get-Module -Name PSScriptAnalyzer -ListAvailable | Select-Object -First 1).Name" 2>& 1)
# If module found, ensure Invoke-ScriptAnalyzer command is available
2020-07-01 17:40:40 -04:00
if [ [ $VALIDATE_PSSA_MODULE = = "PSScriptAnalyzer" ] ] ; then
2020-07-01 08:49:17 -04:00
VALIDATE_PSSA_CMD = $( pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>& 1)
else
# Failed to find module
exit 1
fi
#########################################
# validate we found the script analyzer #
#########################################
2020-07-01 17:40:40 -04:00
if [ [ $VALIDATE_PSSA_CMD != "Invoke-ScriptAnalyzer" ] ] ; then
2020-07-01 08:49:17 -04:00
# Failed to find module
exit 1
fi
#######################
# Load the error code #
#######################
ERROR_CODE = $?
##############################
# Check the shell for errors #
##############################
if [ $ERROR_CODE -ne 0 ] ; then
# Failed
2020-07-01 16:47:24 -04:00
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 } "
2020-07-01 08:49:17 -04:00
exit 1
else
# Success
2020-07-01 17:40:40 -04:00
if [ [ $ACTIONS_RUNNER_DEBUG = = "true" ] ] ; then
2020-07-01 16:40:24 -04:00
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 } "
2020-07-01 08:49:17 -04:00
fi
fi
}
################################################################################
2020-07-20 15:07:56 -04:00
#### Function CallStatusAPI ####################################################
CallStatusAPI( ) {
####################
# Pull in the vars #
####################
LANGUAGE = " $1 " # langauge that was validated
STATUS = " $2 " # success | error
SUCCESS_MSG = 'No errors were found in the linting process'
FAIL_MSG = 'Errors were detected, please view logs'
MESSAGE = '' # Message to send to status API
######################################
# Check the status to create message #
######################################
if [ " $STATUS " = = "success" ] ; then
# Success
MESSAGE = " $SUCCESS_MSG "
else
# Failure
MESSAGE = " $FAIL_MSG "
fi
##############################################
# Call the status API to create status check #
##############################################
2020-07-20 15:29:03 -04:00
SEND_STATUS_CMD = $( curl -f -s -X POST \
--url " $GITHUB_API_URL /repos/ $GITHUB_REPOSITORY /statuses/ $GITHUB_SHA " \
2020-07-20 15:07:56 -04:00
-H 'accept: application/vnd.github.v3+json' \
-H " authorization: Bearer $GITHUB_TOKEN " \
-H 'content-type: application/json' \
-d " { \"state\": \" $STATUS \",
\" target_url\" : \" https://github.com/$GITHUB_REPOSITORY /actions/runs/$GITHUB_RUN_ID \" ,
\" description\" : \" $MESSAGE \" , \" context\" : \" --> Lint-Language/$LANGUAGE \"
} " 2>&1)
#######################
# Load the error code #
#######################
ERROR_CODE = $?
##############################
# Check the shell for errors #
##############################
if [ " $ERROR_CODE " -ne 0 ] ; then
# ERROR
echo "ERROR! Failed to call GitHub Status API!"
echo " ERROR:[ $SEND_STATUS_CMD ] "
# Not going to fail the script on this yet...
fi
}
################################################################################
2019-10-21 12:05:55 -04:00
#### Function Footer ###########################################################
2020-07-01 17:40:40 -04:00
Footer( ) {
2019-10-21 12:05:55 -04:00
echo ""
2019-12-06 08:51:40 -05:00
echo "----------------------------------------------"
echo "----------------------------------------------"
2019-10-21 12:05:55 -04:00
echo "The script has completed"
2019-12-06 08:51:40 -05:00
echo "----------------------------------------------"
echo "----------------------------------------------"
2020-04-23 13:07:35 -04:00
echo ""
2020-04-27 15:13:12 -04:00
2020-06-23 10:25:12 -04:00
###################################
# Prints output report if enabled #
###################################
if [ -z " ${ FORMAT_REPORT } " ] ; then
echo " Reports generated in folder ${ REPORT_OUTPUT_FOLDER } "
fi
2020-04-27 15:13:12 -04:00
##############################
# Prints for errors if found #
##############################
2020-07-01 17:40:40 -04:00
for LANGUAGE in " ${ LANGUAGE_ARRAY [@] } " ; do
2020-04-27 15:13:12 -04:00
###########################
# Build the error counter #
###########################
ERROR_COUNTER = " ERRORS_FOUND_ $LANGUAGE "
##################
# Print if not 0 #
##################
2020-04-27 15:38:43 -04:00
if [ " ${ !ERROR_COUNTER } " -ne 0 ] ; then
2020-07-20 15:07:56 -04:00
# We found errors
###################
# Print the goods #
###################
2020-07-01 16:47:24 -04:00
echo -e " ${ NC } ${ B [R] } ${ F [W] } ERRORS FOUND ${ NC } in $LANGUAGE :[ ${ !ERROR_COUNTER } ] ${ NC } "
2020-07-20 15:07:56 -04:00
#########################################
# Create status API for Failed language #
#########################################
CallStatusAPI " $LANGUAGE " "error"
else
# No errors found
#########################################
# Create status API for Failed language #
#########################################
CallStatusAPI " $LANGUAGE " "success"
2020-07-20 15:13:26 -04:00
fi
2020-04-27 15:13:12 -04:00
done
2020-07-19 15:26:20 -04:00
################################
# 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 } "
done
2020-06-18 15:24:47 -04:00
##################################
# Exit with 0 if errors disabled #
##################################
2020-06-19 13:39:08 -04:00
if [ " $DISABLE_ERRORS " = = "true" ] ; then
2020-07-01 16:47:24 -04:00
echo -e " ${ NC } ${ F [Y] } WARN! ${ NC } Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[ $DISABLE_ERRORS ] ${ NC } "
2020-06-18 15:24:47 -04:00
exit 0
2019-10-21 12:05:55 -04:00
###############################
# Exit with 1 if errors found #
###############################
2020-07-01 17:40:40 -04:00
elif [ " $ERRORS_FOUND_YML " -ne 0 ] ||
[ " $ERRORS_FOUND_JSON " -ne 0 ] ||
[ " $ERRORS_FOUND_XML " -ne 0 ] ||
[ " $ERRORS_FOUND_MARKDOWN " -ne 0 ] ||
[ " $ERRORS_FOUND_BASH " -ne 0 ] ||
[ " $ERRORS_FOUND_PERL " -ne 0 ] ||
2020-07-05 22:21:13 -04:00
[ " $ERRORS_FOUND_RAKU " -ne 0 ] ||
2020-07-01 17:40:40 -04:00
[ " $ERRORS_FOUND_PHP " -ne 0 ] ||
[ " $ERRORS_FOUND_PYTHON " -ne 0 ] ||
[ " $ERRORS_FOUND_COFFEESCRIPT " -ne 0 ] ||
[ " $ERRORS_FOUND_ANSIBLE " -ne 0 ] ||
[ " $ERRORS_FOUND_JAVASCRIPT_ES " -ne 0 ] ||
[ " $ERRORS_FOUND_JAVASCRIPT_STANDARD " -ne 0 ] ||
2020-07-07 11:02:56 -04:00
[ " $ERRORS_FOUND_JSX " -ne 0 ] ||
[ " $ERRORS_FOUND_TSX " -ne 0 ] ||
2020-07-01 17:40:40 -04:00
[ " $ERRORS_FOUND_TYPESCRIPT_ES " -ne 0 ] ||
[ " $ERRORS_FOUND_TYPESCRIPT_STANDARD " -ne 0 ] ||
[ " $ERRORS_FOUND_DOCKER " -ne 0 ] ||
[ " $ERRORS_FOUND_GO " -ne 0 ] ||
[ " $ERRORS_FOUND_TERRAFORM " -ne 0 ] ||
[ " $ERRORS_FOUND_POWERSHELL " -ne 0 ] ||
2020-07-03 08:28:08 -04:00
[ " $ERRORS_FOUND_ARM " -ne 0 ] ||
2020-07-01 17:40:40 -04:00
[ " $ERRORS_FOUND_RUBY " -ne 0 ] ||
[ " $ERRORS_FOUND_CSS " -ne 0 ] ||
[ " $ERRORS_FOUND_CFN " -ne 0 ] ||
[ " $ERRORS_FOUND_ENV " -ne 0 ] ||
[ " $ERRORS_FOUND_OPENAPI " -ne 0 ] ||
[ " $ERRORS_FOUND_PROTOBUF " -ne 0 ] ||
[ " $ERRORS_FOUND_CLOJURE " -ne 0 ] ||
2020-07-06 04:17:20 -04:00
[ " $ERRORS_FOUND_KOTLIN " -ne 0 ] ||
2020-07-06 14:11:35 -04:00
[ " $ERRORS_FOUND_DART " -ne 0 ] ||
2020-07-04 18:14:27 -04:00
[ " $ERRORS_FOUND_HTML " -ne 0 ] ; then
2019-10-21 12:05:55 -04:00
# Failed exit
2020-07-01 15:33:46 -04:00
echo -e " ${ NC } ${ F [R] } Exiting with errors found! ${ NC } "
2019-10-21 10:12:50 -04:00
exit 1
else
2020-04-27 15:55:21 -04:00
#################
# Footer prints #
#################
echo ""
2020-07-01 15:00:05 -04:00
echo -e " ${ NC } ${ F [G] } All file(s) linted successfully with no errors detected ${ NC } "
2020-04-27 15:55:21 -04:00
echo "----------------------------------------------"
echo ""
2019-10-21 12:05:55 -04:00
# Successful exit
exit 0
2019-10-21 10:12:50 -04:00
fi
}
2020-06-21 03:16:45 -04:00
2019-10-21 10:12:50 -04:00
################################################################################
2019-10-21 12:05:55 -04:00
############################### MAIN ###########################################
2019-10-21 10:12:50 -04:00
################################################################################
2019-10-21 12:05:55 -04:00
##########
# Header #
##########
Header
2020-06-23 10:25:12 -04:00
##############################################################
# check flag for validating the report folder does not exist #
##############################################################
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
fi
fi
2019-10-21 15:12:37 -04:00
#######################
2020-06-19 01:44:26 -04:00
# Get GitHub Env Vars #
2019-10-21 15:12:37 -04:00
#######################
2020-06-19 01:44:26 -04:00
# Need to pull in all the GitHub variables
2019-10-21 15:12:37 -04:00
# needed to connect back and update checks
GetGitHubVars
2020-06-20 23:55:10 -04:00
#########################################
# Get the languages we need to validate #
#########################################
2020-04-27 14:47:11 -04:00
GetValidationInfo
2020-04-27 13:21:38 -04:00
2019-10-21 12:05:55 -04:00
########################
# Get the linter rules #
########################
2020-03-11 15:18:21 -04:00
# Get YML rules
2020-07-01 10:45:55 -04:00
GetLinterRules "YAML"
2020-03-11 15:18:21 -04:00
# Get Markdown rules
2020-07-01 10:45:55 -04:00
GetLinterRules "MD"
2020-03-11 15:18:21 -04:00
# Get Python rules
2020-07-01 10:45:55 -04:00
GetLinterRules "PYTHON"
2020-03-11 15:18:21 -04:00
# Get Ruby rules
2020-07-01 10:45:55 -04:00
GetLinterRules "RUBY"
2020-03-11 15:18:21 -04:00
# Get Coffeescript rules
2020-07-01 10:45:55 -04:00
GetLinterRules "COFFEESCRIPT"
2020-03-11 15:18:21 -04:00
# Get Ansible rules
2020-07-01 10:45:55 -04:00
GetLinterRules "ANSIBLE"
2020-03-11 15:18:21 -04:00
# Get JavaScript rules
2020-07-01 10:45:55 -04:00
GetLinterRules "JAVASCRIPT"
2020-04-02 13:42:07 -04:00
# Get TypeScript rules
2020-07-01 10:45:55 -04:00
GetLinterRules "TYPESCRIPT"
2020-02-28 10:51:29 -05:00
# Get Golang rules
2020-07-01 10:45:55 -04:00
GetLinterRules "GO"
2020-03-11 15:18:21 -04:00
# Get Docker rules
2020-07-01 10:45:55 -04:00
GetLinterRules "DOCKER"
2020-03-11 15:18:21 -04:00
# Get Terraform rules
2020-07-01 10:45:55 -04:00
GetLinterRules "TERRAFORM"
2020-06-22 09:16:59 -04:00
# Get PowerShell rules
2020-07-01 10:45:55 -04:00
GetLinterRules "POWERSHELL"
2020-07-02 17:31:16 -04:00
# Get ARM rules
2020-07-03 08:28:08 -04:00
GetLinterRules "ARM"
2020-06-18 19:40:41 -04:00
# Get CSS rules
2020-07-01 10:45:55 -04:00
GetLinterRules "CSS"
2020-06-29 16:22:52 -04:00
# Get CFN rules
2020-07-01 10:45:55 -04:00
GetLinterRules "CFN"
2020-07-06 04:17:20 -04:00
# Get DART rules
GetLinterRules "DART"
2020-07-04 18:14:27 -04:00
# Get HTML rules
GetLinterRules "HTML"
2020-02-03 11:27:40 -05:00
#################################
# Check if were in verbose mode #
#################################
2020-07-01 17:40:40 -04:00
if [ [ $ACTIONS_RUNNER_DEBUG = = "true" ] ] ; then
2020-02-03 11:27:40 -05:00
##################################
# Get and print all version info #
##################################
GetLinterVersions
fi
2020-01-08 14:34:05 -05:00
2020-02-04 12:49:07 -05:00
###########################################
# Check to see if this is a test case run #
###########################################
2020-07-01 17:40:40 -04:00
if [ [ $TEST_CASE_RUN != "false" ] ] ; then
2020-07-20 15:07:56 -04:00
#############################################
# Set the multi status to off for test runs #
#############################################
MULTI_STATUS = 'false'
2020-02-04 12:49:07 -05:00
###########################
# Run only the test cases #
###########################
# Code will exit from inside this loop
RunTestCases
fi
2020-06-29 16:38:33 -04:00
2020-02-03 11:27:40 -05:00
#############################################
# check flag for validation of all codebase #
#############################################
2019-10-25 12:29:31 -04:00
if [ " $VALIDATE_ALL_CODEBASE " = = "false" ] ; then
2020-02-03 11:27:40 -05:00
########################################
# Get list of files changed if env set #
########################################
2019-10-25 12:29:31 -04:00
BuildFileList
fi
2019-10-21 15:12:37 -04:00
2020-02-03 11:27:40 -05:00
###############
# YML LINTING #
###############
2019-10-25 12:29:31 -04:00
if [ " $VALIDATE_YAML " = = "true" ] ; then
2020-02-03 11:27:40 -05:00
######################
# Lint the Yml Files #
######################
2020-02-03 15:54:43 -05:00
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "YML" "yamllint" " yamllint -c $YAML_LINTER_RULES " ".*\.\(yml\|yaml\)\$" " ${ FILE_ARRAY_YML [@] } "
2019-10-25 12:29:31 -04:00
fi
2019-10-21 12:05:55 -04:00
2020-02-03 11:27:40 -05:00
################
# JSON LINTING #
################
2019-10-25 12:29:31 -04:00
if [ " $VALIDATE_JSON " = = "true" ] ; then
2020-02-03 11:27:40 -05:00
#######################
# Lint the json files #
#######################
2020-02-03 15:54:43 -05:00
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" " ${ FILE_ARRAY_JSON [@] } "
2019-10-25 12:29:31 -04:00
fi
2019-10-21 10:12:50 -04:00
2020-02-03 11:27:40 -05:00
###############
# XML LINTING #
###############
2019-10-25 12:29:31 -04:00
if [ " $VALIDATE_XML " = = "true" ] ; then
2020-02-03 11:27:40 -05:00
######################
# Lint the XML Files #
######################
2020-02-03 15:54:43 -05:00
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" " ${ FILE_ARRAY_XML [@] } "
2019-10-25 12:29:31 -04:00
fi
2019-10-21 10:12:50 -04:00
2020-02-03 11:27:40 -05:00
####################
# MARKDOWN LINTING #
####################
2019-10-25 12:29:31 -04:00
if [ " $VALIDATE_MD " = = "true" ] ; then
2020-02-03 11:27:40 -05:00
###########################
# Lint the Markdown Files #
###########################
2020-02-03 15:54:43 -05:00
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "MARKDOWN" "markdownlint" " markdownlint -c $MD_LINTER_RULES " ".*\.\(md\)\$" " ${ FILE_ARRAY_MD [@] } "
2019-10-25 12:29:31 -04:00
fi
2019-10-21 12:05:55 -04:00
2020-02-03 11:27:40 -05:00
################
# BASH LINTING #
################
2019-10-25 12:29:31 -04:00
if [ " $VALIDATE_BASH " = = "true" ] ; then
2020-02-03 11:27:40 -05:00
#######################
# Lint the bash files #
#######################
2020-02-03 15:54:43 -05:00
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
2020-07-06 16:51:17 -04:00
LintCodebase "BASH" "shellcheck" "shellcheck --color" ".*\.\(sh\|bash\|dash\|ksh\)\$" " ${ FILE_ARRAY_BASH [@] } "
2019-10-25 12:29:31 -04:00
fi
2019-10-21 12:05:55 -04:00
2020-02-03 11:27:40 -05:00
##################
# PYTHON LINTING #
##################
2019-10-25 12:29:31 -04:00
if [ " $VALIDATE_PYTHON " = = "true" ] ; then
2020-02-03 11:27:40 -05:00
#########################
# Lint the python files #
#########################
2020-02-03 15:54:43 -05:00
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
2020-06-26 18:16:22 -04:00
LintCodebase "PYTHON" "pylint" " pylint --rcfile $PYTHON_LINTER_RULES " ".*\.\(py\)\$" " ${ FILE_ARRAY_PYTHON [@] } "
2019-10-25 12:29:31 -04:00
fi
2019-10-21 12:05:55 -04:00
2020-06-19 12:41:19 -04:00
###############
# CFN LINTING #
###############
if [ " $VALIDATE_CLOUDFORMATION " = = "true" ] ; then
#################################
# Lint the CloudFormation files #
#################################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "CFN" "cfn-lint" " cfn-lint --config-file $CFN_LINTER_RULES " ".*\.\(json\|yml\|yaml\)\$" " ${ FILE_ARRAY_CFN [@] } "
fi
2020-02-03 11:27:40 -05:00
################
# PERL LINTING #
################
2019-10-25 12:29:31 -04:00
if [ " $VALIDATE_PERL " = = "true" ] ; then
2020-02-03 11:27:40 -05:00
#######################
# Lint the perl files #
#######################
2020-02-03 15:54:43 -05:00
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" " ${ FILE_ARRAY_PERL [@] } "
2019-10-25 12:29:31 -04:00
fi
2019-10-21 12:05:55 -04:00
2020-07-05 22:21:13 -04:00
################
# RAKU LINTING #
################
if [ " $VALIDATE_RAKU " = = "true" ] ; then
#######################
# Lint the raku files #
#######################
echo " $GITHUB_WORKSPACE /META6.json "
if [ -e " $GITHUB_WORKSPACE /META6.json " ] ; then
cd " $GITHUB_WORKSPACE " && zef install --deps-only --/test .
fi
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "RAKU" "raku" " raku -I $GITHUB_WORKSPACE /lib -c " ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" " ${ FILE_ARRAY_RAKU [@] } "
fi
2020-06-18 13:53:24 -04:00
################
# PHP LINTING #
################
if [ " $VALIDATE_PHP " = = "true" ] ; then
#######################
# Lint the PHP files #
#######################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" " ${ FILE_ARRAY_PHP [@] } "
fi
2020-02-03 11:27:40 -05:00
################
# RUBY LINTING #
################
2019-10-25 12:29:31 -04:00
if [ " $VALIDATE_RUBY " = = "true" ] ; then
2020-02-03 11:27:40 -05:00
#######################
# Lint the ruby files #
#######################
2020-02-03 15:54:43 -05:00
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
2020-07-16 10:56:27 -04:00
LintCodebase "RUBY" "rubocop" " rubocop -c $RUBY_LINTER_RULES --force-exclusion " ".*\.\(rb\)\$" " ${ FILE_ARRAY_RUBY [@] } "
2019-10-25 12:29:31 -04:00
fi
2019-10-21 12:05:55 -04:00
2020-02-03 11:27:40 -05:00
########################
# COFFEESCRIPT LINTING #
########################
2019-10-25 12:29:31 -04:00
if [ " $VALIDATE_COFFEE " = = "true" ] ; then
2020-02-03 11:27:40 -05:00
#########################
# Lint the coffee files #
#########################
2020-02-03 15:54:43 -05:00
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
2020-02-04 13:20:22 -05:00
LintCodebase "COFFEESCRIPT" "coffeelint" " coffeelint -f $COFFEESCRIPT_LINTER_RULES " ".*\.\(coffee\)\$" " ${ FILE_ARRAY_COFFEESCRIPT [@] } "
2019-10-25 12:29:31 -04:00
fi
2019-10-21 12:05:55 -04:00
2020-02-28 10:51:29 -05:00
##################
# GOLANG LINTING #
##################
if [ " $VALIDATE_GO " = = "true" ] ; then
#########################
# Lint the golang files #
#########################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "GO" "golangci-lint" " golangci-lint run -c $GO_LINTER_RULES " ".*\.\(go\)\$" " ${ FILE_ARRAY_GO [@] } "
fi
2020-03-11 15:18:21 -04:00
#####################
# TERRAFORM LINTING #
#####################
if [ " $VALIDATE_TERRAFORM " = = "true" ] ; then
############################
# Lint the Terraform files #
############################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "TERRAFORM" "tflint" " tflint -c $TERRAFORM_LINTER_RULES " ".*\.\(tf\)\$" " ${ FILE_ARRAY_TERRAFORM [@] } "
fi
2020-02-03 11:27:40 -05:00
###################
# ANSIBLE LINTING #
###################
2019-10-25 12:29:31 -04:00
if [ " $VALIDATE_ANSIBLE " = = "true" ] ; then
2020-02-03 11:27:40 -05:00
##########################
# Lint the Ansible files #
##########################
# Due to the nature of how we want to validate Ansible, we cannot use the
# standard loop, since it looks for an ansible folder, excludes certain
# files, and looks for additional changes, it should be an outlier
2020-07-01 12:59:00 -04:00
LintAnsibleFiles " $ANSIBLE_LINTER_RULES " # Passing rules but not needed, dont want to exclude unused var
2019-10-25 12:29:31 -04:00
fi
2019-10-22 13:21:42 -04:00
2020-02-03 11:27:40 -05:00
######################
# JAVASCRIPT LINTING #
######################
2020-04-02 13:42:07 -04:00
if [ " $VALIDATE_JAVASCRIPT_ES " = = "true" ] ; then
#############################
# Lint the Javascript files #
#############################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "JAVASCRIPT_ES" "eslint" " eslint --no-eslintrc -c $JAVASCRIPT_LINTER_RULES " ".*\.\(js\)\$" " ${ FILE_ARRAY_JAVASCRIPT_ES [@] } "
fi
######################
# JAVASCRIPT LINTING #
######################
if [ " $VALIDATE_JAVASCRIPT_STANDARD " = = "true" ] ; then
2020-02-03 11:27:40 -05:00
#################################
# Get Javascript standard rules #
#################################
2020-04-02 13:48:35 -04:00
GetStandardRules "javascript"
2020-02-03 11:27:40 -05:00
#############################
# Lint the Javascript files #
#############################
2020-02-03 15:54:43 -05:00
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
2020-04-02 13:42:07 -04:00
LintCodebase "JAVASCRIPT_STANDARD" "standard" " standard $JAVASCRIPT_STANDARD_LINTER_RULES " ".*\.\(js\)\$" " ${ FILE_ARRAY_JAVASCRIPT_STANDARD [@] } "
fi
2020-07-07 11:02:56 -04:00
######################
# JSX LINTING #
######################
if [ " $VALIDATE_JSX " = = "true" ] ; then
#############################
# Lint the JSX files #
#############################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "JSX" "eslint" " eslint --no-eslintrc -c $JAVASCRIPT_LINTER_RULES " ".*\.\(jsx\)\$" " ${ FILE_ARRAY_JSX [@] } "
fi
######################
# TSX LINTING #
######################
if [ " $VALIDATE_TSX " = = "true" ] ; then
#############################
# Lint the TSX files #
#############################
LintCodebase "TSX" "eslint" " eslint --no-eslintrc -c $TYPESCRIPT_LINTER_RULES " ".*\.\(tsx\)\$" " ${ FILE_ARRAY_TSX [@] } "
fi
2020-04-02 13:42:07 -04:00
######################
# TYPESCRIPT LINTING #
######################
if [ " $VALIDATE_TYPESCRIPT_ES " = = "true" ] ; then
#############################
# Lint the Typescript files #
#############################
LintCodebase "TYPESCRIPT_ES" "eslint" " eslint --no-eslintrc -c $TYPESCRIPT_LINTER_RULES " ".*\.\(ts\)\$" " ${ FILE_ARRAY_TYPESCRIPT_ES [@] } "
fi
2020-06-29 16:38:33 -04:00
2020-04-02 13:42:07 -04:00
######################
# TYPESCRIPT LINTING #
######################
if [ " $VALIDATE_TYPESCRIPT_STANDARD " = = "true" ] ; then
#################################
# Get Typescript standard rules #
#################################
2020-04-02 13:48:35 -04:00
GetStandardRules "typescript"
2020-04-02 13:42:07 -04:00
#############################
# Lint the Typescript files #
#############################
LintCodebase "TYPESCRIPT_STANDARD" "standard" " standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin $TYPESCRIPT_STANDARD_LINTER_RULES " ".*\.\(ts\)\$" " ${ FILE_ARRAY_TYPESCRIPT_STANDARD [@] } "
2019-11-06 16:45:44 -05:00
fi
2020-06-18 19:40:41 -04:00
###############
# CSS LINTING #
###############
if [ " $VALIDATE_CSS " = = "true" ] ; then
#################################
# Get CSS standard rules #
#################################
GetStandardRules "stylelint"
#############################
# Lint the CSS files #
#############################
LintCodebase "CSS" "stylelint" " stylelint --config $CSS_LINTER_RULES " ".*\.\(css\)\$" " ${ FILE_ARRAY_CSS [@] } "
fi
2020-06-20 06:02:14 -04:00
###############
2020-06-19 13:32:07 -04:00
# ENV LINTING #
2020-06-20 06:02:14 -04:00
###############
2020-06-19 13:32:07 -04:00
if [ " $VALIDATE_ENV " = = "true" ] ; then
#######################
# Lint the env files #
#######################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
2020-06-20 06:02:14 -04:00
LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\).*\$" " ${ FILE_ARRAY_ENV [@] } "
2020-06-19 13:32:07 -04:00
fi
2020-06-21 03:59:18 -04:00
##################
# KOTLIN LINTING #
##################
if [ " $VALIDATE_KOTLIN " = = "true" ] ; then
#######################
# Lint the Kotlin files #
#######################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
2020-06-29 11:34:23 -04:00
LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" " ${ FILE_ARRAY_KOTLIN [@] } "
2020-06-19 13:32:07 -04:00
fi
2020-06-21 03:16:45 -04:00
########################
# EDITORCONFIG LINTING #
########################
if [ " $VALIDATE_EDITORCONFIG " = = "true" ] ; then
####################################
# Lint the files with editorconfig #
####################################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "EDITORCONFIG" "editorconfig-checker" "editorconfig-checker" " ^.* $" " ${ FILE_ARRAY_ENV [@] } "
fi
2020-07-06 04:17:20 -04:00
##################
# DART LINTING #
##################
if [ " $VALIDATE_DART " = = "true" ] ; then
#######################
# Lint the Dart files #
#######################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
2020-07-15 02:36:22 -04:00
LintCodebase "DART" "dart" " pub get || true && dartanalyzer --fatal-infos --fatal-warnings --options $DART_LINTER_RULES " ".*\.\(dart\)\$" " ${ FILE_ARRAY_DART [@] } "
2020-07-06 04:17:20 -04:00
fi
2020-02-03 11:27:40 -05:00
##################
# DOCKER LINTING #
##################
2020-01-09 17:08:01 -05:00
if [ " $VALIDATE_DOCKER " = = "true" ] ; then
2020-02-03 11:27:40 -05:00
#########################
# Lint the docker files #
#########################
2020-02-03 15:54:43 -05:00
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
2020-07-07 19:59:32 -04:00
# NOTE: dockerfilelint's "-c" option expects the folder *containing* the DOCKER_LINTER_RULES file
2020-07-02 18:30:57 -04:00
LintCodebase "DOCKER" "dockerfilelint" " dockerfilelint -c $( dirname $DOCKER_LINTER_RULES ) " ".*\(Dockerfile\)\$" " ${ FILE_ARRAY_DOCKER [@] } "
2020-01-09 17:08:01 -05:00
fi
2020-06-19 14:30:28 -04:00
###################
# CLOJURE LINTING #
###################
if [ " $VALIDATE_CLOJURE " = = "true" ] ; then
#################################
# Get Clojure standard rules #
#################################
GetStandardRules "clj-kondo"
#########################
# Lint the Clojure files #
#########################
2020-06-24 10:51:16 -04:00
LintCodebase "CLOJURE" "clj-kondo" " clj-kondo --config $CLOJURE_LINTER_RULES --lint " ".*\.\(clj\|cljs\|cljc\|edn\)\$" " ${ FILE_ARRAY_CLOJURE [@] } "
2020-01-09 17:08:01 -05:00
fi
2020-06-28 07:07:51 -04:00
##################
# PROTOBUF LINTING #
##################
if [ " $VALIDATE_PROTOBUF " = = "true" ] ; then
#######################
# Lint the Protocol Buffers files #
#######################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "PROTOBUF" "protolint" " protolint lint --config_path $PROTOBUF_LINTER_RULES " ".*\.\(proto\)\$" " ${ FILE_ARRAY_PROTOBUF [@] } "
fi
2020-06-19 12:13:13 -04:00
######################
# POWERSHELL LINTING #
######################
if [ " $VALIDATE_POWERSHELL " = = "true" ] ; then
2020-07-01 08:49:17 -04:00
###############################################################
# For POWERSHELL, ensure PSScriptAnalyzer module is available #
###############################################################
ValidatePowershellModules
2020-07-01 15:33:20 -04:00
2020-06-19 12:13:13 -04:00
#############################
# Lint the powershell files #
#############################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
2020-06-30 15:32:42 -04:00
LintCodebase "POWERSHELL" "pwsh" " Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path " ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" " ${ FILE_ARRAY_POWERSHELL [@] } "
2020-06-19 12:13:13 -04:00
fi
2020-07-02 17:31:16 -04:00
########################
# ARM Template LINTING #
########################
if [ " $VALIDATE_ARM " = = "true" ] ; then
###############################
# Lint the ARM Template files #
###############################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "ARM" "arm-ttk" " Import-Module $ARM_TTK_PSD1 ; \$config = \$(Import-PowerShellDataFile -Path $ARM_LINTER_RULES ) ; Test-AzTemplate @config -TemplatePath " ".*\.\(json\)\$" " ${ FILE_ARRAY_ARM [@] } "
fi
2020-06-25 02:13:19 -04:00
###################
# OPENAPI LINTING #
###################
if [ " $VALIDATE_OPENAPI " = = "true" ] ; then
# If we are validating all codebase we need to build file list because not every yml/json file is an OpenAPI file
if [ " $VALIDATE_ALL_CODEBASE " = = "true" ] ; then
2020-06-26 11:38:02 -04:00
###############################################################################
# Set the file seperator to newline to allow for grabbing objects with spaces #
###############################################################################
IFS = $'\n'
2020-06-30 10:24:28 -04:00
mapfile -t LIST_FILES < <( find " $GITHUB_WORKSPACE " -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>& 1)
2020-07-01 17:40:40 -04:00
for FILE in " ${ LIST_FILES [@] } " ; do
2020-06-26 09:26:36 -04:00
if DetectOpenAPIFile " $FILE " ; then
2020-06-25 02:13:19 -04:00
FILE_ARRAY_OPENAPI += ( " $FILE " )
fi
done
2020-06-26 11:38:02 -04:00
###########################
# Set IFS back to default #
###########################
IFS = " $DEFAULT_IFS "
2020-06-25 02:13:19 -04:00
fi
##########################
# Lint the OpenAPI files #
##########################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "OPENAPI" "spectral" " spectral lint -r $OPENAPI_LINTER_RULES " "disabledfileext" " ${ FILE_ARRAY_OPENAPI [@] } "
fi
2020-07-04 18:14:27 -04:00
################
# HTML LINTING #
################
if [ " $VALIDATE_HTML " = = "true" ] ; then
#################################
# Get HTML standard rules #
#################################
GetStandardRules "htmlhint"
#############################
# Lint the HTML files #
#############################
LintCodebase "HTML" "htmlhint" " htmlhint --config $HTML_LINTER_RULES " ".*\.\(html\)\$" " ${ FILE_ARRAY_HTML [@] } "
fi
2019-10-21 12:05:55 -04:00
##########
# Footer #
##########
Footer