mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-25 15:41:02 -05:00
Made it a function and put in better place
This commit is contained in:
parent
6792c8bbfa
commit
7bc0f9b8bb
2 changed files with 47 additions and 38 deletions
|
@ -85,7 +85,6 @@ LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
|
|||
"stylelint" "dotenv-linter" "pwsh" "ktlint" "protolint" "clj-kondo"
|
||||
"spectral" "cfn-lint")
|
||||
|
||||
|
||||
#############################
|
||||
# Language array for prints #
|
||||
#############################
|
||||
|
@ -642,6 +641,48 @@ GetGitHubVars()
|
|||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function ValidatePowershellModules ########################################
|
||||
function ValidatePowershellModules()
|
||||
{
|
||||
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
|
||||
if [[ "$VALIDATE_PSSA_MODULE" == "PSScriptAnalyzer" ]]; then
|
||||
VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1)
|
||||
else
|
||||
# Failed to find module
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#########################################
|
||||
# validate we found the script analyzer #
|
||||
#########################################
|
||||
if [[ "$VALIDATE_PSSA_CMD" != "Invoke-ScriptAnalyzer" ]]; then
|
||||
# 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
|
||||
echo "ERROR! Failed find module [PSScriptAnalyzer] for [$LINTER_NAME] in system!"
|
||||
echo "ERROR:[PSSA_MODULE $VALIDATE_PSSA_MODULE] [PSSA_CMD $VALIDATE_PSSA_CMD]"
|
||||
exit 1
|
||||
else
|
||||
# Success
|
||||
if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then
|
||||
echo "Successfully found module [$VALIDATE_PSSA_MODULE] in system"
|
||||
echo "Successfully found command [$VALIDATE_PSSA_CMD] in system"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
#### Function Footer ###########################################################
|
||||
Footer()
|
||||
{
|
||||
|
@ -1088,6 +1129,11 @@ fi
|
|||
# POWERSHELL LINTING #
|
||||
######################
|
||||
if [ "$VALIDATE_POWERSHELL" == "true" ]; then
|
||||
###############################################################
|
||||
# For POWERSHELL, ensure PSScriptAnalyzer module is available #
|
||||
###############################################################
|
||||
ValidatePowershellModules
|
||||
|
||||
#############################
|
||||
# Lint the powershell files #
|
||||
#############################
|
||||
|
|
|
@ -61,43 +61,6 @@ function LintCodebase()
|
|||
fi
|
||||
fi
|
||||
|
||||
###############################################################
|
||||
# For POWERSHELL, ensure PSScriptAnalyzer module is available #
|
||||
###############################################################
|
||||
if [[ "$FILE_TYPE" == "POWERSHELL" ]]; then
|
||||
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
|
||||
if [[ "$VALIDATE_PSSA_MODULE" == "PSScriptAnalyzer" ]]; then
|
||||
VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1)
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$VALIDATE_PSSA_CMD" != "Invoke-ScriptAnalyzer" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ $ERROR_CODE -ne 0 ]; then
|
||||
# Failed
|
||||
echo "ERROR! Failed find module [PSScriptAnalyzer] for [$LINTER_NAME] in system!"
|
||||
echo "ERROR:[PSSA_MODULE $VALIDATE_PSSA_MODULE] [PSSA_CMD $VALIDATE_PSSA_CMD]"
|
||||
exit 1
|
||||
else
|
||||
# Success
|
||||
if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then
|
||||
echo "Successfully found module [$VALIDATE_PSSA_MODULE] in system"
|
||||
echo "Successfully found command [$VALIDATE_PSSA_CMD] in system"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
##########################
|
||||
# Initialize empty Array #
|
||||
##########################
|
||||
|
|
Loading…
Reference in a new issue