From 2e94f3c355d0b8b343387048ab63c4db77db7de0 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Fri, 19 Jun 2020 15:10:34 +0000 Subject: [PATCH 01/25] Feat: Add Powershell to DockerFile --- Dockerfile | 321 +++++++++++++++++++++++++++++------------------------ 1 file changed, 178 insertions(+), 143 deletions(-) diff --git a/Dockerfile b/Dockerfile index da74a9f9..67c5d15f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,143 +1,178 @@ -########################################### -########################################### -## Dockerfile to run GitHub Super-Linter ## -########################################### -########################################### - -################## -# Get base image # -################## -FROM python:alpine - -######################################### -# Label the instance and set maintainer # -######################################### -LABEL com.github.actions.name="GitHub Super-Linter" \ - com.github.actions.description="Lint your code base with GitHub Actions" \ - com.github.actions.icon="code" \ - com.github.actions.color="red" \ - maintainer="GitHub DevOps " - -#################### -# Run APK installs # -#################### -RUN apk add --no-cache \ - bash git git-lfs musl-dev curl gcc jq file\ - npm nodejs \ - libxml2-utils perl \ - ruby ruby-dev ruby-bundler ruby-rdoc make \ - py3-setuptools ansible-lint \ - go - -##################### -# Run Pip3 Installs # -##################### -RUN pip3 --no-cache-dir install --upgrade --no-cache-dir \ - yamllint pylint yq - -#################### -# Run NPM Installs # -#################### -RUN npm config set package-lock false \ - && npm config set loglevel error \ - && npm -g --no-cache install \ - markdownlint-cli \ - jsonlint prettyjson \ - coffeelint \ - typescript eslint \ - standard \ - babel-eslint \ - @typescript-eslint/eslint-plugin \ - @typescript-eslint/parser \ - eslint-plugin-jest \ - && npm --no-cache install \ - markdownlint-cli \ - jsonlint prettyjson \ - coffeelint \ - typescript eslint \ - standard \ - babel-eslint \ - prettier \ - eslint-config-prettier \ - @typescript-eslint/eslint-plugin \ - @typescript-eslint/parser \ - eslint-plugin-jest - -#################################### -# Install dockerfilelint from repo # -#################################### -RUN git clone https://github.com/replicatedhq/dockerfilelint.git && cd /dockerfilelint && npm install - - # I think we could fix this with path but not sure the language... - # https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md - -#################### -# Run GEM installs # -#################### -RUN gem install rubocop:0.74.0 rubocop-rails rubocop-github:0.13.0 - -# Need to fix the version as it installs 'rubocop:0.85.1' as a dep, and forces the default -# We then need to promot the correct verion, uninstall, and fix deps -RUN sh -c 'gem install --default rubocop:0.74.0; yes | gem uninstall rubocop:0.85.1 -a -x -I; gem install rubocop:0.74.0' - -###################### -# Install shellcheck # -###################### -RUN wget -qO- "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz" | tar -xJv \ - && mv "shellcheck-stable/shellcheck" /usr/bin/ - -##################### -# Install Go Linter # -##################### -ARG GO_VERSION='v1.23.7' -RUN wget -O- -nvq https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s "$GO_VERSION" - -################## -# Install TFLint # -################## -RUN curl -Ls "$(curl -Ls https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" -o tflint.zip && unzip tflint.zip && rm tflint.zip \ - && mv "tflint" /usr/bin/ - -########################################### -# Load GitHub Env Vars for GitHub Actions # -########################################### -ENV GITHUB_SHA=${GITHUB_SHA} \ - GITHUB_EVENT_PATH=${GITHUB_EVENT_PATH} \ - GITHUB_WORKSPACE=${GITHUB_WORKSPACE} \ - VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} \ - VALIDATE_YAML=${VALIDATE_YAML} \ - VALIDATE_JSON=${VALIDATE_JSON} \ - VALIDATE_XML=${VALIDATE_XML} \ - VALIDATE_MD=${VALIDATE_MD} \ - VALIDATE_BASH=${VALIDATE_BASH} \ - VALIDATE_PERL=${VALIDATE_PERL} \ - VALIDATE_PYTHON=${VALIDATE_PYTHON} \ - VALIDATE_RUBY=${VALIDATE_RUBY} \ - VALIDATE_COFFEE=${VALIDATE_COFFEE} \ - VALIDATE_ANSIBLE=${VALIDATE_ANSIBLE} \ - VALIDATE_DOCKER=${VALIDATE_DOCKER} \ - VALIDATE_JAVASCRIPT_ES=${VALIDATE_JAVASCRIPT_ES} \ - VALIDATE_JAVASCRIPT_STANDARD=${VALIDATE_JAVASCRIPT_STANDARD} \ - VALIDATE_TYPESCRIPT_ES=${VALIDATE_TYPESCRIPT_ES} \ - VALIDATE_TYPESCRIPT_STANDARD=${VALIDATE_TYPESCRIPT_STANDARD} \ - VALIDATE_GO=${VALIDATE_GO} \ - VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \ - ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \ - RUN_LOCAL=${RUN_LOCAL} \ - TEST_CASE_RUN=${TEST_CASE_RUN} \ - ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} - -############################# -# Copy scripts to container # -############################# -COPY lib /action/lib - -################################## -# Copy linter rules to container # -################################## -COPY TEMPLATES /action/lib/.automation - -###################### -# Set the entrypoint # -###################### -ENTRYPOINT ["/action/lib/linter.sh"] +########################################### +########################################### +## Dockerfile to run GitHub Super-Linter ## +########################################### +########################################### + +################## +# Get base image # +################## +FROM python:alpine + +######################################### +# Label the instance and set maintainer # +######################################### +LABEL com.github.actions.name="GitHub Super-Linter" \ + com.github.actions.description="Lint your code base with GitHub Actions" \ + com.github.actions.icon="code" \ + com.github.actions.color="red" \ + maintainer="GitHub DevOps " + +#################### +# Run APK installs # +#################### +RUN apk add --no-cache \ + bash git git-lfs musl-dev curl gcc jq file\ + npm nodejs \ + libxml2-utils perl \ + ruby ruby-dev ruby-bundler ruby-rdoc make \ + py3-setuptools ansible-lint \ + go + +##################### +# Run Pip3 Installs # +##################### +RUN pip3 --no-cache-dir install --upgrade --no-cache-dir \ + yamllint pylint yq + +#################### +# Run NPM Installs # +#################### +RUN npm config set package-lock false \ + && npm config set loglevel error \ + && npm -g --no-cache install \ + markdownlint-cli \ + jsonlint prettyjson \ + coffeelint \ + typescript eslint \ + standard \ + babel-eslint \ + @typescript-eslint/eslint-plugin \ + @typescript-eslint/parser \ + eslint-plugin-jest \ + && npm --no-cache install \ + markdownlint-cli \ + jsonlint prettyjson \ + coffeelint \ + typescript eslint \ + standard \ + babel-eslint \ + prettier \ + eslint-config-prettier \ + @typescript-eslint/eslint-plugin \ + @typescript-eslint/parser \ + eslint-plugin-jest + +#################################### +# Install dockerfilelint from repo # +#################################### +RUN git clone https://github.com/replicatedhq/dockerfilelint.git && cd /dockerfilelint && npm install + + # I think we could fix this with path but not sure the language... + # https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md + +#################### +# Run GEM installs # +#################### +RUN gem install rubocop:0.74.0 rubocop-rails rubocop-github:0.13.0 + +# Need to fix the version as it installs 'rubocop:0.85.1' as a dep, and forces the default +# We then need to promot the correct verion, uninstall, and fix deps +RUN sh -c 'gem install --default rubocop:0.74.0; yes | gem uninstall rubocop:0.85.1 -a -x -I; gem install rubocop:0.74.0' + +###################### +# Install shellcheck # +###################### +RUN wget -qO- "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz" | tar -xJv \ + && mv "shellcheck-stable/shellcheck" /usr/bin/ + +##################### +# Install Go Linter # +##################### +ARG GO_VERSION='v1.23.7' +RUN wget -O- -nvq https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s "$GO_VERSION" + +################## +# Install TFLint # +################## +RUN curl -Ls "$(curl -Ls https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" -o tflint.zip && unzip tflint.zip && rm tflint.zip \ + && mv "tflint" /usr/bin/ + +######################################### +# Install Powershell + PSScriptAnalyzer # +######################################### +# 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 +RUN apk add --no-cache \ + ca-certificates \ + less \ + ncurses-terminfo-base \ + krb5-libs \ + libgcc \ + libintl \ + libssl1.1 \ + libstdc++ \ + tzdata \ + userspace-rcu \ + zlib \ + icu-libs \ + curl \ + lttng-ust \ + && \ + mkdir -p /opt/microsoft/powershell/7 \ + && \ + curl -s https://api.github.com/repos/powershell/powershell/releases/latest \ + | grep browser_download_url \ + | grep linux-alpine-x64 \ + | cut -d '"' -f 4 \ + | xargs -n 1 wget -O - \ + | tar -xzC /opt/microsoft/powershell/7 \ + && \ + ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh \ + && \ + pwsh -c 'install-module psscriptanalyzer -force' + + +########################################### +# Load GitHub Env Vars for GitHub Actions # +########################################### +ENV GITHUB_SHA=${GITHUB_SHA} \ + GITHUB_EVENT_PATH=${GITHUB_EVENT_PATH} \ + GITHUB_WORKSPACE=${GITHUB_WORKSPACE} \ + VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} \ + VALIDATE_YAML=${VALIDATE_YAML} \ + VALIDATE_JSON=${VALIDATE_JSON} \ + VALIDATE_XML=${VALIDATE_XML} \ + VALIDATE_MD=${VALIDATE_MD} \ + VALIDATE_BASH=${VALIDATE_BASH} \ + VALIDATE_PERL=${VALIDATE_PERL} \ + VALIDATE_PYTHON=${VALIDATE_PYTHON} \ + VALIDATE_RUBY=${VALIDATE_RUBY} \ + VALIDATE_COFFEE=${VALIDATE_COFFEE} \ + VALIDATE_ANSIBLE=${VALIDATE_ANSIBLE} \ + VALIDATE_DOCKER=${VALIDATE_DOCKER} \ + VALIDATE_JAVASCRIPT_ES=${VALIDATE_JAVASCRIPT_ES} \ + VALIDATE_JAVASCRIPT_STANDARD=${VALIDATE_JAVASCRIPT_STANDARD} \ + VALIDATE_TYPESCRIPT_ES=${VALIDATE_TYPESCRIPT_ES} \ + VALIDATE_TYPESCRIPT_STANDARD=${VALIDATE_TYPESCRIPT_STANDARD} \ + VALIDATE_GO=${VALIDATE_GO} \ + VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \ + ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \ + RUN_LOCAL=${RUN_LOCAL} \ + TEST_CASE_RUN=${TEST_CASE_RUN} \ + ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} + +############################# +# Copy scripts to container # +############################# +COPY lib /action/lib + +################################## +# Copy linter rules to container # +################################## +COPY TEMPLATES /action/lib/.automation + +###################### +# Set the entrypoint # +###################### +ENTRYPOINT ["/action/lib/linter.sh"] From d39d5c62ff908cf644e6bc287469c063b35ffc35 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Fri, 19 Jun 2020 16:13:13 +0000 Subject: [PATCH 02/25] Powershell Initial Commit --- .../test/powershell/powershell_bad_1.ps1 | 14 ++++++++++++ .../test/powershell/powershell_good_1.ps1 | 1 + TEMPLATES/.powershell-psscriptanalyzer.psd1 | 18 +++++++++++++++ lib/linter.sh | 22 ++++++++++++++++--- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 .automation/test/powershell/powershell_bad_1.ps1 create mode 100644 .automation/test/powershell/powershell_good_1.ps1 create mode 100644 TEMPLATES/.powershell-psscriptanalyzer.psd1 diff --git a/.automation/test/powershell/powershell_bad_1.ps1 b/.automation/test/powershell/powershell_bad_1.ps1 new file mode 100644 index 00000000..f1709a0a --- /dev/null +++ b/.automation/test/powershell/powershell_bad_1.ps1 @@ -0,0 +1,14 @@ +#Plaintext Parameters +function BadFunction { + param( + [String]$Username = 'me', + [String]$Password = 'password' + ) + $Username + $Password + $VariableThatIsNotUsedLater = '5' + try { + 'Empty Catch Block' + } catch {} +} + diff --git a/.automation/test/powershell/powershell_good_1.ps1 b/.automation/test/powershell/powershell_good_1.ps1 new file mode 100644 index 00000000..d762886f --- /dev/null +++ b/.automation/test/powershell/powershell_good_1.ps1 @@ -0,0 +1 @@ +Write-Output "hello world!" \ No newline at end of file diff --git a/TEMPLATES/.powershell-psscriptanalyzer.psd1 b/TEMPLATES/.powershell-psscriptanalyzer.psd1 new file mode 100644 index 00000000..ab462662 --- /dev/null +++ b/TEMPLATES/.powershell-psscriptanalyzer.psd1 @@ -0,0 +1,18 @@ +#Documentation: https://github.com/PowerShell/PSScriptAnalyzer/blob/master/docs/markdown/Invoke-ScriptAnalyzer.md#-settings +@{ + #CustomRulePath='path\to\CustomRuleModule.psm1' + #RecurseCustomRulePath='path\of\customrules' + #Severity = @( + # 'Error' + # 'Warning' + #) + #IncludeDefaultRules=$true + #ExcludeRules = @( + # 'PSAvoidUsingWriteHost', + # 'MyCustomRuleName' + #) + #IncludeRules = @( + # 'PSAvoidUsingWriteHost', + # 'MyCustomRuleName' + #) +} \ No newline at end of file diff --git a/lib/linter.sh b/lib/linter.sh index 473f53cd..32687755 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -48,20 +48,24 @@ GO_LINTER_RULES="$DEFAULT_RULES_LOCATION/$GO_FILE_NAME" # Path to th # Terraform Vars TERRAFORM_FILE_NAME='.tflint.hcl' # Name of the file TERRAFORM_LINTER_RULES="$DEFAULT_RULES_LOCATION/$TERRAFORM_FILE_NAME" # Path to the Terraform lint rules +# Powershell Vars +POWERSHELL_FILE_NAME='.powershell-psccriptanalyzer.psd1' # Name of the file +POWERSHELL_LINTER_RULES="$DEFAULT_RULES_LOCATION/$POWERSHELL_FILE_NAME" # Path to the Powershell lint rules + ####################################### # Linter array for information prints # ####################################### LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck" "pylint" "perl" "rubocop" "coffeelint" "eslint" "standard" - "ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint") + "ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint" "powershell") ############################# # Language array for prints # ############################# LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RUBY' 'PYTHON' 'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES' - 'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM') + 'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' 'POWERSHELL') ################### # GitHub ENV Vars # @@ -88,6 +92,7 @@ VALIDATE_TYPESCRIPT_STANDARD="${VALIDATE_TYPESCRIPT_STANDARD}" # Boolean to val VALIDATE_DOCKER="${VALIDATE_DOCKER}" # Boolean to validate language VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language +VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases ############## @@ -2225,7 +2230,18 @@ if [ "$VALIDATE_DOCKER" == "true" ]; then LintCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint" ".*\(Dockerfile\)\$" "${FILE_ARRAY_DOCKER[@]}" fi +###################### +# POWERSHELL LINTING # +###################### +if [ "$VALIDATE_POWERSHELL" == "true" ]; then + ############################# + # Lint the powershell files # + ############################# + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -Settings $POWERSHELL_LINTER_RULES -Path' " 'ps[md]?1$' "${FILE_ARRAY_POWERSHELL[@]}" +fi + ########## # Footer # ########## -Footer +Footer \ No newline at end of file From 1e80fc15b5a346a2018d44ef133d42c33eb6e801 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Fri, 19 Jun 2020 12:28:27 -0700 Subject: [PATCH 03/25] Additional File Type test cases --- .automation/test/powershell/powershell.psd1 | 3 +++ .automation/test/powershell/powershell.psm1 | 1 + 2 files changed, 4 insertions(+) create mode 100644 .automation/test/powershell/powershell.psd1 create mode 100644 .automation/test/powershell/powershell.psm1 diff --git a/.automation/test/powershell/powershell.psd1 b/.automation/test/powershell/powershell.psd1 new file mode 100644 index 00000000..68432ff9 --- /dev/null +++ b/.automation/test/powershell/powershell.psd1 @@ -0,0 +1,3 @@ +@{ + 'Hello'='World' +} \ No newline at end of file diff --git a/.automation/test/powershell/powershell.psm1 b/.automation/test/powershell/powershell.psm1 new file mode 100644 index 00000000..d762886f --- /dev/null +++ b/.automation/test/powershell/powershell.psm1 @@ -0,0 +1 @@ +Write-Output "hello world!" \ No newline at end of file From 62fe1b7b41bcba53069c95ad8fc11a3d6a4bfbd6 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Fri, 19 Jun 2020 12:28:58 -0700 Subject: [PATCH 04/25] Add Powershell to Linter --- lib/linter.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 32687755..81e19a20 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -49,7 +49,7 @@ GO_LINTER_RULES="$DEFAULT_RULES_LOCATION/$GO_FILE_NAME" # Path to th TERRAFORM_FILE_NAME='.tflint.hcl' # Name of the file TERRAFORM_LINTER_RULES="$DEFAULT_RULES_LOCATION/$TERRAFORM_FILE_NAME" # Path to the Terraform lint rules # Powershell Vars -POWERSHELL_FILE_NAME='.powershell-psccriptanalyzer.psd1' # Name of the file +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 @@ -133,6 +133,8 @@ FILE_ARRAY_TYPESCRIPT_STANDARD=() # Array of files to check FILE_ARRAY_DOCKER=() # Array of files to check FILE_ARRAY_GO=() # Array of files to check FILE_ARRAY_TERRAFORM=() # Array of files to check +FILE_ARRAY_POWERSHELL=() # Array of files to check + ############ # Counters # @@ -154,6 +156,7 @@ ERRORS_FOUND_TYPESCRIPT_ES=0 # Count of errors found ERRORS_FOUND_DOCKER=0 # Count of errors found ERRORS_FOUND_GO=0 # Count of errors found ERRORS_FOUND_TERRAFORM=0 # Count of errors found +ERRORS_FOUND_POWERSHELL=0 # Count of errors found ################################################################################ ########################## FUNCTIONS BELOW ##################################### @@ -730,6 +733,7 @@ GetValidationInfo() VALIDATE_DOCKER=$(echo "$VALIDATE_DOCKER" | awk '{print tolower($0)}') VALIDATE_GO=$(echo "$VALIDATE_GO" | awk '{print tolower($0)}') VALIDATE_TERRAFORM=$(echo "$VALIDATE_TERRAFORM" | awk '{print tolower($0)}') + VALIDATE_POWERSHELL=$(echo "$VALIDATE_POWERSHELL" | awk '{print tolower($0)}') ################################################ # Determine if any linters were explicitly set # @@ -751,7 +755,9 @@ GetValidationInfo() -n "$VALIDATE_TYPESCRIPT_STANDARD" || \ -n "$VALIDATE_DOCKER" || \ -n "$VALIDATE_GO" || \ - -n "$VALIDATE_TERRAFORM" ]]; then + -n "$VALIDATE_TERRAFORM" || \ + -n "$VALIDATE_POWERSHELL" \ + ]]; then ANY_SET="true" fi @@ -993,6 +999,20 @@ GetValidationInfo() VALIDATE_TERRAFORM="true" fi + ######################################### + # Validate if we should check POWERSHELL # + ######################################### + if [[ "$ANY_SET" == "true" ]]; then + # Some linter flags were set - only run those set to true + if [[ -z "$VALIDATE_POWERSHELL" ]]; then + # POWERSHELL flag was not set - default to false + VALIDATE_POWERSHELL="false" + fi + else + # No linter flags were set - default all to true + VALIDATE_POWERSHELL="true" + fi + ####################################### # Print which linters we are enabling # ####################################### @@ -1081,6 +1101,11 @@ GetValidationInfo() else PRINT_ARRAY+=("- Excluding [TERRAFORM] files in code base...") fi + if [[ "$VALIDATE_POWERSHELL" == "true" ]]; then + PRINT_ARRAY+=("- Validating [POWERSHELL] files in code base...") + else + PRINT_ARRAY+=("- Excluding [POWERSHELL] files in code base...") + fi ############################## # Validate Ansible Directory # @@ -1388,6 +1413,18 @@ BuildFileList() # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## READ_ONLY_CHANGE_FLAG=1 + ########################### + # Get the Powershell files # + ########################### + elif [ "$FILE_TYPE" == "ps1" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_POWERSHELL+=("$FILE") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 elif [ "$FILE" == "Dockerfile" ]; then ################################ # Append the file to the array # @@ -1616,7 +1653,12 @@ LintCodebase() ################################ # Lint the file with the rules # ################################ - LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1) + #Special Handling for Powershell Required + if [ $FILE_TYPE -eq 'POWERSHELL' ];then + + else + LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1) + fi ####################### # Load the error code # @@ -1893,6 +1935,7 @@ Footer() [ "$ERRORS_FOUND_DOCKER" -ne 0 ] || \ [ "$ERRORS_FOUND_GO" -ne 0 ] || \ [ "$ERRORS_FOUND_TERRAFORM" -ne 0 ] || \ + [ "$ERRORS_FOUND_POWERSHELL" -ne 0 ] || \ [ "$ERRORS_FOUND_RUBY" -ne 0 ]; then # Failed exit echo "Exiting with errors found!" @@ -1950,6 +1993,7 @@ RunTestCases() TestCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint" ".*\(Dockerfile\)\$" TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c $ANSIBLE_LINTER_RULES" "ansible-lint" TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$" + TestCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -Settings $POWERSHELL_LINTER_RULES'" ".*\.\(ps\.\*\)\$" ################# # Footer prints # @@ -2004,6 +2048,9 @@ GetLinterRules "$GO_FILE_NAME" "$GO_LINTER_RULES" GetLinterRules "$DOCKER_FILE_NAME" "$DOCKER_LINTER_RULES" # Get Terraform rules GetLinterRules "$TERRAFORM_FILE_NAME" "$TERRAFORM_LINTER_RULES" +# Get Terraform rules +GetLinterRules "$POWERSHELL_FILE_NAME" "$POWERSHELL_LINTER_RULES" + ################################# # Check if were in verbose mode # @@ -2238,7 +2285,7 @@ if [ "$VALIDATE_POWERSHELL" == "true" ]; then # Lint the powershell files # ############################# # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -Settings $POWERSHELL_LINTER_RULES -Path' " 'ps[md]?1$' "${FILE_ARRAY_POWERSHELL[@]}" + LintCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -Settings $POWERSHELL_LINTER_RULES -Path '" ".*\.\(ps[md]\?1\)\$" "${FILE_ARRAY_POWERSHELL[@]}" fi ########## From 507afd74a788f0d289c08c5aa0729e08a49fb681 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Fri, 19 Jun 2020 20:51:12 +0000 Subject: [PATCH 05/25] Move to separate pwshlint script for better handling --- lib/linter.sh | 9 ++------- lib/pwshlint.ps1 | 6 ++++++ 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 lib/pwshlint.ps1 diff --git a/lib/linter.sh b/lib/linter.sh index 81e19a20..ca8c5837 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1653,12 +1653,7 @@ LintCodebase() ################################ # Lint the file with the rules # ################################ - #Special Handling for Powershell Required - if [ $FILE_TYPE -eq 'POWERSHELL' ];then - - else - LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1) - fi + LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1) ####################### # Load the error code # @@ -2285,7 +2280,7 @@ if [ "$VALIDATE_POWERSHELL" == "true" ]; then # Lint the powershell files # ############################# # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -Settings $POWERSHELL_LINTER_RULES -Path '" ".*\.\(ps[md]\?1\)\$" "${FILE_ARRAY_POWERSHELL[@]}" + LintCodebase "POWERSHELL" "/action/lib/pwshlint.ps1" "/action/lib/pwshlint.ps1 $POWERSHELL_LINTER_RULES " ".*\.\(ps[md]\?1\)\$" "${FILE_ARRAY_POWERSHELL[@]}" fi ########## diff --git a/lib/pwshlint.ps1 b/lib/pwshlint.ps1 new file mode 100644 index 00000000..8045282e --- /dev/null +++ b/lib/pwshlint.ps1 @@ -0,0 +1,6 @@ +#!/usr/bin/pwsh +param( + [String]$SettingsPath, + [String]$FileToAnalyze +) +Invoke-ScriptAnalyzer -Settings $SettingsPath -Path $FileToAnalyze \ No newline at end of file From 3e4ad2fcdbfd7be9f18cf7b9bd7d9127859bb9d7 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Fri, 19 Jun 2020 21:11:40 +0000 Subject: [PATCH 06/25] Enable Exit catch --- lib/pwshlint.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pwshlint.ps1 b/lib/pwshlint.ps1 index 8045282e..a3a7cfd7 100644 --- a/lib/pwshlint.ps1 +++ b/lib/pwshlint.ps1 @@ -3,4 +3,4 @@ param( [String]$SettingsPath, [String]$FileToAnalyze ) -Invoke-ScriptAnalyzer -Settings $SettingsPath -Path $FileToAnalyze \ No newline at end of file +$ScriptAnalyzerResults = Invoke-ScriptAnalyzer -EnableExit -Settings $SettingsPath -Path $FileToAnalyze \ No newline at end of file From 793ac9b8615387a24ef2c14a3ae8bf51808031e0 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Fri, 19 Jun 2020 14:26:06 -0700 Subject: [PATCH 07/25] DOCS: Add Powershell --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f1dfb044..e28f409a 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **TypeScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | | **XML** | [LibXML](http://xmlsoft.org/) | | **YAML** | [YamlLint](https://github.com/adrienverge/yamllint) | +| **Powershell** | [PSScriptAnalyzer](https://github.com/PowerShell/Psscriptanalyzer) | ## How to use To use this **GitHub** Action you will need to complete the following: @@ -129,6 +130,7 @@ and won't run anything unexpected. | **VALIDATE_TYPESCRIPT_STANDARD** | `true` | Flag to enable or disable the linting process of the language. (Utilizing: standard) | | **VALIDATE_DOCKER** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_GO** | `true` | Flag to enable or disable the linting process of the language. | +| **VALIDATE_POWERSHELL** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_TERRAFORM** | `true` | Flag to enable or disable the linting process of the language. | | **ANSIBLE_DIRECTORY** | `/ansible` | Flag to set the root directory for Ansible file location(s). | | **ACTIONS_RUNNER_DEBUG** | `false` | Flag to enable additional information about the linter, versions, and additional output. | From 96242befa3a96b5ab3c82fe0550a602dd2f25887 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 08:20:50 -0500 Subject: [PATCH 08/25] fixed or statement --- lib/linter.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index ba4a12be..6fabb8bc 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -770,7 +770,7 @@ GetValidationInfo() -n "$VALIDATE_DOCKER" || \ -n "$VALIDATE_GO" || \ -n "$VALIDATE_TERRAFORM" || \ - -n "$VALIDATE_POWERSHELL" \ + -n "$VALIDATE_POWERSHELL" || \ -n "$VALIDATE_CSS" || \ -n "$VALIDATE_ENV" ]]; then ANY_SET="true" @@ -2409,4 +2409,4 @@ fi ########## # Footer # ########## -Footer \ No newline at end of file +Footer From 2d7275249687d36cbc33f755f3678a8e3c9b603a Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 08:23:46 -0500 Subject: [PATCH 09/25] fix loops --- lib/linter.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/linter.sh b/lib/linter.sh index 6fabb8bc..70b99760 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1026,6 +1026,7 @@ GetValidationInfo() else # No linter flags were set - default all to true VALIDATE_POWERSHELL="true" + fi ################################### # Validate if we should check CSS # @@ -1147,6 +1148,7 @@ GetValidationInfo() PRINT_ARRAY+=("- Validating [POWERSHELL] files in code base...") else PRINT_ARRAY+=("- Excluding [POWERSHELL] files in code base...") + fi if [[ "$VALIDATE_CSS" == "true" ]]; then PRINT_ARRAY+=("- Validating [CSS] files in code base...") else From e1edf788e208ba146a16b92e3b90bf3d080ae0a7 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 08:26:38 -0500 Subject: [PATCH 10/25] fixed readme --- .automation/test/powershell/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .automation/test/powershell/README.md diff --git a/.automation/test/powershell/README.md b/.automation/test/powershell/README.md new file mode 100644 index 00000000..5a778c98 --- /dev/null +++ b/.automation/test/powershell/README.md @@ -0,0 +1,13 @@ +# PowerShell Test Cases +This folder holds the test cases for **PowerShell**. + +## Additional Docs +No Additional information is needed for this test case. + +## Good Test Cases +The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted. +- **Note:** They are linted utilizing the default linter rules. + +## Bad Test Cases +The test cases denoted: `LANGUAGE_bad_FILE.EXTENSION` are **NOT** valid, and should trigger errors when linted. +- **Note:** They are linted utilizing the default linter rules. From 85c273d94750113ef7c11174a98f861976f1b39a Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 08:40:09 -0500 Subject: [PATCH 11/25] adding more test cases --- .automation/test/powershell/powershell_bad_1.psd1 | 3 +++ .automation/test/powershell/powershell_bad_1.psm1 | 1 + .../powershell/{powershell.psd1 => powershell_good_1.psd1} | 0 .../powershell/{powershell.psm1 => powershell_good_1.psm1} | 0 4 files changed, 4 insertions(+) create mode 100644 .automation/test/powershell/powershell_bad_1.psd1 create mode 100644 .automation/test/powershell/powershell_bad_1.psm1 rename .automation/test/powershell/{powershell.psd1 => powershell_good_1.psd1} (100%) rename .automation/test/powershell/{powershell.psm1 => powershell_good_1.psm1} (100%) diff --git a/.automation/test/powershell/powershell_bad_1.psd1 b/.automation/test/powershell/powershell_bad_1.psd1 new file mode 100644 index 00000000..5940164c --- /dev/null +++ b/.automation/test/powershell/powershell_bad_1.psd1 @@ -0,0 +1,3 @@ +@{ + 'Hello'='World +} diff --git a/.automation/test/powershell/powershell_bad_1.psm1 b/.automation/test/powershell/powershell_bad_1.psm1 new file mode 100644 index 00000000..60d812b1 --- /dev/null +++ b/.automation/test/powershell/powershell_bad_1.psm1 @@ -0,0 +1 @@ +Write-Output "hello world! diff --git a/.automation/test/powershell/powershell.psd1 b/.automation/test/powershell/powershell_good_1.psd1 similarity index 100% rename from .automation/test/powershell/powershell.psd1 rename to .automation/test/powershell/powershell_good_1.psd1 diff --git a/.automation/test/powershell/powershell.psm1 b/.automation/test/powershell/powershell_good_1.psm1 similarity index 100% rename from .automation/test/powershell/powershell.psm1 rename to .automation/test/powershell/powershell_good_1.psm1 From b95544805ef2bb044784e5bf29e58990939bb154 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 09:40:19 -0500 Subject: [PATCH 12/25] fix version to variable --- Dockerfile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1f159db1..709a7d27 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ RUN apk add --no-cache \ ca-certificates less ncurses-terminfo-base \ krb5-libs libgcc libintl libssl1.1 libstdc++ \ tzdata userspace-rcu zlib icu-libs lttng-ust - + ######################################### # Install Powershell + PSScriptAnalyzer # ######################################### @@ -100,7 +100,9 @@ RUN gem install rubocop:0.74.0 rubocop-rails rubocop-github:0.13.0 # Need to fix the version as it installs 'rubocop:0.85.1' as a dep, and forces the default # We then need to promote the correct version, uninstall, and fix deps -RUN sh -c 'gem install --default rubocop:0.74.0; yes | gem uninstall rubocop:0.85.1 -a -x -I; gem install rubocop:0.74.0' +RUN sh -c 'INCORRECT_VERSION=$(gem list rhc -e rubocop |grep rubocop |awk "{print $2}" |cut -d"(" -f2|cut -d"," -f1); \ + gem install --default rubocop:0.74.0; \ + yes | gem uninstall rubocop:$INCORRECT_VERSION -a -x -I; gem install rubocop:0.74.0' ###################### # Install shellcheck # @@ -173,4 +175,4 @@ COPY TEMPLATES /action/lib/.automation ###################### # Set the entrypoint # ###################### -ENTRYPOINT ["/action/lib/linter.sh"] \ No newline at end of file +ENTRYPOINT ["/action/lib/linter.sh"] From 247f156c83a23cc955afeb59a900d8d1e686ce9d Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 09:41:04 -0500 Subject: [PATCH 13/25] fix format --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 709a7d27..068f5edb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -100,9 +100,10 @@ RUN gem install rubocop:0.74.0 rubocop-rails rubocop-github:0.13.0 # Need to fix the version as it installs 'rubocop:0.85.1' as a dep, and forces the default # We then need to promote the correct version, uninstall, and fix deps -RUN sh -c 'INCORRECT_VERSION=$(gem list rhc -e rubocop |grep rubocop |awk "{print $2}" |cut -d"(" -f2|cut -d"," -f1); \ +RUN sh -c 'INCORRECT_VERSION=$(gem list rhc -e rubocop | grep rubocop | awk "{print $2}" | cut -d"(" -f2| cut -d"," -f1); \ gem install --default rubocop:0.74.0; \ - yes | gem uninstall rubocop:$INCORRECT_VERSION -a -x -I; gem install rubocop:0.74.0' + yes | gem uninstall rubocop:$INCORRECT_VERSION -a -x -I; \ + gem install rubocop:0.74.0' ###################### # Install shellcheck # From f0e1f999abfa4787ce2835d6695bd9bd68410773 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 09:42:04 -0500 Subject: [PATCH 14/25] space --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 068f5edb..01f00e31 100644 --- a/Dockerfile +++ b/Dockerfile @@ -100,7 +100,7 @@ RUN gem install rubocop:0.74.0 rubocop-rails rubocop-github:0.13.0 # Need to fix the version as it installs 'rubocop:0.85.1' as a dep, and forces the default # We then need to promote the correct version, uninstall, and fix deps -RUN sh -c 'INCORRECT_VERSION=$(gem list rhc -e rubocop | grep rubocop | awk "{print $2}" | cut -d"(" -f2| cut -d"," -f1); \ +RUN sh -c 'INCORRECT_VERSION=$(gem list rhc -e rubocop | grep rubocop | awk "{print $2}" | cut -d"(" -f2 | cut -d"," -f1); \ gem install --default rubocop:0.74.0; \ yes | gem uninstall rubocop:$INCORRECT_VERSION -a -x -I; \ gem install rubocop:0.74.0' From 948c8c4f5da4ef77841bc02a25407233166cfbc4 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 09:54:09 -0500 Subject: [PATCH 15/25] make exec --- lib/pwshlint.ps1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 lib/pwshlint.ps1 diff --git a/lib/pwshlint.ps1 b/lib/pwshlint.ps1 old mode 100644 new mode 100755 From 25f89245892b4b7d1f8e60dd22f9ad905d5ad0f9 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 10:09:46 -0500 Subject: [PATCH 16/25] fix output --- lib/pwshlint.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pwshlint.ps1 b/lib/pwshlint.ps1 index a3a7cfd7..4131e8ba 100755 --- a/lib/pwshlint.ps1 +++ b/lib/pwshlint.ps1 @@ -3,4 +3,4 @@ param( [String]$SettingsPath, [String]$FileToAnalyze ) -$ScriptAnalyzerResults = Invoke-ScriptAnalyzer -EnableExit -Settings $SettingsPath -Path $FileToAnalyze \ No newline at end of file +Invoke-ScriptAnalyzer -EnableExit -Settings $SettingsPath -Path $FileToAnalyze From 5bbaf3f5a069970c7436f0601c651e686db2a6a0 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 10:29:34 -0500 Subject: [PATCH 17/25] convert to more command line style --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index 70b99760..fb3f0e0c 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -2405,7 +2405,7 @@ if [ "$VALIDATE_POWERSHELL" == "true" ]; then # Lint the powershell files # ############################# # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "POWERSHELL" "/action/lib/pwshlint.ps1" "/action/lib/pwshlint.ps1 $POWERSHELL_LINTER_RULES " ".*\.\(ps[md]\?1\)\$" "${FILE_ARRAY_POWERSHELL[@]}" + LintCodebase "POWERSHELL" "PowerShell" "pwsh -c 'Invoke-ScriptAnalyzer -Settings $POWERSHELL_LINTER_RULES $POWERSHELL_LINTER_RULES'" ".*\.\(ps[md]\?1\)\$" "${FILE_ARRAY_POWERSHELL[@]}" fi ########## From 1ecb355954e0052b3439ea3dc73864c80010d77b Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 10:36:06 -0500 Subject: [PATCH 18/25] fixed pathing --- lib/linter.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index fb3f0e0c..1dddd5d8 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -2085,7 +2085,7 @@ RunTestCases() TestCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint" ".*\(Dockerfile\)\$" TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c $ANSIBLE_LINTER_RULES" "ansible-lint" TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$" - TestCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -Settings $POWERSHELL_LINTER_RULES'" ".*\.\(ps\.\*\)\$" + TestCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path'" ".*\.\(ps\.\*\)\$" TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" @@ -2405,7 +2405,7 @@ if [ "$VALIDATE_POWERSHELL" == "true" ]; then # Lint the powershell files # ############################# # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "POWERSHELL" "PowerShell" "pwsh -c 'Invoke-ScriptAnalyzer -Settings $POWERSHELL_LINTER_RULES $POWERSHELL_LINTER_RULES'" ".*\.\(ps[md]\?1\)\$" "${FILE_ARRAY_POWERSHELL[@]}" + LintCodebase "POWERSHELL" "PowerShell" "pwsh -c 'Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path'" ".*\.\(ps[md]\?1\)\$" "${FILE_ARRAY_POWERSHELL[@]}" fi ########## From dc7137b504cbeb69c2420bcc38ec9072f98fcb92 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 10:58:52 -0500 Subject: [PATCH 19/25] add all file types --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index 1dddd5d8..82bf140c 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -2405,7 +2405,7 @@ if [ "$VALIDATE_POWERSHELL" == "true" ]; then # Lint the powershell files # ############################# # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "POWERSHELL" "PowerShell" "pwsh -c 'Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path'" ".*\.\(ps[md]\?1\)\$" "${FILE_ARRAY_POWERSHELL[@]}" + LintCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path'" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}" fi ########## From 209529d93b576c8bb52d4c0e96ac6e186154739c Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 11:16:45 -0500 Subject: [PATCH 20/25] cleanup --- lib/linter.sh | 2 +- lib/pwshlint.ps1 | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100755 lib/pwshlint.ps1 diff --git a/lib/linter.sh b/lib/linter.sh index 82bf140c..14e63131 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -2085,7 +2085,7 @@ RunTestCases() TestCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint" ".*\(Dockerfile\)\$" TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c $ANSIBLE_LINTER_RULES" "ansible-lint" TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$" - TestCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path'" ".*\.\(ps\.\*\)\$" + TestCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path'" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" diff --git a/lib/pwshlint.ps1 b/lib/pwshlint.ps1 deleted file mode 100755 index 4131e8ba..00000000 --- a/lib/pwshlint.ps1 +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/pwsh -param( - [String]$SettingsPath, - [String]$FileToAnalyze -) -Invoke-ScriptAnalyzer -EnableExit -Settings $SettingsPath -Path $FileToAnalyze From 32232a2442ac9c6dcbba5be6b6a4f3674e0a25e1 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 11:35:31 -0500 Subject: [PATCH 21/25] fixed quotes --- lib/linter.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 14e63131..810adef6 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1909,6 +1909,12 @@ TestCodebase() # Lint the file with the rules # ################################ LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER/ansible" || exit; $LINTER_COMMAND "$FILE" 2>&1) + elif [[ "$FILE_TYPE" == "POWERSHELL" ]]; then + ################################ + # Lint the file with the rules # + ################################ + # Need to append "'" to make the pwsh call syntax correct + LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE" \' 2>&1) else ################################ # Lint the file with the rules # @@ -2085,7 +2091,7 @@ RunTestCases() TestCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint" ".*\(Dockerfile\)\$" TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c $ANSIBLE_LINTER_RULES" "ansible-lint" TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$" - TestCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path'" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" + TestCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" @@ -2405,7 +2411,8 @@ if [ "$VALIDATE_POWERSHELL" == "true" ]; then # Lint the powershell files # ############################# # 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[@]}" + # NOTE: the offset of the missing "'" is taken care of in the loop logic + LintCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}" fi ########## From 64dba67f88e71e530494934ff341a202164c6da4 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 12:16:32 -0500 Subject: [PATCH 22/25] fixed error codes --- lib/linter.sh | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 810adef6..cfd6a5e9 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1739,10 +1739,26 @@ LintCodebase() echo "---------------------------" echo "File:[$FILE]" - ################################ - # Lint the file with the rules # - ################################ - LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1) + #################### + # Set the base Var # + #################### + LINT_CMD='' + + ####################################### + # Corner case for Powershell subshell # + ####################################### + if [[ "$FILE_TYPE" == "POWERSHELL" ]]; then + ################################ + # Lint the file with the rules # + ################################ + # Need to append "'" to make the pwsh call syntax correct, also exit with exit code from inner subshell + LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE" \' 2>&1 ; exit "$?") + else + ################################ + # Lint the file with the rules # + ################################ + LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1) + fi ####################### # Load the error code # @@ -1913,8 +1929,8 @@ TestCodebase() ################################ # Lint the file with the rules # ################################ - # Need to append "'" to make the pwsh call syntax correct - LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE" \' 2>&1) + # Need to append "'" to make the pwsh call syntax correct, also exit with exit code from inner subshell + LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE" \' 2>&1 ; exit "$?") else ################################ # Lint the file with the rules # From 107387d10aefe426ff8bce80de84d2c395b84604 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 12:27:54 -0500 Subject: [PATCH 23/25] fixing order --- lib/linter.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index cfd6a5e9..6f0d732c 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1752,7 +1752,7 @@ LintCodebase() # Lint the file with the rules # ################################ # Need to append "'" to make the pwsh call syntax correct, also exit with exit code from inner subshell - LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE" \' 2>&1 ; exit "$?") + LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE"; exit $?\' 2>&1) else ################################ # Lint the file with the rules # @@ -1930,7 +1930,7 @@ TestCodebase() # Lint the file with the rules # ################################ # Need to append "'" to make the pwsh call syntax correct, also exit with exit code from inner subshell - LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE" \' 2>&1 ; exit "$?") + LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE"; exit $?\' 2>&1) else ################################ # Lint the file with the rules # From d7d3e7273980bfa49795d113b39d5eb7ec5a1344 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 12:56:35 -0500 Subject: [PATCH 24/25] testing --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index 6f0d732c..fa7e41d0 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -x # shellcheck disable=SC1003,SC2016 ################################################################################ From 714855e739c06dca6a35b9191888712d3a30d322 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 13:12:26 -0500 Subject: [PATCH 25/25] fixing quotes --- lib/linter.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index fa7e41d0..4c1a5b08 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash # shellcheck disable=SC1003,SC2016 ################################################################################ @@ -1752,7 +1752,7 @@ LintCodebase() # Lint the file with the rules # ################################ # Need to append "'" to make the pwsh call syntax correct, 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; $LINTER_COMMAND "$FILE"; exit $? 2>&1) else ################################ # Lint the file with the rules # @@ -1930,7 +1930,7 @@ TestCodebase() # Lint the file with the rules # ################################ # Need to append "'" to make the pwsh call syntax correct, 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; $LINTER_COMMAND "$FILE"; exit $? 2>&1) else ################################ # Lint the file with the rules # @@ -2107,7 +2107,7 @@ RunTestCases() TestCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint" ".*\(Dockerfile\)\$" TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c $ANSIBLE_LINTER_RULES" "ansible-lint" TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$" - TestCodebase "POWERSHELL" "pwsh" "pwsh -c 'Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" + TestCodebase "POWERSHELL" "pwsh" "pwsh -c Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" @@ -2427,8 +2427,7 @@ if [ "$VALIDATE_POWERSHELL" == "true" ]; then # Lint the powershell files # ############################# # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - # NOTE: the offset of the missing "'" is taken care of in the loop logic - 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" "pwsh -c Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}" fi ##########