mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-10 02:53:36 -05:00
commit
4672d5fd59
3 changed files with 66 additions and 16 deletions
14
Dockerfile
14
Dockerfile
|
@ -39,15 +39,19 @@ RUN apk add --no-cache \
|
||||||
#########################################
|
#########################################
|
||||||
# Reference: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7
|
# Reference: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7
|
||||||
# Slightly modified to always retrieve latest stable Powershell version
|
# Slightly modified to always retrieve latest stable Powershell version
|
||||||
RUN mkdir -p /opt/microsoft/powershell/7 \
|
# If changing PWSH_VERSION='latest' to a specific version, use format PWSH_VERSION='tags/v7.0.2'
|
||||||
&& curl -s https://api.github.com/repos/powershell/powershell/releases/latest \
|
ARG PWSH_VERSION='latest'
|
||||||
|
ARG PWSH_DIRECTORY='/opt/microsoft/powershell'
|
||||||
|
ARG PSSA_VERSION='latest'
|
||||||
|
RUN mkdir -p ${PWSH_DIRECTORY} \
|
||||||
|
&& curl -s https://api.github.com/repos/powershell/powershell/releases/${PWSH_VERSION} \
|
||||||
| grep browser_download_url \
|
| grep browser_download_url \
|
||||||
| grep linux-alpine-x64 \
|
| grep linux-alpine-x64 \
|
||||||
| cut -d '"' -f 4 \
|
| cut -d '"' -f 4 \
|
||||||
| xargs -n 1 wget -O - \
|
| xargs -n 1 wget -O - \
|
||||||
| tar -xzC /opt/microsoft/powershell/7 \
|
| tar -xzC ${PWSH_DIRECTORY} \
|
||||||
&& ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh \
|
&& ln -s ${PWSH_DIRECTORY}/pwsh /usr/bin/pwsh -f \
|
||||||
&& pwsh -c 'install-module psscriptanalyzer -Scope AllUsers -force'
|
&& pwsh -c 'Install-Module -Name PSScriptAnalyzer -RequiredVersion ${PSSA_VERSION} -Scope AllUsers -Force'
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
# Run Pip3 Installs #
|
# Run Pip3 Installs #
|
||||||
|
|
|
@ -82,10 +82,9 @@ CLOJURE_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CLOJURE_FILE_NAME"
|
||||||
LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
|
LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
|
||||||
"pylint" "perl" "rubocop" "coffeelint" "eslint" "standard"
|
"pylint" "perl" "rubocop" "coffeelint" "eslint" "standard"
|
||||||
"ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint"
|
"ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint"
|
||||||
"stylelint" "dotenv-linter" "powershell" "ktlint" "protolint" "clj-kondo"
|
"stylelint" "dotenv-linter" "pwsh" "ktlint" "protolint" "clj-kondo"
|
||||||
"spectral" "cfn-lint")
|
"spectral" "cfn-lint")
|
||||||
|
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# Language array for prints #
|
# Language array for prints #
|
||||||
#############################
|
#############################
|
||||||
|
@ -642,6 +641,48 @@ GetGitHubVars()
|
||||||
fi
|
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 ###########################################################
|
#### Function Footer ###########################################################
|
||||||
Footer()
|
Footer()
|
||||||
{
|
{
|
||||||
|
@ -1088,11 +1129,16 @@ fi
|
||||||
# POWERSHELL LINTING #
|
# POWERSHELL LINTING #
|
||||||
######################
|
######################
|
||||||
if [ "$VALIDATE_POWERSHELL" == "true" ]; then
|
if [ "$VALIDATE_POWERSHELL" == "true" ]; then
|
||||||
|
###############################################################
|
||||||
|
# For POWERSHELL, ensure PSScriptAnalyzer module is available #
|
||||||
|
###############################################################
|
||||||
|
ValidatePowershellModules
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# Lint the powershell files #
|
# Lint the powershell files #
|
||||||
#############################
|
#############################
|
||||||
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
||||||
LintCodebase "POWERSHELL" "pwsh" "pwsh -c Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}"
|
LintCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
###################
|
###################
|
||||||
|
|
|
@ -35,9 +35,9 @@ function LintCodebase()
|
||||||
PRINT_ARRAY+=("----------------------------------------------")
|
PRINT_ARRAY+=("----------------------------------------------")
|
||||||
PRINT_ARRAY+=("----------------------------------------------")
|
PRINT_ARRAY+=("----------------------------------------------")
|
||||||
|
|
||||||
#######################################
|
#####################################
|
||||||
# Validate we have jsonlint installed #
|
# Validate we have linter installed #
|
||||||
#######################################
|
#####################################
|
||||||
VALIDATE_INSTALL_CMD=$(command -v "$LINTER_NAME" 2>&1)
|
VALIDATE_INSTALL_CMD=$(command -v "$LINTER_NAME" 2>&1)
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
|
@ -56,7 +56,7 @@ function LintCodebase()
|
||||||
else
|
else
|
||||||
# Success
|
# Success
|
||||||
if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then
|
if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then
|
||||||
echo "Successfully found binary in system"
|
echo "Successfully found binary for [$LINTER_NAME] in system"
|
||||||
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
echo "Location:[$VALIDATE_INSTALL_CMD]"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -166,8 +166,8 @@ function LintCodebase()
|
||||||
################################
|
################################
|
||||||
# Lint the file with the rules #
|
# Lint the file with the rules #
|
||||||
################################
|
################################
|
||||||
# Need to append "'" to make the pwsh call syntax correct, also exit with exit code from inner subshell
|
# Need to run PowerShell commands using pwsh -c, also exit with exit code from inner subshell
|
||||||
LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE"; exit $? 2>&1)
|
LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; pwsh -c "($LINTER_COMMAND $FILE)"; exit $? 2>&1)
|
||||||
else
|
else
|
||||||
################################
|
################################
|
||||||
# Lint the file with the rules #
|
# Lint the file with the rules #
|
||||||
|
@ -333,8 +333,8 @@ function TestCodebase()
|
||||||
################################
|
################################
|
||||||
# Lint the file with the rules #
|
# Lint the file with the rules #
|
||||||
################################
|
################################
|
||||||
# Need to append "'" to make the pwsh call syntax correct, also exit with exit code from inner subshell
|
# Need to run PowerShell commands using pwsh -c, also exit with exit code from inner subshell
|
||||||
LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE"; exit $? 2>&1)
|
LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; pwsh -c "($LINTER_COMMAND $FILE)"; exit $? 2>&1)
|
||||||
else
|
else
|
||||||
################################
|
################################
|
||||||
# Lint the file with the rules #
|
# Lint the file with the rules #
|
||||||
|
|
Loading…
Reference in a new issue