From 5212a5b016b32a96bef00c9e5d9a05effb339d17 Mon Sep 17 00:00:00 2001 From: Zack Koppert Date: Fri, 19 Jun 2020 11:53:22 -0700 Subject: [PATCH 01/53] More complete release instructions --- .github/CONTRIBUTING.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index f553dcfc..e2302dd8 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -31,9 +31,11 @@ Draft pull requests are also welcome to get feedback early on, or if there is so ## Releasing If you are the current maintainer of this action: -1. Update `README.md` to reflect new version number in the suggested workflow file section -2. Draft [Release](https://help.github.com/en/github/administering-a-repository/managing-releases-in-a-repository) document explaining details of Release -3. Look for approval from [CODEOWNERS](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners) +1. Update `README.md` and the wiki to reflect new version number in the example workflow file sections +2. Draft [Release](https://help.github.com/en/github/administering-a-repository/managing-releases-in-a-repository) with a summarized changelog +3. Publish the docker image to GitHub package registry +4. Publish the docker image to Docker Hub +5. Look for approval from [CODEOWNERS](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners) ## Resources - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) From 2e94f3c355d0b8b343387048ab63c4db77db7de0 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Fri, 19 Jun 2020 15:10:34 +0000 Subject: [PATCH 02/53] 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 03/53] 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 04/53] 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 05/53] 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 06/53] 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 07/53] 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 f13251355513f7dff2119bfdd5d730f21f591e3d Mon Sep 17 00:00:00 2001 From: Zack Koppert Date: Fri, 19 Jun 2020 14:21:23 -0700 Subject: [PATCH 08/53] Add link to wiki for new language support --- .github/ISSUE_TEMPLATE/feature_request.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 11fc491e..670c0420 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -18,3 +18,6 @@ A clear and concise description of any alternative solutions or features you've **Additional context** Add any other context or screenshots about the feature request here. + +**Note** +If this is a request to add a new language, after submitting this issue check out [the wiki](https://github.com/github/super-linter/wiki/Adding-new-language-support) for more info on how to accomplish that. From 79ebca41ac61010ed3ee89e0fbe1c4ea4a5023a2 Mon Sep 17 00:00:00 2001 From: Zack Koppert Date: Fri, 19 Jun 2020 14:23:15 -0700 Subject: [PATCH 09/53] Remove EOL space --- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 670c0420..caee45bc 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -20,4 +20,4 @@ A clear and concise description of any alternative solutions or features you've Add any other context or screenshots about the feature request here. **Note** -If this is a request to add a new language, after submitting this issue check out [the wiki](https://github.com/github/super-linter/wiki/Adding-new-language-support) for more info on how to accomplish that. +If this is a request to add a new language, after submitting this issue check out [the wiki](https://github.com/github/super-linter/wiki/Adding-new-language-support) for more info on how to accomplish that. From 793ac9b8615387a24ef2c14a3ae8bf51808031e0 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Fri, 19 Jun 2020 14:26:06 -0700 Subject: [PATCH 10/53] 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 46a1d1eb25a82872c9a41d9f58b9c7415a0d059e Mon Sep 17 00:00:00 2001 From: Antoine Leblanc Date: Sat, 20 Jun 2020 12:18:41 +0200 Subject: [PATCH 11/53] Update anchor for both CSS and Env linter in the table of content Signed-off-by: Antoine Leblanc --- docs/disabling-linters.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index 0a2af8b6..bb418456 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -20,8 +20,8 @@ Below is examples and documentation for each language and the various methods to - [Golang](#golang) - [Dockerfile](#dockerfile) - [Terraform](#terraform) -- [CSS](#stylelint) -- [ENV](#dotenv-linter) +- [CSS](#css) +- [ENV](#env) From 502883f2245651e783baa15423f06c161084d511 Mon Sep 17 00:00:00 2001 From: Nicholas Chambers Date: Sat, 20 Jun 2020 12:51:24 -0500 Subject: [PATCH 12/53] Turn the pipe operator into the proper or operator --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index ca88f558..d96c55c0 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -223,7 +223,7 @@ GetLinterVersions() ############################## # Check the shell for errors # ############################## - if [ $ERROR_CODE -ne 0 ] | [ -z "${GET_VERSION_CMD[*]}" ]; then + if [ $ERROR_CODE -ne 0 ] || [ -z "${GET_VERSION_CMD[*]}" ]; then echo "WARN! Failed to get version info for:[$LINTER]" echo "---------------------------------------------" else From e4fecc1c8d69da71ccdda926050cfdf8bd2fc559 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sat, 20 Jun 2020 23:49:32 -0400 Subject: [PATCH 13/53] spelling: against --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index ca88f558..4874df78 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -2018,7 +2018,7 @@ RunTestCases() # version of linter.sh, and a new container is built with the latest codebase # for testing. That container is spun up, and ran, # with the flag: TEST_CASE_RUN=true - # So that the new code can be validated againt the test cases + # So that the new code can be validated against the test cases ################# # Header prints # From 246396b570fe0f270a76d011f5f1de3030d061f4 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sat, 20 Jun 2020 23:50:18 -0400 Subject: [PATCH 14/53] spelling: changeset --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index 4874df78..86ce20a4 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1636,7 +1636,7 @@ LintCodebase() if [ ${#FILE_ARRAY[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then # No files found in commit and user has asked to not validate code base SKIP_FLAG=1 - # echo " - No files found in chageset to lint for language:[$FILE_TYPE]" + # echo " - No files found in changeset to lint for language:[$FILE_TYPE]" elif [ ${#FILE_ARRAY[@]} -ne 0 ]; then # We have files added to array of files to check LIST_FILES=("${FILE_ARRAY[@]}") # Copy the array into list From 44cade916171621afc84af741b3c339d126d3158 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sat, 20 Jun 2020 23:50:46 -0400 Subject: [PATCH 15/53] spelling: commits --- lib/linter.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 86ce20a4..f9b3fbfb 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1261,9 +1261,9 @@ BuildFileList() echo "Generating Diff with:[git diff --name-only '$DEFAULT_BRANCH..$GITHUB_SHA' --diff-filter=d]" fi - ################################################ - # Get the Array of files changed in the comits # - ################################################ + ################################################# + # Get the Array of files changed in the commits # + ################################################# # shellcheck disable=SC2207 RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only "$DEFAULT_BRANCH..$GITHUB_SHA" --diff-filter=d 2>&1)) From f5039368ca473977461511680de661b2a1e3c5a6 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sat, 20 Jun 2020 23:53:07 -0400 Subject: [PATCH 16/53] spelling: commencing --- .automation/test/coffeescript/coffeescript_bad_1.coffee | 2 +- .automation/test/coffeescript/coffeescript_good_1.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.automation/test/coffeescript/coffeescript_bad_1.coffee b/.automation/test/coffeescript/coffeescript_bad_1.coffee index 624cb3cd..5efeeacb 100644 --- a/.automation/test/coffeescript/coffeescript_bad_1.coffee +++ b/.automation/test/coffeescript/coffeescript_bad_1.coffee @@ -60,7 +60,7 @@ module.exports = (robot) -> ) # Drop the hammer # ################### robot.respond /drop the hammer/i, (msg) -> - msg.send "Commmencing the hammer dropping..." + msg.send "Commencing the hammer dropping..." msg.send msg.random dropHammer ############### diff --git a/.automation/test/coffeescript/coffeescript_good_1.coffee b/.automation/test/coffeescript/coffeescript_good_1.coffee index 40bc1264..62f2a4fe 100644 --- a/.automation/test/coffeescript/coffeescript_good_1.coffee +++ b/.automation/test/coffeescript/coffeescript_good_1.coffee @@ -62,7 +62,7 @@ module.exports = (robot) -> # Drop the hammer # ################### robot.respond /drop the hammer/i, (msg) -> - msg.send "Commmencing the hammer dropping..." + msg.send "Commencing the hammer dropping..." msg.send msg.random dropHammer ############### From 6e8aa549cb27e87febc9d5f920131bfbe61d6257 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sat, 20 Jun 2020 23:53:54 -0400 Subject: [PATCH 17/53] spelling: disable --- .github/linters/.yaml-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/linters/.yaml-lint.yml b/.github/linters/.yaml-lint.yml index faccea80..2aa49bd1 100644 --- a/.github/linters/.yaml-lint.yml +++ b/.github/linters/.yaml-lint.yml @@ -3,7 +3,7 @@ # These are the rules used for # # linting all the yaml files in the stack # # NOTE: # -# You can disble line with: # +# You can disable line with: # # # yamllint disable-line # ########################################### rules: From 8ec0bd8f61576c876b5eeddf466f7176b418004d Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sat, 20 Jun 2020 23:54:43 -0400 Subject: [PATCH 18/53] spelling: iterate --- lib/linter.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index f9b3fbfb..9fd5af02 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1282,9 +1282,9 @@ BuildFileList() exit 1 fi - ################################################# - # Itterate through the array of all files found # - ################################################# + ################################################ + # Iterate through the array of all files found # + ################################################ echo "" echo "----------------------------------------------" echo "Files that have been modified in the commit(s):" From 566cd3d5574d553e598a1bd62522d146a1f8a464 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sat, 20 Jun 2020 23:55:10 -0400 Subject: [PATCH 19/53] spelling: languages --- lib/linter.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 9fd5af02..4ca5911f 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -2075,9 +2075,9 @@ Header # needed to connect back and update checks GetGitHubVars -########################################## -# Get the langugages we need to validate # -########################################## +######################################### +# Get the languages we need to validate # +######################################### GetValidationInfo ######################## From d542dc4d76efa259a95840b3938cf2111652136f Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sat, 20 Jun 2020 23:56:56 -0400 Subject: [PATCH 20/53] spelling: numeric --- .automation/cleanup-docker.sh | 6 +++--- .automation/upload-docker.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.automation/cleanup-docker.sh b/.automation/cleanup-docker.sh index ba2cb758..131daf6a 100755 --- a/.automation/cleanup-docker.sh +++ b/.automation/cleanup-docker.sh @@ -115,9 +115,9 @@ ValidateInput() # Check if we need to get the name of the branch # ################################################## if [[ "$IMAGE_VERSION" != "latest" ]]; then - ################################### - # Remove non alpha-numberic chars # - ################################### + ################################## + # Remove non alpha-numeric chars # + ################################## IMAGE_VERSION=$(echo "$IMAGE_VERSION" | tr -cd '[:alnum:]') else ############################################# diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index 644bee8d..c41adb33 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -120,9 +120,9 @@ ValidateInput() exit 1 fi - ################################### - # Remove non alpha-numberic chars # - ################################### + ################################## + # Remove non alpha-numeric chars # + ################################## BRANCH_NAME=$(echo "$BRANCH_NAME" | tr -cd '[:alnum:]') ############################################ From 64c1dfe67b5304569b5edad72b89a978f0467d56 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sat, 20 Jun 2020 23:57:39 -0400 Subject: [PATCH 21/53] spelling: promote --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a93c72bc..de08dd4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -81,7 +81,7 @@ RUN git clone https://github.com/replicatedhq/dockerfilelint.git && cd /dockerfi 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 +# We then need to promote 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' ###################### From f3b12894a2996f8829c42522ce4065bb055d5501 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 21 Jun 2020 00:00:08 -0400 Subject: [PATCH 22/53] spelling: settings --- .../ansible/ghe-initialize/tasks/collectd-settings.yml | 6 +++--- .../ghe-initialize/tasks/ghe-initial-configuration.yml | 8 ++++---- .../test/ansible/ghe-initialize/tasks/splunk-settings.yml | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.automation/test/ansible/ghe-initialize/tasks/collectd-settings.yml b/.automation/test/ansible/ghe-initialize/tasks/collectd-settings.yml index f6f08485..0c73fc94 100644 --- a/.automation/test/ansible/ghe-initialize/tasks/collectd-settings.yml +++ b/.automation/test/ansible/ghe-initialize/tasks/collectd-settings.yml @@ -42,9 +42,9 @@ group: admin mode: 0644 - ######################################################### - # Set up Admin password, License, and Initial Setttings # - ######################################################### + ######################################################## + # Set up Admin password, License, and Initial Settings # + ######################################################## - name: Setup Grafana # yamllint disable shell: curl --fail -Lk \ diff --git a/.automation/test/ansible/ghe-initialize/tasks/ghe-initial-configuration.yml b/.automation/test/ansible/ghe-initialize/tasks/ghe-initial-configuration.yml index 91865d3c..d44e2101 100644 --- a/.automation/test/ansible/ghe-initialize/tasks/ghe-initial-configuration.yml +++ b/.automation/test/ansible/ghe-initialize/tasks/ghe-initial-configuration.yml @@ -57,10 +57,10 @@ group: admin mode: 0644 - ######################################################### - # Set up Admin password, License, and Initial Setttings # - ######################################################### - - name: Setup License, Admin Password, and Initial Setttings + ######################################################## + # Set up Admin password, License, and Initial Settings # + ######################################################## + - name: Setup License, Admin Password, and Initial Settings command: curl --fail -Lk \ -X POST "https://{{ ansible_host }}:8443/setup/api/start" \ -F license=@/tmp/ghe-license.ghl \ diff --git a/.automation/test/ansible/ghe-initialize/tasks/splunk-settings.yml b/.automation/test/ansible/ghe-initialize/tasks/splunk-settings.yml index 33919111..aaaa0780 100644 --- a/.automation/test/ansible/ghe-initialize/tasks/splunk-settings.yml +++ b/.automation/test/ansible/ghe-initialize/tasks/splunk-settings.yml @@ -42,9 +42,9 @@ group: admin mode: 0644 - ######################################################### - # Set up Admin password, License, and Initial Setttings # - ######################################################### + ######################################################## + # Set up Admin password, License, and Initial Settings # + ######################################################## - name: Setup Splunk # yamllint disable shell: curl --fail -Lk \ From 0408343139e86064e48d8aeb888cd83ba9ae83f1 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 21 Jun 2020 00:00:46 -0400 Subject: [PATCH 23/53] spelling: typescript --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index 4ca5911f..2a925646 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -32,7 +32,7 @@ COFFEESCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$COFFEE_FILE_NAME" # Path to JAVASCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file JAVASCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$JAVASCRIPT_FILE_NAME" # Path to the Javascript lint rules JAVASCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard -# Typecript Vars +# Typescript Vars TYPESCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file TYPESCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$TYPESCRIPT_FILE_NAME" # Path to the Typescript lint rules TYPESCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard From 3bf84dbb9ca86f601618b9b318b5cfd9200a2d0c Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 21 Jun 2020 00:01:16 -0400 Subject: [PATCH 24/53] spelling: version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index de08dd4d..fc6a0212 100644 --- a/Dockerfile +++ b/Dockerfile @@ -81,7 +81,7 @@ RUN git clone https://github.com/replicatedhq/dockerfilelint.git && cd /dockerfi 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 verion, uninstall, and fix deps +# 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' ###################### From aed53d0ee5aca96103393f41d0a916ef8f9922db Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 21 Jun 2020 00:02:45 -0400 Subject: [PATCH 25/53] spelling: visible --- .automation/test/javascript/javascript_bad_1.js | 2 +- .automation/test/javascript/javascript_good_1.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.automation/test/javascript/javascript_bad_1.js b/.automation/test/javascript/javascript_bad_1.js index 0ed075fc..98e5ee29 100644 --- a/.automation/test/javascript/javascript_bad_1.js +++ b/.automation/test/javascript/javascript_bad_1.js @@ -7,7 +7,7 @@ var userArray = [ 'user1' ] here is some garbage = that var teamDescription = Team of Robots -var teamPrivacy = 'closed' // closed (visibile) / secret (hidden) are options here +var teamPrivacy = 'closed' // closed (visible) / secret (hidden) are options here var teamName = process.env.GHES_TEAM_NAME var teamAccess = 'pull' // pull,push,admin options here diff --git a/.automation/test/javascript/javascript_good_1.js b/.automation/test/javascript/javascript_good_1.js index 09417a6b..ad32089f 100644 --- a/.automation/test/javascript/javascript_good_1.js +++ b/.automation/test/javascript/javascript_good_1.js @@ -5,7 +5,7 @@ var handler = createHandler({ path: '/webhook', secret: (process.env.SECRET) }) var userArray = ['user1'] var teamDescription = 'Team of Robots' -var teamPrivacy = 'closed' // closed (visibile) / secret (hidden) are options here +var teamPrivacy = 'closed' // closed (visible) / secret (hidden) are options here var teamName = process.env.GHES_TEAM_NAME var teamAccess = 'pull' // pull,push,admin options here From b2836561770b0afa46793b640e0011672576dfb4 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 21 Jun 2020 00:03:30 -0400 Subject: [PATCH 26/53] spelling: whitespace --- lib/linter.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index 2a925646..d88d0a6d 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -354,9 +354,9 @@ GetStandardRules() ENV_STRING+="--env ${ENV} " done - ######################################## - # Remove trailing and ending witespace # - ######################################## + ######################################### + # Remove trailing and ending whitespace # + ######################################### if [[ "$LINTER" == "javascript" ]]; then JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" elif [[ "$LINTER" == "typescript" ]]; then From 037865ec11141b80b0da29a28e25cd7b8ff1e295 Mon Sep 17 00:00:00 2001 From: Wonjun Kim Date: Sun, 21 Jun 2020 16:59:18 +0900 Subject: [PATCH 27/53] Add kotlin support to super-linter --- .automation/test/kotlin/README.md | 13 ++++++ .automation/test/kotlin/kotlin_bad_1.kt | 6 +++ .automation/test/kotlin/kotlint_good_1.kt | 6 +++ Dockerfile | 9 +++- README.md | 2 + docs/disabling-linters.md | 25 +++++++++++ lib/linter.sh | 55 +++++++++++++++++++++-- 7 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 .automation/test/kotlin/README.md create mode 100644 .automation/test/kotlin/kotlin_bad_1.kt create mode 100644 .automation/test/kotlin/kotlint_good_1.kt diff --git a/.automation/test/kotlin/README.md b/.automation/test/kotlin/README.md new file mode 100644 index 00000000..f1fd9cfe --- /dev/null +++ b/.automation/test/kotlin/README.md @@ -0,0 +1,13 @@ +# Kotlin Test Cases +This folder holds the test cases for **Kotlin**. + +## 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. diff --git a/.automation/test/kotlin/kotlin_bad_1.kt b/.automation/test/kotlin/kotlin_bad_1.kt new file mode 100644 index 00000000..ad02ddc8 --- /dev/null +++ b/.automation/test/kotlin/kotlin_bad_1.kt @@ -0,0 +1,6 @@ +fun main() { + val n = "World"; + val v = "Hello, ${n}!"; + + println(v); +} \ No newline at end of file diff --git a/.automation/test/kotlin/kotlint_good_1.kt b/.automation/test/kotlin/kotlint_good_1.kt new file mode 100644 index 00000000..6e1f1a51 --- /dev/null +++ b/.automation/test/kotlin/kotlint_good_1.kt @@ -0,0 +1,6 @@ +fun main() { + val n = "World" + val v = "Hello, $n!" + + println(v) +} diff --git a/Dockerfile b/Dockerfile index a93c72bc..1021e0bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,7 @@ RUN apk add --no-cache \ libxml2-utils perl \ ruby ruby-dev ruby-bundler ruby-rdoc make \ py3-setuptools ansible-lint \ - go + go openjdk8-jre ##################### # Run Pip3 Installs # @@ -108,6 +108,12 @@ RUN curl -Ls "$(curl -Ls https://api.github.com/repos/terraform-linters/tflint/r RUN wget "https://github.com/dotenv-linter/dotenv-linter/releases/latest/download/dotenv-linter-alpine-x86_64.tar.gz" -O - -q | tar -xzf - \ && mv "dotenv-linter" /usr/bin +################## +# Install ktlint # +################## +RUN curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.37.2/ktlint && chmod a+x ktlint \ + && mv "ktlint" /usr/bin/ + ########################################### # Load GitHub Env Vars for GitHub Actions # ########################################### @@ -135,6 +141,7 @@ ENV GITHUB_SHA=${GITHUB_SHA} \ VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \ VALIDATE_CSS=${VALIDATE_CSS} \ VALIDATE_ENV=${VALIDATE_ENV} \ + VALIDATE_KOTLIN=${VALIDATE_KOTLIN} \ ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \ RUN_LOCAL=${RUN_LOCAL} \ TEST_CASE_RUN=${TEST_CASE_RUN} \ diff --git a/README.md b/README.md index 8e6d6f39..0c3328f0 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **XML** | [LibXML](http://xmlsoft.org/) | | **YAML** | [YamlLint](https://github.com/adrienverge/yamllint) | | **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) | +| **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) | ## How to use To use this **GitHub** Action you will need to complete the following: @@ -137,6 +138,7 @@ and won't run anything unexpected. | **VALIDATE_TERRAFORM** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_CSS** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_ENV** | `true` | Flag to enable or disable the linting process of the language. | +| **VALIDATE_KOTLIN** | `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. | | **DISABLE_ERRORS** | `false` | Flag to have the linter complete with exit code 0 even if errors were detected. | diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index b972d31c..0972bfda 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -22,6 +22,7 @@ Below is examples and documentation for each language and the various methods to - [Terraform](#terraform) - [CSS](#stylelint) - [ENV](#dotenv-linter) +- [Kotlin](#kotlin) @@ -564,3 +565,27 @@ a {} ### dotenv-linter disable entire file - There is currently **No** way to disable rules inline of the file(s) + +-------------------------------------------------------------------------------- + +## Kotlin +- [ktlint](https://github.com/pinterest/ktlint) + +### ktlint Config file +- There is no top level *configuration file* available at this time + +### ktlint disable single line +```kotlin +import package.* // ktlint-disable no-wildcard-imports +``` + +### ktlint disable code block +```kotlin +/* ktlint-disable no-wildcard-imports */ +import package.a.* +import package.b.* +/* ktlint-enable no-wildcard-imports */ +``` + +### ktlint disable entire file +- There is currently **No** way to disable rules inline of the file(s) diff --git a/lib/linter.sh b/lib/linter.sh index ca88f558..5d468ab0 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -59,14 +59,14 @@ CSS_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CSS_FILE_NAME" # Path to th LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck" "pylint" "perl" "rubocop" "coffeelint" "eslint" "standard" "ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint" - "stylelint" "dotenv-linter") + "stylelint" "dotenv-linter" "ktlint") ############################# # 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' 'CSS' "ENV") + 'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' 'CSS' 'ENV' 'KOTLIN') ################### # GitHub ENV Vars # @@ -96,6 +96,7 @@ VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate lang VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language VALIDATE_CSS="${VALIDATE_CSS}" # Boolean to validate language VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate language +VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases DISABLE_ERRORS="${DISABLE_ERRORS}" # Boolean to enable warning-only output without throwing errors @@ -140,6 +141,7 @@ FILE_ARRAY_GO=() # Array of files to check FILE_ARRAY_TERRAFORM=() # Array of files to check FILE_ARRAY_CSS=() # Array of files to check FILE_ARRAY_ENV=() # Array of files to check +FILE_ARRAY_KOTLIN=() # Array of files to check ############ # Counters # @@ -163,6 +165,7 @@ ERRORS_FOUND_GO=0 # Count of errors found ERRORS_FOUND_TERRAFORM=0 # Count of errors found ERRORS_FOUND_CSS=0 # Count of errors found ERRORS_FOUND_ENV=0 # Count of errors found +ERRORS_FOUND_KOTLIN=0 # Count of errors found ################################################################################ ########################## FUNCTIONS BELOW ##################################### @@ -741,6 +744,7 @@ GetValidationInfo() VALIDATE_TERRAFORM=$(echo "$VALIDATE_TERRAFORM" | awk '{print tolower($0)}') VALIDATE_CSS=$(echo "$VALIDATE_CSS" | awk '{print tolower($0)}') VALIDATE_ENV=$(echo "$VALIDATE_ENV" | awk '{print tolower($0)}') + VALIDATE_KOTLIN=$(echo "$VALIDATE_KOTLIN" | awk '{print tolower($0)}') ################################################ # Determine if any linters were explicitly set # @@ -764,7 +768,8 @@ GetValidationInfo() -n "$VALIDATE_GO" || \ -n "$VALIDATE_TERRAFORM" || \ -n "$VALIDATE_CSS" || \ - -n "$VALIDATE_ENV" ]]; then + -n "$VALIDATE_ENV" || \ + -n "$VALIDATE_KOTLIN" ]]; then ANY_SET="true" fi @@ -1034,6 +1039,21 @@ GetValidationInfo() VALIDATE_ENV="true" fi + ###################################### + # Validate if we should check KOTLIN # + ###################################### + if [[ "$ANY_SET" == "true" ]]; then + # Some linter flags were set - only run those set to true + if [[ -z "$VALIDATE_KOTLIN" ]]; then + # ENV flag was not set - default to false + VALIDATE_KOTLIN="false" + fi + else + # No linter flags were set - default all to true + VALIDATE_KOTLIN="true" + fi + + ####################################### # Print which linters we are enabling # ####################################### @@ -1132,6 +1152,11 @@ GetValidationInfo() else PRINT_ARRAY+=("- Excluding [ENV] files in code base...") fi + if [[ "$VALIDATE_KOTLIN" == "true" ]]; then + PRINT_ARRAY+=("- Validating [KOTLIN] files in code base...") + else + PRINT_ARRAY+=("- Excluding [KOTLIN] files in code base...") + fi ############################## # Validate Ansible Directory # @@ -1479,6 +1504,15 @@ BuildFileList() # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## READ_ONLY_CHANGE_FLAG=1 + elif [ "$FILE_TYPE" == "kt" ] || [ "$FILE_TYPE" == "kts" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_KOTLIN+=("$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 # @@ -1992,7 +2026,8 @@ Footer() [ "$ERRORS_FOUND_TERRAFORM" -ne 0 ] || \ [ "$ERRORS_FOUND_RUBY" -ne 0 ] || \ [ "$ERRORS_FOUND_CSS" -ne 0 ] || \ - [ "$ERRORS_FOUND_ENV" -ne 0 ]; then + [ "$ERRORS_FOUND_ENV" -ne 0 ] || \ + [ "$ERRORS_FOUND_KOTLIN" -ne 0 ]; then # Failed exit echo "Exiting with errors found!" exit 1 @@ -2051,6 +2086,7 @@ RunTestCases() TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$" TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" + TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" ################# # Footer prints # @@ -2347,6 +2383,17 @@ if [ "$VALIDATE_ENV" == "true" ]; then LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" "${FILE_ARRAY_ENV[@]}" fi +################## +# KOTLIN LINTING # +################## +if [ "$VALIDATE_KOTLIN" == "true" ]; then + ####################### + # Lint the Kotlin files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "${FILE_ARRAY_ENV[@]}" +fi + ################## # DOCKER LINTING # ################## From 865f6005fdda6c1cfe88238f0c68a728bd5a0001 Mon Sep 17 00:00:00 2001 From: Zack Koppert Date: Sun, 21 Jun 2020 11:02:36 -0700 Subject: [PATCH 28/53] spelling fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e6d6f39..1cf0539b 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ The **Super-Linter** has *CI/CT/CD* configured utilizing **GitHub** Actions. - `.automation/test` contains all test cases for each language that should be validated - These **GitHub** Actions utilize the Checks API and Protected Branches to help follow the SDLC - When the Pull Request is merged to master, the **Super-Linter** **Docker** container is then updated and deployed with the new codebase - - **Note:** The branches **Docker** container is also removed from **DockerHub** to cleanup after itself + - **Note:** The branch's **Docker** container is also removed from **DockerHub** to cleanup after itself ## Limitations Below are a list of the known limitations for the **GitHub Super-Linter**: From 95e8a759580681054b22547bd6b90b7e13ff1b6b Mon Sep 17 00:00:00 2001 From: Wonjun Kim Date: Mon, 22 Jun 2020 11:07:39 +0900 Subject: [PATCH 29/53] Update ktlint to latest version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1021e0bd..13aacf77 100644 --- a/Dockerfile +++ b/Dockerfile @@ -111,7 +111,7 @@ RUN wget "https://github.com/dotenv-linter/dotenv-linter/releases/latest/downloa ################## # Install ktlint # ################## -RUN curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.37.2/ktlint && chmod a+x ktlint \ +RUN curl -sSLO https://github.com/pinterest/ktlint/releases/latest/download/ktlint && chmod a+x ktlint \ && mv "ktlint" /usr/bin/ ########################################### From 081e267c15a77104434f980190c57491a1f16b70 Mon Sep 17 00:00:00 2001 From: Grachev Mikhail Date: Sat, 20 Jun 2020 13:02:14 +0300 Subject: [PATCH 30/53] Add support more variants names of env files Update linter.sh Update Dockerfile Update linter.sh --- Dockerfile | 4 ++-- lib/linter.sh | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index a93c72bc..4d2c7908 100644 --- a/Dockerfile +++ b/Dockerfile @@ -102,9 +102,9 @@ RUN wget -O- -nvq https://raw.githubusercontent.com/golangci/golangci-lint/maste 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 dotenv-linter # -################## +######################### RUN wget "https://github.com/dotenv-linter/dotenv-linter/releases/latest/download/dotenv-linter-alpine-x86_64.tar.gz" -O - -q | tar -xzf - \ && mv "dotenv-linter" /usr/bin diff --git a/lib/linter.sh b/lib/linter.sh index ca88f558..4b174c18 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1020,9 +1020,9 @@ GetValidationInfo() VALIDATE_CSS="true" fi - #################################### + ################################### # Validate if we should check ENV # - #################################### + ################################### if [[ "$ANY_SET" == "true" ]]; then # Some linter flags were set - only run those set to true if [[ -z "$VALIDATE_ENV" ]]; then @@ -2050,7 +2050,7 @@ RunTestCases() TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c $ANSIBLE_LINTER_RULES" "ansible-lint" TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$" TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" - TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" + TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\).*\$" ################# # Footer prints # @@ -2336,15 +2336,15 @@ if [ "$VALIDATE_CSS" == "true" ]; then LintCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" "${FILE_ARRAY_CSS[@]}" fi -################ +############### # ENV LINTING # -################ +############### if [ "$VALIDATE_ENV" == "true" ]; then ####################### # Lint the env files # ####################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" "${FILE_ARRAY_ENV[@]}" + LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\).*\$" "${FILE_ARRAY_ENV[@]}" fi ################## 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 31/53] 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 32/53] 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 33/53] 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 34/53] 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 35/53] 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 36/53] 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 37/53] 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 38/53] 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 e01b7fc4e472957e386f8c6cae6f42f3f0bf2be3 Mon Sep 17 00:00:00 2001 From: Thomas Hughes Date: Mon, 22 Jun 2020 09:58:04 -0500 Subject: [PATCH 39/53] Add IAmHughes as CODEOWNER --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c70dda77..c9921dce 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,4 +1,4 @@ ###################################################################### # These owners will be the default owners for everything in the repo # ###################################################################### -* @admiralawkbar @jwiebalk @zkoppert \ No newline at end of file +* @admiralawkbar @jwiebalk @zkoppert @IAmHughes 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 40/53] 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 41/53] 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 42/53] 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 d709a18a6ce5fe3f3141cebaeabaf9b4c56dcef3 Mon Sep 17 00:00:00 2001 From: Broder Peters Date: Mon, 22 Jun 2020 17:39:05 +0200 Subject: [PATCH 43/53] Point linter.yml example to existing version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1cf0539b..43f040a1 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ jobs: # Run Linter against code base # ################################ - name: Lint Code Base - uses: docker://github/super-linter:v2.1.1 + uses: docker://github/super-linter:v2.1.0 env: VALIDATE_ALL_CODEBASE: false VALIDATE_ANSIBLE: false 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 44/53] 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 45/53] 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 46/53] 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 47/53] 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 48/53] 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 49/53] 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 50/53] 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 ########## From f7ca82806feb8cfbca00de8466537cb36d5c8de4 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Thu, 18 Jun 2020 19:53:24 +0200 Subject: [PATCH 51/53] Add PHP linting foundation --- .automation/test/php/README.md | 13 ++++++++ .automation/test/php/php_bad_1.php | 5 +++ .automation/test/php/php_good_1.php | 5 +++ Dockerfile | 4 ++- README.md | 2 ++ docs/disabling-linters.md | 18 ++++++++++ lib/linter.sh | 51 ++++++++++++++++++++++++++++- 7 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 .automation/test/php/README.md create mode 100644 .automation/test/php/php_bad_1.php create mode 100644 .automation/test/php/php_good_1.php diff --git a/.automation/test/php/README.md b/.automation/test/php/README.md new file mode 100644 index 00000000..7ab89f43 --- /dev/null +++ b/.automation/test/php/README.md @@ -0,0 +1,13 @@ +# PHP Test Cases +This folder holds the test cases for **PHP**. + +## 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. diff --git a/.automation/test/php/php_bad_1.php b/.automation/test/php/php_bad_1.php new file mode 100644 index 00000000..9c2999f6 --- /dev/null +++ b/.automation/test/php/php_bad_1.php @@ -0,0 +1,5 @@ + Date: Mon, 22 Jun 2020 13:55:41 -0500 Subject: [PATCH 52/53] fix rubocop logic --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4d2c7908..58e6444b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -82,7 +82,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 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' +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 # From c82c02cf55cc4c5601d86e5f21aefceca4f1163d Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Mon, 22 Jun 2020 14:42:49 -0500 Subject: [PATCH 53/53] removing hard coded errors --- .automation/test/php/php_bad_1.php | 2 -- .automation/test/php/php_good_1.php | 2 -- 2 files changed, 4 deletions(-) diff --git a/.automation/test/php/php_bad_1.php b/.automation/test/php/php_bad_1.php index 9c2999f6..e564fc66 100644 --- a/.automation/test/php/php_bad_1.php +++ b/.automation/test/php/php_bad_1.php @@ -1,5 +1,3 @@