2020-06-23 12:02:45 -04:00
#!/usr/bin/env bash
2019-10-21 10:12:50 -04:00
2024-02-20 14:05:39 -05:00
set -o nounset
set -o pipefail
2024-02-20 12:27:06 -05:00
# Version of the Super-linter (standard,slim,etc)
IMAGE = " ${ IMAGE :- standard } "
2020-09-28 16:29:48 -04:00
2020-06-29 10:55:59 -04:00
#########################
# Source Function Files #
#########################
2024-02-21 12:51:47 -05:00
# Source log functions and variables early so we can use them ASAP
# shellcheck source=/dev/null
source /action/lib/functions/log.sh # Source the function script(s)
2020-06-30 10:56:15 -04:00
# shellcheck source=/dev/null
2020-11-12 12:27:34 -05:00
source /action/lib/functions/buildFileList.sh # Source the function script(s)
2020-06-30 10:56:15 -04:00
# shellcheck source=/dev/null
2021-04-26 10:00:42 -04:00
source /action/lib/functions/detectFiles.sh # Source the function script(s)
2020-06-30 10:56:15 -04:00
# shellcheck source=/dev/null
2021-04-26 10:00:42 -04:00
source /action/lib/functions/linterRules.sh # Source the function script(s)
# shellcheck source=/dev/null
source /action/lib/functions/updateSSL.sh # Source the function script(s)
2020-11-12 12:27:34 -05:00
# shellcheck source=/dev/null
2021-04-26 10:00:42 -04:00
source /action/lib/functions/validation.sh # Source the function script(s)
2020-11-12 12:27:34 -05:00
# shellcheck source=/dev/null
2021-04-26 10:00:42 -04:00
source /action/lib/functions/worker.sh # Source the function script(s)
2022-02-09 16:24:57 -05:00
# shellcheck source=/dev/null
source /action/lib/functions/setupSSH.sh # Source the function script(s)
2024-01-05 17:07:39 -05:00
# shellcheck source=/dev/null
source /action/lib/functions/githubEvent.sh
2024-06-21 02:54:19 -04:00
# shellcheck source=/dev/null
source /action/lib/functions/githubDomain.sh
2024-07-30 02:35:14 -04:00
# shellcheck source=/dev/null
source /action/lib/functions/output.sh
2024-06-21 02:54:19 -04:00
if ! ValidateGitHubUrls; then
fatal "GitHub URLs failed validation"
fi
2020-06-29 10:55:59 -04:00
2024-01-11 15:30:00 -05:00
# We want a lowercase value
declare -l RUN_LOCAL
2023-12-12 14:57:15 -05:00
# Initialize RUN_LOCAL early because we need it for logging
2024-01-11 15:30:00 -05:00
RUN_LOCAL = " ${ RUN_LOCAL :- "false" } "
2023-12-12 14:57:15 -05:00
# Dynamically set the default behavior for GitHub Actions log markers because
# we want to give users a chance to enable this even when running locally, but
# we still want to provide a default value in case they don't want to explictly
# configure it.
if [ [ " ${ RUN_LOCAL } " = = "true" ] ] ; then
DEFAULT_ENABLE_GITHUB_ACTIONS_GROUP_TITLE = "false"
2024-07-11 04:01:11 -04:00
DEFAULT_ENABLE_GITHUB_ACTIONS_STEP_SUMMARY = "false"
2023-12-12 14:57:15 -05:00
else
DEFAULT_ENABLE_GITHUB_ACTIONS_GROUP_TITLE = "true"
2024-07-11 04:01:11 -04:00
DEFAULT_ENABLE_GITHUB_ACTIONS_STEP_SUMMARY = "true"
2023-12-12 14:57:15 -05:00
fi
# Let users configure GitHub Actions log markers regardless of running locally or not
ENABLE_GITHUB_ACTIONS_GROUP_TITLE = " ${ ENABLE_GITHUB_ACTIONS_GROUP_TITLE :- " ${ DEFAULT_ENABLE_GITHUB_ACTIONS_GROUP_TITLE } " } "
2024-01-30 14:24:55 -05:00
export ENABLE_GITHUB_ACTIONS_GROUP_TITLE
2023-12-12 14:57:15 -05:00
startGitHubActionsLogGroup " ${ SUPER_LINTER_INITIALIZATION_LOG_GROUP_TITLE } "
2024-07-11 04:01:11 -04:00
# Let users configure GitHub Actions step summary regardless of running locally or not
ENABLE_GITHUB_ACTIONS_STEP_SUMMARY = " ${ ENABLE_GITHUB_ACTIONS_STEP_SUMMARY :- " ${ DEFAULT_ENABLE_GITHUB_ACTIONS_STEP_SUMMARY } " } "
export ENABLE_GITHUB_ACTIONS_STEP_SUMMARY
2024-02-27 13:17:22 -05:00
# We want a lowercase value
declare -l BASH_EXEC_IGNORE_LIBRARIES
BASH_EXEC_IGNORE_LIBRARIES = " ${ BASH_EXEC_IGNORE_LIBRARIES :- false } "
2024-01-11 15:30:00 -05:00
# We want a lowercase value
declare -l DISABLE_ERRORS
DISABLE_ERRORS = " ${ DISABLE_ERRORS :- "false" } "
# We want a lowercase value
declare -l IGNORE_GENERATED_FILES
# Do not ignore generated files by default for backwards compatibility
IGNORE_GENERATED_FILES = " ${ IGNORE_GENERATED_FILES :- false } "
2024-01-30 14:24:55 -05:00
export IGNORE_GENERATED_FILES
2024-01-11 15:30:00 -05:00
# We want a lowercase value
declare -l IGNORE_GITIGNORED_FILES
IGNORE_GITIGNORED_FILES = " ${ IGNORE_GITIGNORED_FILES :- false } "
2024-01-30 14:24:55 -05:00
export IGNORE_GITIGNORED_FILES
2024-01-11 15:30:00 -05:00
# We want a lowercase value
declare -l MULTI_STATUS
MULTI_STATUS = " ${ MULTI_STATUS :- true } "
2024-07-01 08:50:52 -04:00
# We want a lowercase value
declare -l SAVE_SUPER_LINTER_OUTPUT
SAVE_SUPER_LINTER_OUTPUT = " ${ SAVE_SUPER_LINTER_OUTPUT :- false } "
2024-01-11 15:30:00 -05:00
# We want a lowercase value
declare -l SSH_INSECURE_NO_VERIFY_GITHUB_KEY
SSH_INSECURE_NO_VERIFY_GITHUB_KEY = " ${ SSH_INSECURE_NO_VERIFY_GITHUB_KEY :- false } "
# We want a lowercase value
declare -l SSH_SETUP_GITHUB
SSH_SETUP_GITHUB = " ${ SSH_SETUP_GITHUB :- false } "
# We want a lowercase value
declare -l SUPPRESS_FILE_TYPE_WARN
SUPPRESS_FILE_TYPE_WARN = " ${ SUPPRESS_FILE_TYPE_WARN :- false } "
# We want a lowercase value
declare -l SUPPRESS_POSSUM
SUPPRESS_POSSUM = " ${ SUPPRESS_POSSUM :- false } "
# We want a lowercase value
declare -l TEST_CASE_RUN
# Option to tell code to run only test cases
TEST_CASE_RUN = " ${ TEST_CASE_RUN :- "false" } "
2024-04-08 14:48:30 -04:00
export TEST_CASE_RUN
2024-01-11 15:30:00 -05:00
2024-08-12 06:31:38 -04:00
declare -l FIX_MODE_TEST_CASE_RUN
FIX_MODE_TEST_CASE_RUN = " ${ FIX_MODE_TEST_CASE_RUN :- "false" } "
export FIX_MODE_TEST_CASE_RUN
2024-01-11 15:30:00 -05:00
# We want a lowercase value
declare -l USE_FIND_ALGORITHM
USE_FIND_ALGORITHM = " ${ USE_FIND_ALGORITHM :- false } "
# We want a lowercase value
declare -l VALIDATE_ALL_CODEBASE
VALIDATE_ALL_CODEBASE = " ${ VALIDATE_ALL_CODEBASE :- "true" } "
# We want a lowercase value
declare -l YAML_ERROR_ON_WARNING
YAML_ERROR_ON_WARNING = " ${ YAML_ERROR_ON_WARNING :- false } "
2024-07-28 15:34:40 -04:00
# We want a lowercase value
declare -l SAVE_SUPER_LINTER_SUMMARY
SAVE_SUPER_LINTER_SUMMARY = " ${ SAVE_SUPER_LINTER_SUMMARY :- false } "
2024-08-31 13:50:00 -04:00
declare -l REMOVE_ANSI_COLOR_CODES_FROM_OUTPUT
REMOVE_ANSI_COLOR_CODES_FROM_OUTPUT = " ${ REMOVE_ANSI_COLOR_CODES_FROM_OUTPUT :- "false" } "
export REMOVE_ANSI_COLOR_CODES_FROM_OUTPUT
2024-08-01 12:40:30 -04:00
# Define private output paths early because cleanup depends on those being defined
DEFAULT_SUPER_LINTER_OUTPUT_DIRECTORY_NAME = "super-linter-output"
SUPER_LINTER_OUTPUT_DIRECTORY_NAME = " ${ SUPER_LINTER_OUTPUT_DIRECTORY_NAME :- ${ DEFAULT_SUPER_LINTER_OUTPUT_DIRECTORY_NAME } } "
export SUPER_LINTER_OUTPUT_DIRECTORY_NAME
debug " Super-linter main output directory name: ${ SUPER_LINTER_OUTPUT_DIRECTORY_NAME } "
SUPER_LINTER_PRIVATE_OUTPUT_DIRECTORY_PATH = " /tmp/ ${ DEFAULT_SUPER_LINTER_OUTPUT_DIRECTORY_NAME } "
export SUPER_LINTER_PRIVATE_OUTPUT_DIRECTORY_PATH
debug " Super-linter private output directory path: ${ SUPER_LINTER_PRIVATE_OUTPUT_DIRECTORY_PATH } "
mkdir -p " ${ SUPER_LINTER_PRIVATE_OUTPUT_DIRECTORY_PATH } "
2024-08-14 16:20:56 -04:00
FIX_MODE_ENABLED = "false"
2024-01-11 15:30:00 -05:00
ValidateBooleanConfigurationVariables
2023-12-12 14:57:15 -05: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
###########
2024-01-11 15:30:00 -05:00
DEFAULT_RULES_LOCATION = '/action/lib/.automation' # Default rules files location
DEFAULT_SUPER_LINTER_WORKSPACE = "/tmp/lint" # Fall-back value for the workspace
DEFAULT_WORKSPACE = " ${ DEFAULT_WORKSPACE :- ${ DEFAULT_SUPER_LINTER_WORKSPACE } } " # Default workspace if running locally
FILTER_REGEX_INCLUDE = " ${ FILTER_REGEX_INCLUDE :- "" } "
2024-06-19 12:58:11 -04:00
export FILTER_REGEX_INCLUDE
2024-01-11 15:30:00 -05:00
FILTER_REGEX_EXCLUDE = " ${ FILTER_REGEX_EXCLUDE :- "" } "
2024-06-19 12:58:11 -04:00
export FILTER_REGEX_EXCLUDE
2024-01-11 15:30:00 -05:00
# shellcheck disable=SC2034 # Variable is referenced in other scripts
RAW_FILE_ARRAY = ( ) # Array of all files that were changed
# shellcheck disable=SC2034 # Variable is referenced in other scripts
TEST_CASE_FOLDER = 'test/linters' # Folder for test cases we should always ignore
2023-12-05 03:04:13 -05:00
2023-12-15 04:29:34 -05:00
# Set the log level
TF_LOG_LEVEL = "info"
2024-02-20 14:05:39 -05:00
if [ [ " ${ LOG_DEBUG } " = = "true" ] ] ; then
2023-12-15 04:29:34 -05:00
TF_LOG_LEVEL = "debug"
fi
export TF_LOG_LEVEL
debug " TF_LOG_LEVEL: ${ TF_LOG_LEVEL } "
TFLINT_LOG = " ${ TF_LOG_LEVEL } "
export TFLINT_LOG
debug " TFLINT_LOG: ${ TFLINT_LOG } "
2024-08-05 02:56:56 -04:00
# Load linter configuration and rules files
# shellcheck source=/dev/null
source /action/lib/globals/linterRules.sh
2020-06-18 19:40:41 -04:00
2024-08-05 02:56:56 -04:00
# Load languages array
2024-07-31 11:00:41 -04:00
# shellcheck source=/dev/null
source /action/lib/globals/languages.sh
2020-07-21 09:12:28 -04:00
2020-07-01 17:40:40 -04:00
Header( ) {
2021-01-19 12:03:14 -05:00
if [ [ " ${ SUPPRESS_POSSUM } " = = "false" ] ] ; then
2024-04-19 09:18:04 -04:00
info " $( /bin/bash /action/lib/functions/possum.sh) "
2021-01-19 12:03:14 -05:00
fi
2020-05-06 11:03:06 -04:00
2020-07-30 16:39:05 -04:00
info "---------------------------------------------"
info "--- GitHub Actions Multi Language Linter ----"
2024-02-20 14:05:39 -05:00
info " - Image Creation Date: ${ BUILD_DATE } "
info " - Image Revision: ${ BUILD_REVISION } "
info " - Image Version: ${ BUILD_VERSION } "
2020-07-30 16:39:05 -04:00
info "---------------------------------------------"
info "---------------------------------------------"
info "The Super-Linter source code can be found at:"
2023-08-17 11:12:11 -04:00
info " - https://github.com/super-linter/super-linter"
2020-07-30 16:39:05 -04:00
info "---------------------------------------------"
2024-01-11 15:30:00 -05:00
if [ [ ${ VALIDATE_ALL_CODEBASE } != "false" ] ] ; then
VALIDATE_ALL_CODEBASE = "true"
info "- Validating all files in code base..."
else
info "- Validating changed files in code base..."
fi
2019-10-21 12:05:55 -04:00
}
2023-12-07 14:07:22 -05:00
ConfigureGitSafeDirectories( ) {
debug "Configuring Git safe directories"
declare -a git_safe_directories = ( " ${ GITHUB_WORKSPACE } " " ${ DEFAULT_SUPER_LINTER_WORKSPACE } " " ${ DEFAULT_WORKSPACE } " )
for safe_directory in " ${ git_safe_directories [@] } " ; do
debug " Set ${ safe_directory } as a Git safe directory "
if ! git config --global --add safe.directory " ${ safe_directory } " ; then
fatal " Cannot configure ${ safe_directory } as a Git safe directory. "
fi
done
}
2020-07-01 17:40:40 -04:00
GetGitHubVars( ) {
2020-07-30 16:39:05 -04:00
info "--------------------------------------------"
info "Gathering GitHub information..."
2019-10-21 15:12:37 -04:00
2024-02-08 03:41:07 -05:00
local GITHUB_REPOSITORY_DEFAULT_BRANCH
GITHUB_REPOSITORY_DEFAULT_BRANCH = "master"
2020-07-21 13:09:07 -04:00
if [ [ ${ RUN_LOCAL } != "false" ] ] ; then
2023-12-07 14:07:22 -05:00
info " RUN_LOCAL has been set to: ${ RUN_LOCAL } . Bypassing GitHub Actions variables... "
2020-06-19 13:31:53 -04:00
2024-02-20 14:05:39 -05:00
if [ -z " ${ GITHUB_WORKSPACE :- } " ] ; then
2020-07-21 13:09:07 -04:00
GITHUB_WORKSPACE = " ${ DEFAULT_WORKSPACE } "
2020-06-19 13:31:53 -04:00
fi
2020-06-29 10:55:59 -04:00
2024-01-11 15:30:00 -05:00
ValidateGitHubWorkspace " ${ GITHUB_WORKSPACE } "
2020-07-06 17:57:30 -04:00
2023-11-05 00:29:52 -04:00
pushd " ${ GITHUB_WORKSPACE } " >/dev/null || exit 1
2020-01-09 11:29:18 -05:00
2023-12-07 14:07:22 -05:00
if [ [ " ${ USE_FIND_ALGORITHM } " = = "false" ] ] ; then
ConfigureGitSafeDirectories
debug " Initializing GITHUB_SHA considering ${ GITHUB_WORKSPACE } "
2024-01-30 02:48:24 -05:00
if ! GITHUB_SHA = $( git -C " ${ GITHUB_WORKSPACE } " rev-parse HEAD) ; then
2023-12-07 14:07:22 -05:00
fatal " Failed to initialize GITHUB_SHA. Output: ${ GITHUB_SHA } "
fi
debug " GITHUB_SHA: ${ GITHUB_SHA } "
else
debug "Skip the initalization of GITHUB_SHA because we don't need it"
fi
2023-12-14 15:22:49 -05:00
MULTI_STATUS = "false"
debug " Setting MULTI_STATUS to ${ MULTI_STATUS } because we are not running on GitHub Actions "
2019-10-21 15:12:37 -04:00
else
2024-01-11 15:30:00 -05:00
ValidateGitHubWorkspace " ${ GITHUB_WORKSPACE } "
2019-10-21 15:12:37 -04:00
2024-01-04 16:54:47 -05:00
# Ensure that Git can access the local repository
ConfigureGitSafeDirectories
2024-04-18 02:48:55 -04:00
if [ -z " ${ GITHUB_EVENT_PATH :- } " ] ; then
2024-01-04 16:54:47 -05:00
fatal " Failed to get GITHUB_EVENT_PATH: ${ GITHUB_EVENT_PATH } ] "
2020-01-09 11:29:18 -05:00
else
2024-01-15 13:37:45 -05:00
info " Successfully found GITHUB_EVENT_PATH: ${ GITHUB_EVENT_PATH } ] "
2024-01-04 16:54:47 -05:00
debug " ${ GITHUB_EVENT_PATH } contents: $( cat " ${ GITHUB_EVENT_PATH } " ) "
2020-01-09 11:29:18 -05:00
fi
2019-10-21 15:12:37 -04:00
2024-04-18 02:48:55 -04:00
if [ -z " ${ GITHUB_SHA :- } " ] ; then
2024-01-04 16:54:47 -05:00
fatal " Failed to get GITHUB_SHA: ${ GITHUB_SHA } "
2023-12-04 04:47:49 -05:00
else
2024-01-15 13:37:45 -05:00
info " Successfully found GITHUB_SHA: ${ GITHUB_SHA } "
2023-12-04 04:47:49 -05:00
fi
2024-04-18 02:48:55 -04:00
if ! GIT_ROOT_COMMIT_SHA = " $( git -C " ${ GITHUB_WORKSPACE } " rev-list --max-parents= 0 " ${ GITHUB_SHA } " ) " ; then
fatal " Failed to get the root commit: ${ GIT_ROOT_COMMIT_SHA } "
else
debug " Successfully found the root commit: ${ GIT_ROOT_COMMIT_SHA } "
fi
export GIT_ROOT_COMMIT_SHA
2020-01-09 11:29:18 -05:00
##################################################
# Need to pull the GitHub Vars from the env file #
##################################################
2020-09-05 06:25:44 -04:00
GITHUB_ORG = $( jq -r '.repository.owner.login' <" ${ GITHUB_EVENT_PATH } " )
2020-01-09 11:29:18 -05:00
2021-03-04 14:51:44 -05:00
# Github sha on PR events is not the latest commit.
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request
if [ " $GITHUB_EVENT_NAME " = = "pull_request" ] ; then
2024-01-04 16:54:47 -05:00
debug " This is a GitHub pull request. Updating the current GITHUB_SHA ( ${ GITHUB_SHA } ) to the pull request HEAD SHA "
2023-12-04 04:47:49 -05:00
2024-01-30 02:48:24 -05:00
if ! GITHUB_SHA = $( jq -r .pull_request.head.sha <" $GITHUB_EVENT_PATH " ) ; then
2024-01-04 16:54:47 -05:00
fatal " Failed to update GITHUB_SHA for pull request event: ${ GITHUB_SHA } "
2023-12-04 04:47:49 -05:00
fi
debug " Updated GITHUB_SHA: ${ GITHUB_SHA } "
2023-12-23 13:33:53 -05:00
elif [ " ${ GITHUB_EVENT_NAME } " = = "push" ] ; then
debug "This is a GitHub push event."
2024-04-18 02:48:55 -04:00
if [ [ " ${ GITHUB_SHA } " = = " ${ GIT_ROOT_COMMIT_SHA } " ] ] ; then
debug " ${ GITHUB_SHA } is the initial commit. Skip initializing GITHUB_BEFORE_SHA because there no commit before the initial commit "
else
debug " ${ GITHUB_SHA } is not the initial commit "
GITHUB_PUSH_COMMIT_COUNT = $( GetGithubPushEventCommitCount " $GITHUB_EVENT_PATH " )
if [ -z " ${ GITHUB_PUSH_COMMIT_COUNT } " ] ; then
fatal "Failed to get GITHUB_PUSH_COMMIT_COUNT"
fi
info " Successfully found GITHUB_PUSH_COMMIT_COUNT: ${ GITHUB_PUSH_COMMIT_COUNT } "
# Ref: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
debug "Get the hash of the commit to start the diff from from Git because the GitHub push event payload may not contain references to base_ref or previous commit."
2024-08-02 04:37:27 -04:00
debug "Check if the commit is a merge commit by checking if it has more than one parent"
local GIT_COMMIT_PARENTS_COUNT
GIT_COMMIT_PARENTS_COUNT = $( git -C " ${ GITHUB_WORKSPACE } " rev-list --parents -n 1 " ${ GITHUB_SHA } " | wc -w)
debug " Git commit parents count (GIT_COMMIT_PARENTS_COUNT): ${ GIT_COMMIT_PARENTS_COUNT } "
GIT_COMMIT_PARENTS_COUNT = $(( GIT_COMMIT_PARENTS_COUNT - 1 ))
debug " Subtract 1 from GIT_COMMIT_PARENTS_COUNT to get the actual number of merge parents because the count includes the commit itself. GIT_COMMIT_PARENTS_COUNT: ${ GIT_COMMIT_PARENTS_COUNT } "
# Ref: https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt
local GIT_BEFORE_SHA_HEAD = "HEAD"
if [ ${ GIT_COMMIT_PARENTS_COUNT } -gt 1 ] ; then
debug " ${ GITHUB_SHA } is a merge commit because it has more than one parent. "
GIT_BEFORE_SHA_HEAD = " ${ GIT_BEFORE_SHA_HEAD } ^2 "
debug " Add the suffix to GIT_BEFORE_SHA_HEAD to get the second parent of the merge commit: ${ GIT_BEFORE_SHA_HEAD } "
GITHUB_PUSH_COMMIT_COUNT = $(( GITHUB_PUSH_COMMIT_COUNT - 1 ))
debug " Remove one commit from GITHUB_PUSH_COMMIT_COUNT to account for the merge commit. GITHUB_PUSH_COMMIT_COUNT: ${ GITHUB_PUSH_COMMIT_COUNT } "
else
debug " ${ GITHUB_SHA } is not a merge commit because it has a single parent. No need to add the parent identifier (^) to the revision indicator because it's implicitly set to ^1 when there's only one parent. "
fi
GIT_BEFORE_SHA_HEAD = " ${ GIT_BEFORE_SHA_HEAD } ~ ${ GITHUB_PUSH_COMMIT_COUNT } "
debug " GIT_BEFORE_SHA_HEAD: ${ GIT_BEFORE_SHA_HEAD } "
2024-04-18 02:48:55 -04:00
# shellcheck disable=SC2086 # We checked that GITHUB_PUSH_COMMIT_COUNT is an integer
2024-08-02 04:37:27 -04:00
if ! GITHUB_BEFORE_SHA = $( git -C " ${ GITHUB_WORKSPACE } " rev-parse ${ GIT_BEFORE_SHA_HEAD } ) ; then
2024-04-18 02:48:55 -04:00
fatal " Failed to initialize GITHUB_BEFORE_SHA for a push event. Output: ${ GITHUB_BEFORE_SHA } "
fi
ValidateGitBeforeShaReference
info " Successfully found GITHUB_BEFORE_SHA: ${ GITHUB_BEFORE_SHA } "
2024-01-04 16:54:47 -05:00
fi
2021-03-04 14:51:44 -05:00
fi
2020-01-09 11:29:18 -05:00
############################
# Validate we have a value #
############################
2020-07-21 13:09:07 -04:00
if [ -z " ${ GITHUB_ORG } " ] ; then
2020-07-30 16:39:05 -04:00
error "Failed to get [GITHUB_ORG]!"
fatal " [ ${ GITHUB_ORG } ] "
2020-01-09 11:29:18 -05:00
else
2024-01-15 13:37:45 -05:00
info " Successfully found GITHUB_ORG: ${ GITHUB_ORG } "
2020-01-09 11:29:18 -05:00
fi
#######################
# Get the GitHub Repo #
#######################
2020-09-05 06:25:44 -04:00
GITHUB_REPO = $( jq -r '.repository.name' <" ${ GITHUB_EVENT_PATH } " )
2020-01-09 11:29:18 -05:00
############################
# Validate we have a value #
############################
2020-07-21 13:09:07 -04:00
if [ -z " ${ GITHUB_REPO } " ] ; then
2020-07-30 16:39:05 -04:00
error "Failed to get [GITHUB_REPO]!"
fatal " [ ${ GITHUB_REPO } ] "
2020-01-09 11:29:18 -05:00
else
2024-01-15 13:37:45 -05:00
info " Successfully found GITHUB_REPO: ${ GITHUB_REPO } "
2020-01-09 11:29:18 -05:00
fi
2024-02-08 03:41:07 -05:00
GITHUB_REPOSITORY_DEFAULT_BRANCH = $( GetGithubRepositoryDefaultBranch " ${ GITHUB_EVENT_PATH } " )
fi
if [ -z " ${ GITHUB_REPOSITORY_DEFAULT_BRANCH } " ] ; then
fatal "Failed to get GITHUB_REPOSITORY_DEFAULT_BRANCH"
else
debug " Successfully detected the default branch for this repository: ${ GITHUB_REPOSITORY_DEFAULT_BRANCH } "
fi
DEFAULT_BRANCH = " ${ DEFAULT_BRANCH :- ${ GITHUB_REPOSITORY_DEFAULT_BRANCH } } "
if [ [ " ${ DEFAULT_BRANCH } " != " ${ GITHUB_REPOSITORY_DEFAULT_BRANCH } " ] ] ; then
debug " The default branch for this repository was set to ${ GITHUB_REPOSITORY_DEFAULT_BRANCH } , but it was explicitly overridden using the DEFAULT_BRANCH variable, and set to: ${ DEFAULT_BRANCH } "
2019-10-21 15:12:37 -04:00
fi
2024-02-08 03:41:07 -05:00
info " The default branch for this repository is set to: ${ DEFAULT_BRANCH } "
2020-07-20 15:07:56 -04:00
2023-12-14 15:22:49 -05:00
if [ " ${ MULTI_STATUS } " = = "true" ] ; then
2020-07-20 15:07:56 -04:00
2023-12-14 15:22:49 -05:00
if [ [ ${ RUN_LOCAL } = = "true" ] ] ; then
# Safety check. This shouldn't occur because we forcefully set MULTI_STATUS=false above
# when RUN_LOCAL=true
fatal "Cannot enable status reports when running locally."
fi
2024-04-18 02:48:55 -04:00
if [ -z " ${ GITHUB_TOKEN :- } " ] ; then
2023-12-14 15:22:49 -05:00
fatal "Failed to get [GITHUB_TOKEN]. Terminating because status reports were explicitly enabled, but GITHUB_TOKEN was not provided."
else
2024-01-15 13:37:45 -05:00
info "Successfully found GITHUB_TOKEN."
2023-12-14 15:22:49 -05:00
fi
2020-07-20 15:07:56 -04:00
2024-04-18 02:48:55 -04:00
if [ -z " ${ GITHUB_REPOSITORY :- } " ] ; then
2020-07-30 16:39:05 -04:00
error "Failed to get [GITHUB_REPOSITORY]!"
fatal " [ ${ GITHUB_REPOSITORY } ] "
2020-07-20 15:07:56 -04:00
else
2024-01-15 13:37:45 -05:00
info " Successfully found GITHUB_REPOSITORY: ${ GITHUB_REPOSITORY } "
2020-07-20 15:07:56 -04:00
fi
2024-04-18 02:48:55 -04:00
if [ -z " ${ GITHUB_RUN_ID :- } " ] ; then
2020-07-30 16:39:05 -04:00
error "Failed to get [GITHUB_RUN_ID]!"
fatal " [ ${ GITHUB_RUN_ID } ] "
2020-01-09 11:29:18 -05:00
else
2024-01-15 13:37:45 -05:00
info " Successfully found GITHUB_RUN_ID ${ GITHUB_RUN_ID } "
2020-01-09 11:29:18 -05:00
fi
2024-02-09 13:45:44 -05:00
GITHUB_STATUS_URL = " ${ GITHUB_API_URL } /repos/ ${ GITHUB_REPOSITORY } /statuses/ ${ GITHUB_SHA } "
debug " GitHub Status URL: ${ GITHUB_STATUS_URL } "
GITHUB_STATUS_TARGET_URL = " ${ GITHUB_SERVER_URL } / ${ GITHUB_REPOSITORY } /actions/runs/ ${ GITHUB_RUN_ID } "
debug " GitHub Status target URL: ${ GITHUB_STATUS_TARGET_URL } "
2023-12-14 15:22:49 -05:00
else
debug " Skip GITHUB_TOKEN, GITHUB_REPOSITORY, and GITHUB_RUN_ID validation because we don't need these variables for GitHub Actions status reports. MULTI_STATUS: ${ MULTI_STATUS } "
2019-10-21 15:12:37 -04:00
fi
2024-01-30 14:24:55 -05:00
# We need this for parallel
export GITHUB_WORKSPACE
2020-04-27 13:21:38 -04:00
}
2024-02-20 14:05:39 -05:00
2020-07-20 15:07:56 -04:00
CallStatusAPI( ) {
2023-03-19 01:54:32 -04:00
LANGUAGE = " ${ 1 } " # language that was validated
2020-07-30 16:39:05 -04:00
STATUS = " ${ 2 } " # success | error
2020-07-20 15:07:56 -04:00
SUCCESS_MSG = 'No errors were found in the linting process'
FAIL_MSG = 'Errors were detected, please view logs'
2020-07-30 16:39:05 -04:00
MESSAGE = '' # Message to send to status API
2020-07-20 15:07:56 -04:00
2021-03-02 09:29:12 -05:00
debug " Calling Multi-Status API for $LANGUAGE with status $STATUS "
2020-07-20 15:07:56 -04:00
######################################
# Check the status to create message #
######################################
2020-07-21 13:09:07 -04:00
if [ " ${ STATUS } " = = "success" ] ; then
2020-07-20 15:07:56 -04:00
# Success
2020-07-21 13:09:07 -04:00
MESSAGE = " ${ SUCCESS_MSG } "
2020-07-20 15:07:56 -04:00
else
# Failure
2020-07-21 13:09:07 -04:00
MESSAGE = " ${ FAIL_MSG } "
2020-07-20 15:07:56 -04:00
fi
2020-07-21 11:13:15 -04:00
##########################################################
# Check to see if were enabled for multi Status mesaages #
##########################################################
2020-08-19 15:18:49 -04:00
if [ " ${ MULTI_STATUS } " = = "true" ] && [ -n " ${ GITHUB_TOKEN } " ] && [ -n " ${ GITHUB_REPOSITORY } " ] ; then
2020-09-03 19:37:10 -04:00
# make sure we honor DISABLE_ERRORS
if [ " ${ DISABLE_ERRORS } " = = "true" ] ; then
STATUS = "success"
fi
2020-07-21 11:13:15 -04:00
##############################################
# Call the status API to create status check #
##############################################
2024-01-30 02:48:24 -05:00
if ! SEND_STATUS_CMD = $(
2022-09-28 09:45:01 -04:00
curl -f -s --show-error -X POST \
2024-02-09 13:45:44 -05:00
--url " ${ GITHUB_STATUS_URL } " \
2020-09-15 01:44:55 -04:00
-H 'accept: application/vnd.github.v3+json' \
-H " authorization: Bearer ${ GITHUB_TOKEN } " \
-H 'content-type: application/json' \
-d " { \"state\": \" ${ STATUS } \",
2024-02-09 13:45:44 -05:00
\" target_url\" : \" ${ GITHUB_STATUS_TARGET_URL } \" ,
2020-07-21 13:09:07 -04:00
\" description\" : \" ${ MESSAGE } \" , \" context\" : \" --> Linted: ${ LANGUAGE } \"
2020-09-09 14:22:32 -04:00
} " 2>&1
2024-01-30 02:48:24 -05:00
) ; then
2023-12-05 03:04:13 -05:00
info " Failed to call GitHub Status API: ${ SEND_STATUS_CMD } "
2020-07-01 08:49:17 -04:00
fi
fi
}
2024-01-30 14:24:55 -05:00
2020-07-22 15:49:26 -04:00
Footer( ) {
2020-07-30 16:39:05 -04:00
info "----------------------------------------------"
info "----------------------------------------------"
2020-07-22 15:49:26 -04:00
2024-01-30 14:24:55 -05:00
local ANY_LINTER_SUCCESS
ANY_LINTER_SUCCESS = "false"
local SUPER_LINTER_EXIT_CODE
SUPER_LINTER_EXIT_CODE = 0
2020-07-21 09:23:32 -04:00
2024-07-28 15:34:40 -04:00
if [ [ " ${ SAVE_SUPER_LINTER_SUMMARY } " = = "true" ] ] ; then
debug " Saving Super-linter summary to ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } "
2024-07-30 02:35:14 -04:00
WriteSummaryHeader " ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } "
2024-07-11 04:01:11 -04:00
fi
2020-07-01 17:40:40 -04:00
for LANGUAGE in " ${ LANGUAGE_ARRAY [@] } " ; do
2024-01-30 14:24:55 -05:00
# This used to be the count of errors found for a given LANGUAGE, but since
# after we switched to running linters against a batch of files, it may not
# represent the actual number of files that didn't pass the validation,
# but a number that's less than that because of how GNU parallel returns
# exit codes.
# Ref: https://www.gnu.org/software/parallel/parallel.html#exit-status
2024-07-01 08:50:52 -04:00
ERROR_COUNTER_FILE_PATH = " ${ SUPER_LINTER_PRIVATE_OUTPUT_DIRECTORY_PATH } /super-linter-parallel-command-exit-code- ${ LANGUAGE } "
2024-01-30 14:24:55 -05:00
if [ ! -f " ${ ERROR_COUNTER_FILE_PATH } " ] ; then
debug " Error counter ${ ERROR_COUNTER_FILE_PATH } doesn't exist "
else
ERROR_COUNTER = $( <" ${ ERROR_COUNTER_FILE_PATH } " )
debug " ERROR_COUNTER for ${ LANGUAGE } : ${ ERROR_COUNTER } "
if [ [ ${ ERROR_COUNTER } -ne 0 ] ] ; then
error " Errors found in ${ LANGUAGE } "
2024-07-11 04:01:11 -04:00
2024-07-28 15:34:40 -04:00
if [ [ " ${ SAVE_SUPER_LINTER_SUMMARY } " = = "true" ] ] ; then
2024-07-30 02:35:14 -04:00
WriteSummaryLineFailure " ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } " " ${ LANGUAGE } "
2024-07-11 04:01:11 -04:00
fi
2024-08-14 12:16:44 -04:00
# Print stdout and stderr in case the log level is higher than INFO
# so users still get feedback. Print output as error so it gets emitted
2024-02-10 04:16:31 -05:00
if [ [ " ${ LOG_VERBOSE } " != "true" ] ] ; then
local STDOUT_LINTER_FILE_PATH
2024-07-01 08:50:52 -04:00
STDOUT_LINTER_FILE_PATH = " ${ SUPER_LINTER_PRIVATE_OUTPUT_DIRECTORY_PATH } /super-linter-parallel-stdout- ${ LANGUAGE } "
2024-02-10 04:16:31 -05:00
if [ [ -e " ${ STDOUT_LINTER_FILE_PATH } " ] ] ; then
2024-08-14 12:16:44 -04:00
error " Stdout contents for ${ LANGUAGE } :\n------\n $( cat " ${ STDOUT_LINTER_FILE_PATH } " ) \n------ "
2024-02-10 04:16:31 -05:00
else
debug " Stdout output file path for ${ LANGUAGE } ( ${ STDOUT_LINTER_FILE_PATH } ) doesn't exist "
fi
local STDERR_LINTER_FILE_PATH
2024-07-01 08:50:52 -04:00
STDERR_LINTER_FILE_PATH = " ${ SUPER_LINTER_PRIVATE_OUTPUT_DIRECTORY_PATH } /super-linter-parallel-stderr- ${ LANGUAGE } "
2024-02-10 04:16:31 -05:00
if [ [ -e " ${ STDERR_LINTER_FILE_PATH } " ] ] ; then
2024-08-14 12:16:44 -04:00
error " Stderr contents for ${ LANGUAGE } :\n------\n $( cat " ${ STDERR_LINTER_FILE_PATH } " ) \n------ "
2024-02-10 04:16:31 -05:00
else
debug " Stderr output file path for ${ LANGUAGE } ( ${ STDERR_LINTER_FILE_PATH } ) doesn't exist "
fi
fi
2024-01-30 14:24:55 -05:00
CallStatusAPI " ${ LANGUAGE } " "error"
SUPER_LINTER_EXIT_CODE = 1
debug " Setting super-linter exit code to ${ SUPER_LINTER_EXIT_CODE } because there were errors for ${ LANGUAGE } "
elif [ [ ${ ERROR_COUNTER } -eq 0 ] ] ; then
notice " Successfully linted ${ LANGUAGE } "
2024-07-28 15:34:40 -04:00
if [ [ " ${ SAVE_SUPER_LINTER_SUMMARY } " = = "true" ] ] ; then
2024-07-30 02:35:14 -04:00
WriteSummaryLineSuccess " ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } " " ${ LANGUAGE } "
2024-07-11 04:01:11 -04:00
fi
2020-09-05 06:25:44 -04:00
CallStatusAPI " ${ LANGUAGE } " "success"
2024-01-30 14:24:55 -05:00
ANY_LINTER_SUCCESS = "true"
debug " Set ANY_LINTER_SUCCESS to ${ ANY_LINTER_SUCCESS } because ${ LANGUAGE } reported a success "
2020-09-05 06:25:44 -04:00
fi
2020-04-27 15:13:12 -04:00
fi
done
2024-01-30 14:24:55 -05:00
if [ [ " ${ ANY_LINTER_SUCCESS } " = = "true" ] ] && [ [ ${ SUPER_LINTER_EXIT_CODE } -ne 0 ] ] ; then
SUPER_LINTER_EXIT_CODE = 2
debug " There was at least one linter that reported a success. Setting the super-linter exit code to: ${ SUPER_LINTER_EXIT_CODE } "
fi
2020-07-21 13:09:07 -04:00
if [ " ${ DISABLE_ERRORS } " = = "true" ] ; then
2024-01-30 14:24:55 -05:00
warn " The super-linter exit code is ${ SUPER_LINTER_EXIT_CODE } . Forcibly setting it to 0 because DISABLE_ERRORS is set to: ${ DISABLE_ERRORS } "
SUPER_LINTER_EXIT_CODE = 0
2020-07-22 15:49:26 -04:00
fi
2024-01-30 14:24:55 -05:00
if [ [ ${ SUPER_LINTER_EXIT_CODE } -eq 0 ] ] ; then
notice "All files and directories linted successfully"
2024-07-28 15:34:40 -04:00
if [ [ " ${ SAVE_SUPER_LINTER_SUMMARY } " = = "true" ] ] ; then
2024-07-30 02:35:14 -04:00
WriteSummaryFooterSuccess " ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } "
2024-07-11 04:01:11 -04:00
fi
2024-01-30 14:24:55 -05:00
else
error "Super-linter detected linting errors"
2024-07-28 15:34:40 -04:00
if [ [ " ${ SAVE_SUPER_LINTER_SUMMARY } " = = "true" ] ] ; then
2024-07-30 02:35:14 -04:00
WriteSummaryFooterFailure " ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } "
2024-07-11 04:01:11 -04:00
fi
fi
2024-07-28 15:34:40 -04:00
if [ [ " ${ SAVE_SUPER_LINTER_SUMMARY } " = = "true" ] ] ; then
2024-08-25 13:43:33 -04:00
if ! FormatSuperLinterSummaryFile " ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } " ; then
fatal "Error while formatting the Super-linter summary file."
fi
2024-07-28 15:34:40 -04:00
debug " Super-linter summary file ( ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } ) contents:\n $( cat " ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } " ) "
fi
2024-07-11 04:01:11 -04:00
if [ [ " ${ ENABLE_GITHUB_ACTIONS_STEP_SUMMARY } " = = "true" ] ] ; then
2024-07-28 15:34:40 -04:00
debug " Appending Super-linter summary to ${ GITHUB_STEP_SUMMARY } "
if ! cat " ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } " >>" ${ GITHUB_STEP_SUMMARY } " ; then
fatal " Error while appending the content of ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } to ${ GITHUB_STEP_SUMMARY } "
fi
2024-01-30 14:24:55 -05:00
fi
2020-07-22 15:49:26 -04:00
2024-01-30 14:24:55 -05:00
exit ${ SUPER_LINTER_EXIT_CODE }
2019-10-21 10:12:50 -04:00
}
2024-02-20 14:05:39 -05:00
2021-05-25 11:14:43 -04:00
UpdateLoopsForImage( ) {
######################################################################
# Need to clean the array lists of the linters removed for the image #
######################################################################
if [ [ " ${ IMAGE } " = = "slim" ] ] ; then
#############################################
# Need to remove linters for the slim image #
#############################################
2024-08-16 10:23:52 -04:00
REMOVE_ARRAY = (
"ARM"
"CSHARP"
"DOTNET_SLN_FORMAT_ANALYZERS"
"DOTNET_SLN_FORMAT_STYLE"
"DOTNET_SLN_FORMAT_WHITESPACE"
"POWERSHELL"
"RUST_2015"
"RUST_2018"
"RUST_2021"
"RUST_CLIPPY"
)
2021-05-25 11:14:43 -04:00
# Remove from LANGUAGE_ARRAY
2024-01-15 13:37:45 -05:00
debug "Removing Languages from LANGUAGE_ARRAY for slim image..."
2021-05-25 11:14:43 -04:00
for REMOVE_LANGUAGE in " ${ REMOVE_ARRAY [@] } " ; do
for INDEX in " ${ !LANGUAGE_ARRAY[@] } " ; do
if [ [ ${ LANGUAGE_ARRAY [INDEX] } = " ${ REMOVE_LANGUAGE } " ] ] ; then
2024-01-15 13:37:45 -05:00
debug " found item:[ ${ REMOVE_LANGUAGE } ], removing Language... "
2021-05-25 11:14:43 -04:00
unset 'LANGUAGE_ARRAY[INDEX]'
fi
done
done
fi
}
2023-01-05 08:32:46 -05:00
2023-01-04 01:17:47 -05:00
# shellcheck disable=SC2317
2020-07-27 17:11:33 -04:00
cleanup( ) {
2020-07-30 16:39:05 -04:00
local -ri EXIT_CODE = $?
2024-02-27 08:57:36 -05:00
debug " Captured exit code: ${ EXIT_CODE } "
2024-01-10 04:06:04 -05:00
2024-02-20 14:05:39 -05:00
if [ -n " ${ GITHUB_WORKSPACE :- } " ] ; then
debug "Removing temporary files and directories"
rm -rf \
" ${ GITHUB_WORKSPACE } /.mypy_cache " \
" ${ GITHUB_WORKSPACE } /logback.log "
2024-01-10 04:06:04 -05:00
2024-02-20 14:05:39 -05:00
if [ [ " ${ SUPER_LINTER_COPIED_R_LINTER_RULES_FILE :- } " = = "true" ] ] ; then
debug " Deleting ${ R_RULES_FILE_PATH_IN_ROOT } because super-linter created it. "
rm -rf " ${ R_RULES_FILE_PATH_IN_ROOT } "
fi
2024-01-10 04:06:04 -05:00
2024-02-20 14:05:39 -05:00
# Define this variable here so we can rely on it as soon as possible
local LOG_FILE_PATH = " ${ GITHUB_WORKSPACE } / ${ LOG_FILE } "
debug " LOG_FILE_PATH: ${ LOG_FILE_PATH } "
if [ " ${ CREATE_LOG_FILE } " = "true" ] ; then
2024-08-31 13:50:00 -04:00
if [ [ " ${ REMOVE_ANSI_COLOR_CODES_FROM_OUTPUT } " = = "true" ] ] &&
! RemoveAnsiColorCodesFromFile " ${ LOG_TEMP } " ; then
fatal " Error while removing ANSI color codes from ${ LOG_TEMP } "
fi
2024-02-20 14:05:39 -05:00
debug " Moving log file from ${ LOG_TEMP } to ${ LOG_FILE_PATH } "
mv \
--force \
" ${ LOG_TEMP } " " ${ LOG_FILE_PATH } "
else
2024-07-01 08:50:52 -04:00
debug " Skip moving the log file from ${ LOG_TEMP } to ${ LOG_FILE_PATH } "
fi
if [ " ${ SAVE_SUPER_LINTER_OUTPUT } " = "true" ] ; then
if [ -e " ${ SUPER_LINTER_OUTPUT_DIRECTORY_PATH } " ] ; then
debug " ${ SUPER_LINTER_OUTPUT_DIRECTORY_PATH } already exists. Deleting it before moving the new output directory there. "
rm -fr " ${ SUPER_LINTER_OUTPUT_DIRECTORY_PATH } "
fi
debug " Moving Super-linter output from ${ SUPER_LINTER_PRIVATE_OUTPUT_DIRECTORY_PATH } to ${ SUPER_LINTER_OUTPUT_DIRECTORY_PATH } "
mv " ${ SUPER_LINTER_PRIVATE_OUTPUT_DIRECTORY_PATH } " " ${ SUPER_LINTER_OUTPUT_DIRECTORY_PATH } "
else
2024-08-01 12:40:30 -04:00
debug " Skip moving the private Super-linter output directory ( ${ SUPER_LINTER_PRIVATE_OUTPUT_DIRECTORY_PATH } ) to the output directory ( ${ SUPER_LINTER_OUTPUT_DIRECTORY_PATH :- "not initialized yet" } ) "
2024-02-20 14:05:39 -05:00
fi
2024-07-01 08:50:52 -04:00
2023-01-05 08:32:46 -05:00
else
2024-02-20 14:05:39 -05:00
debug "GITHUB_WORKSPACE is not set. Skipping filesystem cleanup steps"
2023-01-05 08:32:46 -05:00
fi
2020-07-27 17:11:33 -04:00
2023-01-04 01:17:47 -05:00
exit " ${ EXIT_CODE } "
2020-07-30 16:39:05 -04:00
trap - 0 1 2 3 6 14 15
2019-10-21 10:12:50 -04:00
}
2020-07-27 17:11:33 -04:00
trap 'cleanup' 0 1 2 3 6 14 15
2023-01-05 08:32:46 -05:00
2019-10-21 12:05:55 -04:00
##########
# Header #
##########
Header
2021-05-25 11:14:43 -04:00
################################################
# Need to update the loops for the image style #
################################################
UpdateLoopsForImage
2024-04-19 09:18:04 -04:00
# Print linter versions
info " $( cat " ${ VERSION_FILE } " ) "
2020-11-02 16:39:34 -05:00
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
2023-12-07 14:07:22 -05:00
# Ensure that Git safe directories are configured because we don't do this in
# all cases when initializing variables
ConfigureGitSafeDirectories
2024-02-09 13:45:44 -05:00
############################################
# Create SSH agent and add key if provided #
############################################
SetupSshAgent
SetupGithubComSshKeys
2020-09-21 18:53:30 -04:00
########################################################
# Initialize variables that depend on GitHub variables #
########################################################
2023-12-02 03:35:41 -05:00
TYPESCRIPT_STANDARD_TSCONFIG_FILE = " ${ GITHUB_WORKSPACE } / ${ TYPESCRIPT_STANDARD_TSCONFIG_FILE :- "tsconfig.json" } "
debug " TYPESCRIPT_STANDARD_TSCONFIG_FILE: ${ TYPESCRIPT_STANDARD_TSCONFIG_FILE } "
2024-01-10 04:06:04 -05:00
R_RULES_FILE_PATH_IN_ROOT = " ${ GITHUB_WORKSPACE } / ${ R_FILE_NAME } "
debug " R_RULES_FILE_PATH_IN_ROOT: ${ R_RULES_FILE_PATH_IN_ROOT } "
2024-07-28 15:34:40 -04:00
SUPER_LINTER_MAIN_OUTPUT_DIRECTORY_PATH = " ${ GITHUB_WORKSPACE } / ${ SUPER_LINTER_OUTPUT_DIRECTORY_NAME } "
export SUPER_LINTER_MAIN_OUTPUT_DIRECTORY_PATH
debug " Super-linter main output directory path: ${ SUPER_LINTER_MAIN_OUTPUT_DIRECTORY_PATH } "
2024-07-01 08:50:52 -04:00
2024-07-28 15:34:40 -04:00
SUPER_LINTER_OUTPUT_DIRECTORY_PATH = " ${ SUPER_LINTER_MAIN_OUTPUT_DIRECTORY_PATH } /super-linter "
2024-07-01 08:50:52 -04:00
export SUPER_LINTER_OUTPUT_DIRECTORY_PATH
debug " Super-linter output directory path: ${ SUPER_LINTER_OUTPUT_DIRECTORY_PATH } "
2024-07-28 15:34:40 -04:00
SUPER_LINTER_SUMMARY_OUTPUT_PATH = " ${ SUPER_LINTER_MAIN_OUTPUT_DIRECTORY_PATH } / ${ SUPER_LINTER_SUMMARY_FILE_NAME :- "super-linter-summary.md" } "
export SUPER_LINTER_SUMMARY_OUTPUT_PATH
debug " Super-linter summary output path: ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } "
if [ [ " ${ ENABLE_GITHUB_ACTIONS_STEP_SUMMARY } " = = "true" ] ] && [ [ " ${ SAVE_SUPER_LINTER_SUMMARY } " = = "false" ] ] ; then
debug " ENABLE_GITHUB_ACTIONS_STEP_SUMMARY is set to ${ SAVE_SUPER_LINTER_SUMMARY } , but SAVE_SUPER_LINTER_SUMMARY is set to ${ SAVE_SUPER_LINTER_SUMMARY } "
SAVE_SUPER_LINTER_SUMMARY = "true"
debug " Set SAVE_SUPER_LINTER_SUMMARY to ${ SAVE_SUPER_LINTER_SUMMARY } because we need to append its contents to ${ GITHUB_STEP_SUMMARY } later "
fi
# Ensure that the main output directory and files exist because the user might not have created them
# before running Super-linter. These conditions list all the cases that require an output
# directory to be there.
if [ [ " ${ SAVE_SUPER_LINTER_OUTPUT } " = "true" ] ] ||
[ [ " ${ SAVE_SUPER_LINTER_SUMMARY } " = = "true" ] ] ||
[ [ " ${ CREATE_LOG_FILE } " = "true" ] ] ; then
debug " Ensure that ${ SUPER_LINTER_MAIN_OUTPUT_DIRECTORY_PATH } exists "
mkdir -p " ${ SUPER_LINTER_MAIN_OUTPUT_DIRECTORY_PATH } "
fi
if [ [ " ${ SAVE_SUPER_LINTER_SUMMARY } " = = "true" ] ] ; then
2024-07-30 02:35:14 -04:00
debug " Remove eventual ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } leftover "
rm -f " ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } "
2024-07-28 15:34:40 -04:00
debug " Ensuring that ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } exists. "
if ! touch " ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } " ; then
fatal " Cannot create Super-linter summary file: ${ SUPER_LINTER_SUMMARY_OUTPUT_PATH } "
fi
fi
2020-10-08 18:54:28 -04:00
############################
# Validate the environment #
############################
2024-07-16 04:22:45 -04:00
info "--------------------------------------------"
info "Validating the configuration"
if ! ValidateFindMode; then
fatal "Error while validating the configuration."
fi
if ! ValidateValidationVariables; then
fatal "Error while validating the configuration of enabled linters"
fi
if ! ValidateAnsibleDirectory; then
2024-07-28 15:34:40 -04:00
fatal "Error while validating the configuration of the Ansible directory"
fi
if [ [ " ${ ENABLE_GITHUB_ACTIONS_STEP_SUMMARY } " = = "true" ] ] ||
[ [ " ${ SAVE_SUPER_LINTER_SUMMARY } " = = "true" ] ] ; then
if ! ValidateSuperLinterSummaryOutputPath; then
fatal "Super-linter summary configuration failed validation"
fi
else
debug "Super-linter summary is disabled. No need to validate its configuration."
2024-07-16 04:22:45 -04:00
fi
2023-12-07 14:07:22 -05:00
2023-12-18 13:31:06 -05:00
if [ [ " ${ USE_FIND_ALGORITHM } " = = "false" ] ] || [ [ " ${ IGNORE_GITIGNORED_FILES } " = = "true" ] ] ; then
2023-12-04 04:47:49 -05:00
debug "Validate the local Git environment"
ValidateLocalGitRepository
2024-04-30 11:58:11 -04:00
# We need to validate the commit SHA reference and the default branch only when
# using Git to get the list of files to lint
if [ [ " ${ USE_FIND_ALGORITHM } " = = "false" ] ] ; then
debug "Validate the Git SHA and branch references"
ValidateGitShaReference
ValidateDefaultGitBranch
fi
2023-12-04 04:47:49 -05:00
else
debug "Skipped the validation of the local Git environment because we don't depend on it."
fi
2023-12-24 11:56:15 -05:00
ValidateDeprecatedVariables
2024-02-20 14:05:39 -05:00
# After checking if LOG_LEVEL is set to a deprecated value (see the ValidateDeprecatedVariables function),
# we can unset it so other programs that rely on this variable, such as Checkov and renovate-config-validator
# don't get confused.
unset LOG_LEVEL
2021-06-10 14:09:24 -04:00
#################################
# Get the linter rules location #
#################################
LinterRulesLocation
2019-10-21 12:05:55 -04:00
########################
# Get the linter rules #
########################
2022-03-16 11:21:57 -04:00
for LANGUAGE in " ${ LANGUAGE_ARRAY_FOR_LINTER_RULES [@] } " ; do
2020-10-03 17:01:07 -04:00
debug " Loading rules for ${ LANGUAGE } ... "
2020-10-15 05:43:56 -04:00
eval " GetLinterRules ${ LANGUAGE } ${ DEFAULT_RULES_LOCATION } "
2020-10-03 17:01:07 -04:00
done
2020-02-03 11:27:40 -05:00
2023-12-02 03:35:41 -05:00
# Load rules for special cases
2020-10-08 18:54:28 -04:00
GetStandardRules "javascript"
2024-08-07 09:36:16 -04:00
#############################################################################
# Validate the environment that depends on linter rules variables being set #
#############################################################################
# We need the variables defined in linterCommandsOptions to initialize FIX_....
# variables.
# shellcheck source=/dev/null
source /action/lib/globals/linterCommandsOptions.sh
if ! ValidateCheckModeAndFixModeVariables; then
fatal "Error while validating the configuration fix mode for linters that support that"
fi
2021-04-26 10:00:42 -04:00
#################################
# Check for SSL cert and update #
#################################
CheckSSLCert
2020-10-03 06:55:34 -04:00
###########################################
# Build the list of files for each linter #
###########################################
2023-12-24 11:56:15 -05:00
BuildFileList " ${ VALIDATE_ALL_CODEBASE } " " ${ TEST_CASE_RUN } "
2019-10-21 15:12:37 -04:00
2021-09-10 10:43:20 -04:00
#####################################
# Run additional Installs as needed #
#####################################
RunAdditionalInstalls
2023-12-12 14:57:15 -05:00
endGitHubActionsLogGroup " ${ SUPER_LINTER_INITIALIZATION_LOG_GROUP_TITLE } "
2024-01-30 14:24:55 -05:00
###############
# Run linters #
###############
declare PARALLEL_RESULTS_FILE_PATH
2024-07-01 08:50:52 -04:00
PARALLEL_RESULTS_FILE_PATH = " ${ SUPER_LINTER_PRIVATE_OUTPUT_DIRECTORY_PATH } /super-linter-results.json "
2024-01-30 14:24:55 -05:00
debug " PARALLEL_RESULTS_FILE_PATH: ${ PARALLEL_RESULTS_FILE_PATH } "
2020-06-25 02:13:19 -04:00
2024-08-14 16:20:56 -04:00
declare -i LINTING_MAX_PROCS
LINTING_MAX_PROCS = $( nproc)
CheckIfFixModeIsEnabled
if [ [ " ${ FIX_MODE_ENABLED } " = = "true" ] ] ; then
# This slows down the fix process, but avoids that linters that work on the same
# types of files try opening the same file at the same time
LINTING_MAX_PROCS = 1
debug " Set LINTING_MAX_PROCS to ${ LINTING_MAX_PROCS } to avoid that linters and formatters edit the same file at the same time. "
fi
2024-01-30 14:24:55 -05:00
declare -a PARALLEL_COMMAND
2024-08-14 16:20:56 -04:00
PARALLEL_COMMAND = ( parallel --will-cite --keep-order --max-procs " $(( LINTING_MAX_PROCS)) " --xargs --results " ${ PARALLEL_RESULTS_FILE_PATH } " )
2020-08-17 08:01:25 -04:00
2024-01-30 14:24:55 -05:00
# Run one LANGUAGE per process. Each of these processes will run more processees in parellel if supported
PARALLEL_COMMAND += ( --max-lines 1)
2020-08-15 15:29:22 -04:00
2024-01-30 14:24:55 -05:00
if [ " ${ LOG_DEBUG } " = = "true" ] ; then
debug "LOG_DEBUG is enabled. Enable verbose ouput for parallel"
PARALLEL_COMMAND += ( --verbose)
fi
2020-06-25 02:13:19 -04:00
2024-01-30 14:24:55 -05:00
PARALLEL_COMMAND += ( "LintCodebase" "{}" " \" ${ TEST_CASE_RUN } \" " )
debug " PARALLEL_COMMAND: ${ PARALLEL_COMMAND [*] } "
2020-07-04 18:14:27 -04:00
2024-01-30 14:24:55 -05:00
PARALLEL_COMMAND_OUTPUT = $( printf "%s\n" " ${ LANGUAGE_ARRAY [@] } " | " ${ PARALLEL_COMMAND [@] } " 2>& 1)
PARALLEL_COMMAND_RETURN_CODE = $?
debug " PARALLEL_COMMAND_OUTPUT when running linters (exit code: ${ PARALLEL_COMMAND_RETURN_CODE } ):\n ${ PARALLEL_COMMAND_OUTPUT } "
debug " Parallel output file ( ${ PARALLEL_RESULTS_FILE_PATH } ) contents when running linters:\n $( cat " ${ PARALLEL_RESULTS_FILE_PATH } " ) "
RESULTS_OBJECT =
2024-02-05 05:49:22 -05:00
if ! RESULTS_OBJECT = $( jq --raw-output -n '[inputs]' " ${ PARALLEL_RESULTS_FILE_PATH } " ) ; then
2024-01-30 14:24:55 -05:00
fatal " Error loading results when building the file list: ${ RESULTS_OBJECT } "
fi
debug " RESULTS_OBJECT when running linters:\n ${ RESULTS_OBJECT } "
2024-02-05 05:49:22 -05:00
# Get raw output so we can strip quotes from the data we load. Also, strip the final newline to avoid adding it two times
2024-02-05 12:24:07 -05:00
if ! STDOUT_LINTERS = " $( jq --raw-output '.[] | select(.Stdout[:-1] | length > 0) | .Stdout[:-1]' <<< " ${ RESULTS_OBJECT } " ) " ; then
2024-01-30 14:24:55 -05:00
fatal " Error when loading stdout when running linters:\n ${ STDOUT_LINTERS } "
fi
if [ -n " ${ STDOUT_LINTERS } " ] ; then
info " Command output when running linters:\n------\n ${ STDOUT_LINTERS } \n------ "
else
debug "Stdout when running linters is empty"
fi
2024-02-05 12:24:07 -05:00
if ! STDERR_LINTERS = " $( jq --raw-output '.[] | select(.Stderr[:-1] | length > 0) | .Stderr[:-1]' <<< " ${ RESULTS_OBJECT } " ) " ; then
2024-01-30 14:24:55 -05:00
fatal " Error when loading stderr for ${ FILE_TYPE } :\n ${ STDERR_LINTERS } "
fi
if [ -n " ${ STDERR_LINTERS } " ] ; then
2024-02-05 05:49:22 -05:00
info " Stderr when running linters:\n------\n ${ STDERR_LINTERS } \n------ "
2024-01-30 14:24:55 -05:00
else
debug "Stderr when running linters is empty"
fi
if [ [ ${ PARALLEL_COMMAND_RETURN_CODE } -ne 0 ] ] ; then
fatal " Error when running linters. Exit code: ${ PARALLEL_COMMAND_RETURN_CODE } "
fi
2020-07-23 13:52:43 -04:00
2019-10-21 12:05:55 -04:00
##########
# Footer #
##########
Footer