diff --git a/.automation/README.md b/.automation/README.md index 812c2aae..485e97ec 100644 --- a/.automation/README.md +++ b/.automation/README.md @@ -19,4 +19,5 @@ When the script is triggered in a branch, it will push with the tag:**NameOfBran - **Note:** The branch name will be reduced to alphanumeric for consistency and uploading ## test + This folder holds all **Test Cases** to help run the *CI/CT/CD* process for the **Super-Linter**. diff --git a/.automation/cleanup-docker.sh b/.automation/cleanup-docker.sh index b2c96257..838119c4 100755 --- a/.automation/cleanup-docker.sh +++ b/.automation/cleanup-docker.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ################################################################################ ############# Cleanup Image on DockerHub @admiralawkbar ######################## diff --git a/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh b/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh index 7978c630..5a0f32dd 100644 --- a/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh +++ b/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ################################################################################ # Script to run ghe-config-apply on the primary GHES instance 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/.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..e564fc66 --- /dev/null +++ b/.automation/test/php/php_bad_1.php @@ -0,0 +1,3 @@ +&1)) diff --git a/.automation/test/shell/shell_good_1.sh b/.automation/test/shell/shell_good_1.sh index 66430423..9a1f5bc5 100644 --- a/.automation/test/shell/shell_good_1.sh +++ b/.automation/test/shell/shell_good_1.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # CMD HELLO_WORLD=$(echo "Hello World" | cut -f1 -d' ' 2>&1) diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index 6cddd9de..12c15635 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ################################################################################ ############# Deploy Container to DockerHub @admiralawkbar ##################### @@ -20,6 +20,9 @@ GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace DOCKER_USERNAME="${DOCKER_USERNAME}" # Username to login to DockerHub DOCKER_PASSWORD="${DOCKER_PASSWORD}" # Password to login to DockerHub +GPR_USERNAME="${GPR_USERNAME}" # Username to login to GitHub package registry +GPR_TOKEN="${GPR_TOKEN}" # Password to login to GitHub package registry +REGISTRY="${REGISTRY}" # What registry to upload | or IMAGE_REPO="${IMAGE_REPO}" # Image repo to upload the image IMAGE_VERSION="${IMAGE_VERSION}" # Version to tag the image DOCKERFILE_PATH="${DOCKERFILE_PATH}" # Path to the Dockerfile to be uploaded @@ -33,7 +36,7 @@ Header() { echo "" echo "-------------------------------------------------------" - echo "------ GitHub Actions Upload image to DockerHub -------" + echo "---- GitHub Actions Upload image to [$REGISTRY] ----" echo "-------------------------------------------------------" echo "" } @@ -51,9 +54,9 @@ ValidateInput() echo "----------------------------------------------" echo "" - ############################ + ############################# # Validate GITHUB_WORKSPACE # - ############################ + ############################# if [ -z "$GITHUB_WORKSPACE" ]; then echo "ERROR! Failed to get [GITHUB_WORKSPACE]!" echo "ERROR:[$GITHUB_WORKSPACE]" @@ -62,28 +65,77 @@ ValidateInput() echo "Successfully found:[GITHUB_WORKSPACE], value:[$GITHUB_WORKSPACE]" fi - ############################ - # Validate DOCKER_USERNAME # - ############################ - if [ -z "$DOCKER_USERNAME" ]; then - echo "ERROR! Failed to get [DOCKER_USERNAME]!" - echo "ERROR:[$DOCKER_USERNAME]" + ##################### + # Validate REGISTRY # + ##################### + if [ -z "$REGISTRY" ]; then + echo "ERROR! Failed to get [REGISTRY]!" + echo "ERROR:[$REGISTRY]" exit 1 else - echo "Successfully found:[DOCKER_USERNAME], value:[$DOCKER_USERNAME]" + echo "Successfully found:[REGISTRY], value:[$REGISTRY]" fi - ############################ - # Validate DOCKER_PASSWORD # - ############################ - if [ -z "$DOCKER_PASSWORD" ]; then - echo "ERROR! Failed to get [DOCKER_PASSWORD]!" - echo "ERROR:[$DOCKER_PASSWORD]" - exit 1 + ##################################################### + # See if we need values for GitHub package Registry # + ##################################################### + if [[ "$REGISTRY" == "GPR" ]]; then + ######################### + # Validate GPR_USERNAME # + ######################### + if [ -z "$GPR_USERNAME" ]; then + echo "ERROR! Failed to get [GPR_USERNAME]!" + echo "ERROR:[$GPR_USERNAME]" + exit 1 + else + echo "Successfully found:[GPR_USERNAME], value:[$GPR_USERNAME]" + fi + + ###################### + # Validate GPR_TOKEN # + ###################### + if [ -z "$GPR_TOKEN" ]; then + echo "ERROR! Failed to get [GPR_TOKEN]!" + echo "ERROR:[$GPR_TOKEN]" + exit 1 + else + echo "Successfully found:[GPR_TOKEN], value:[********]" + fi + ######################################## + # See if we need values for Ducker hub # + ######################################## + elif [[ "$REGISTRY" == "Docker" ]]; then + ############################ + # Validate DOCKER_USERNAME # + ############################ + if [ -z "$DOCKER_USERNAME" ]; then + echo "ERROR! Failed to get [DOCKER_USERNAME]!" + echo "ERROR:[$DOCKER_USERNAME]" + exit 1 + else + echo "Successfully found:[DOCKER_USERNAME], value:[$DOCKER_USERNAME]" + fi + + ############################ + # Validate DOCKER_PASSWORD # + ############################ + if [ -z "$DOCKER_PASSWORD" ]; then + echo "ERROR! Failed to get [DOCKER_PASSWORD]!" + echo "ERROR:[$DOCKER_PASSWORD]" + exit 1 + else + echo "Successfully found:[DOCKER_PASSWORD], value:[********]" + fi + ########################################### + # We were not passed a registry to update # + ########################################### else - echo "Successfully found:[DOCKER_PASSWORD], value:[********]" + echo "ERROR! Failed to find a valid registry!" + echo "Registry:[$REGISTRY]" + exit 1 fi + ####################### # Validate IMAGE_REPO # ####################### @@ -93,6 +145,14 @@ ValidateInput() exit 1 else echo "Successfully found:[IMAGE_REPO], value:[$IMAGE_REPO]" + ############################################### + # Need to see if GPR registry and update name # + ############################################### + if [[ "$REGISTRY" == "GPR" ]]; then + NAME="docker.pkg.github/$IMAGE_REPO" + IMAGE_REPO="$NAME" + echo "Updated [IMAGE_REPO] to:[$IMAGE_REPO] for GPR" + fi fi ########################## @@ -146,22 +206,30 @@ ValidateInput() fi } ################################################################################ -#### Function LoginToDocker #################################################### -LoginToDocker() +#### Function Authenticate ##################################################### +Authenticate() { + ################ + # Pull in Vars # + ################ + USERNAME="$1" # Name to auth with + PASSWORD="$2" # Password to auth with + URL="$3" # Url to auth towards + NAME="$4" # name of the service + ################ # Print header # ################ echo "" echo "----------------------------------------------" - echo "Login to DockerHub..." + echo "Login to $NAME..." echo "----------------------------------------------" echo "" - ###################### - # Login to DockerHub # - ###################### - LOGIN_CMD=$(docker login --username "$DOCKER_USERNAME" --password "$DOCKER_PASSWORD" 2>&1) + ################### + # Auth to service # + ################### + LOGIN_CMD=$(docker login "$URL" --username "$USERNAME" --password "$PASSWORD" 2>&1) ####################### # Load the error code # @@ -173,12 +241,12 @@ LoginToDocker() ############################## if [ $ERROR_CODE -ne 0 ]; then # ERROR - echo "ERROR! Failed to authenticate to DockerHub!" + echo "ERROR! Failed to authenticate to $NAME!" echo "ERROR:[$LOGIN_CMD]" exit 1 else # SUCCESS - echo "Successfully authenticated to DockerHub!" + echo "Successfully authenticated to $NAME!" fi } ################################################################################ @@ -194,7 +262,6 @@ BuildImage() echo "----------------------------------------------" echo "" - ################################ # Validate the DOCKERFILE_PATH # ################################ @@ -238,7 +305,7 @@ UploadImage() ################ echo "" echo "----------------------------------------------" - echo "Uploading the DockerFile image..." + echo "Uploading the DockerFile image to $REGISTRY..." echo "----------------------------------------------" echo "" @@ -261,7 +328,7 @@ UploadImage() exit 1 else # SUCCESS - echo "Successfully Uploaded Docker image to DockerHub!" + echo "Successfully Uploaded Docker image to $REGISTRY!" fi ######################### @@ -329,16 +396,34 @@ Header ################## ValidateInput -###################### -# Login to DockerHub # -###################### -LoginToDocker - ################### # Build the image # ################### BuildImage +###################### +# Login to DockerHub # +###################### +if [[ "$REGISTRY" == "Docker" ]]; then + # Authenticate "Username" "Password" "Url" "Name" + Authenticate "$DOCKER_USERNAME" "$DOCKER_PASSWORD" "" "Dockerhub" + +#################################### +# Login to GitHub Package Registry # +#################################### +elif [[ "$REGISTRY" == "GPR" ]]; then + # Authenticate "Username" "Password" "Url" "Name" + Authenticate "$GPR_USERNAME" "$GPR_TOKEN" "https://docker.pkg.github.com" "GitHub Package Registry" + +else + ######### + # ERROR # + ######### + echo "ERROR! Registry not set correctly!" + echo "Registry:[$REGISTRY]" + exit 1 +fi + #################### # Upload the image # #################### 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 diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index f553dcfc..253b1933 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. A GitHub Action will Publish the Docker image to GitHub Package Registry once a Release is created +4. A GitHub Action will Publish the Docker image to Docker Hub once a Release is created +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/) diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 11fc491e..caee45bc 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. diff --git a/.github/workflows/cleanup-DEV.yml b/.github/workflows/cleanup-DEV.yml index 63d46c7a..53ef1f6a 100644 --- a/.github/workflows/cleanup-DEV.yml +++ b/.github/workflows/cleanup-DEV.yml @@ -47,7 +47,7 @@ jobs: # Set the Env Vars DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - IMAGE_REPO: admiralawkbar/super-linter + IMAGE_REPO: github/super-linter IMAGE_VERSION: ${{ github.event.pull_request.head.ref }} shell: bash run: .automation/cleanup-docker.sh diff --git a/.github/workflows/deploy-DEV.yml b/.github/workflows/deploy-DEV.yml index 4b6975d7..d9af1b44 100644 --- a/.github/workflows/deploy-DEV.yml +++ b/.github/workflows/deploy-DEV.yml @@ -43,13 +43,14 @@ jobs: ##################### # Run Deploy script # ##################### - - name: Deploy image to DockerHub + - name: Deploy DEV image to DockerHub env: # Set the Env Vars DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} IMAGE_REPO: github/super-linter DOCKERFILE_PATH: Dockerfile + REGISTRY: Docker shell: bash run: .automation/upload-docker.sh diff --git a/.github/workflows/deploy-PROD.yml b/.github/workflows/deploy-PROD.yml index fd39563b..b2306c80 100644 --- a/.github/workflows/deploy-PROD.yml +++ b/.github/workflows/deploy-PROD.yml @@ -40,7 +40,7 @@ jobs: ##################### # Run Deploy script # ##################### - - name: Deploy image to DockerHub + - name: Deploy latest image to DockerHub env: # Set the Env Vars DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} @@ -48,5 +48,6 @@ jobs: IMAGE_REPO: github/super-linter IMAGE_VERSION: latest DOCKERFILE_PATH: Dockerfile + REGISTRY: Docker shell: bash run: .automation/upload-docker.sh diff --git a/.github/workflows/deploy-RELEASE.yml b/.github/workflows/deploy-RELEASE.yml new file mode 100644 index 00000000..4417ed4b --- /dev/null +++ b/.github/workflows/deploy-RELEASE.yml @@ -0,0 +1,68 @@ +--- +######################### +######################### +## Deploy Docker Image ## +######################### +######################### + +# +# Documentation: +# https://help.github.com/en/articles/workflow-syntax-for-github-actions +# + +####################################### +# Start the job on all push to master # +####################################### +on: + release: + # Want to run the automation when a release is created + types: ['created'] + +############### +# Set the Job # +############### +jobs: + build: + # Name the Job + name: Deploy Docker Image - Release + # Set the agent to run on + runs-on: ubuntu-latest + ################## + # Load all steps # + ################## + steps: + ########################## + # Checkout the code base # + ########################## + - name: Checkout Code + uses: actions/checkout@v2 + + ################################### + # Run Deploy script for Dockerhub # + ################################### + - name: Deploy Release image to Dockerhub + env: + # Set the Env Vars + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + IMAGE_REPO: github/super-linter + IMAGE_VERSION: ${{ github.event.release.tag_name }} + DOCKERFILE_PATH: Dockerfile + REGISTRY: Docker + shell: bash + run: .automation/upload-docker.sh + + ############################# + # Run Deploy script for GPR # + ############################# + - name: Deploy Release image to GitHub Package Registry + env: + # Set the Env Vars + GPR_USERNAME: ${{ secrets.GPR_USERNAME }} + GPR_TOKEN: ${{ secrets.GPR_TOKEN }} + IMAGE_REPO: github/super-linter + IMAGE_VERSION: ${{ github.event.release.tag_name }} + DOCKERFILE_PATH: Dockerfile + REGISTRY: GPR + shell: bash + run: .automation/upload-docker.sh diff --git a/Dockerfile b/Dockerfile index fc6a0212..49a5dbb1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,27 @@ RUN apk add --no-cache \ libxml2-utils perl \ ruby ruby-dev ruby-bundler ruby-rdoc make \ py3-setuptools ansible-lint \ - go + go \ + openjdk8-jre \ + php7 \ + ca-certificates less ncurses-terminfo-base \ + krb5-libs libgcc libintl libssl1.1 libstdc++ \ + tzdata userspace-rcu zlib icu-libs lttng-ust + +######################################### +# 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 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' ##################### # Run Pip3 Installs # @@ -82,7 +102,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 '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 # @@ -102,12 +125,18 @@ 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 +################## +# Install ktlint # +################## +RUN curl -sSLO https://github.com/pinterest/ktlint/releases/latest/download/ktlint && chmod a+x ktlint \ + && mv "ktlint" /usr/bin/ + ########################################### # Load GitHub Env Vars for GitHub Actions # ########################################### @@ -116,12 +145,14 @@ ENV GITHUB_SHA=${GITHUB_SHA} \ GITHUB_WORKSPACE=${GITHUB_WORKSPACE} \ DEFAULT_BRANCH=${DEFAULT_BRANCH} \ VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} \ + LINTER_RULES_PATH=${LINTER_RULES_PATH} \ 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_PHP=${VALIDATE_PHP} \ VALIDATE_PYTHON=${VALIDATE_PYTHON} \ VALIDATE_RUBY=${VALIDATE_RUBY} \ VALIDATE_COFFEE=${VALIDATE_COFFEE} \ @@ -135,6 +166,8 @@ ENV GITHUB_SHA=${GITHUB_SHA} \ VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \ VALIDATE_CSS=${VALIDATE_CSS} \ VALIDATE_ENV=${VALIDATE_ENV} \ + VALIDATE_KOTLIN=${VALIDATE_KOTLIN} \ + VALIDATE_POWERSHELL=${VALIDATE_POWERSHELL} \ ANSIBLE_DIRECTORY=${ANSIBLE_DIRECTORY} \ RUN_LOCAL=${RUN_LOCAL} \ TEST_CASE_RUN=${TEST_CASE_RUN} \ diff --git a/README.md b/README.md index 1cf0539b..218a30d5 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **JSON** | [jsonlint](https://github.com/zaach/jsonlint) | | **Markdown** | [markdownlint](https://github.com/igorshubovych/markdownlint-cli#readme) | | **Perl** | [perl](https://pkgs.alpinelinux.org/package/edge/main/x86/perl) | +| **PHP** | [PHP](https://www.php.net/) | | **Python3** | [pylint](https://www.pylint.org/) | | **Ruby** | [RuboCop](https://github.com/rubocop-hq/rubocop) | | **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) | @@ -34,7 +35,9 @@ 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) | | **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: @@ -95,14 +98,14 @@ jobs: # Run Linter against code base # ################################ - name: Lint Code Base - uses: docker://github/super-linter:v2.1.1 + uses: docker://github/super-linter:v2.2.0 env: VALIDATE_ALL_CODEBASE: false VALIDATE_ANSIBLE: false ... ``` -**NOTE:** Using the line:`uses: docker://github/super-linter:v2.1.0` will pull the image down from **DockerHub** and run the **GitHub Super-Linter**. Using the line: `uses: github/super-linter@v2.1.0` will build and compile the **GitHub Super-Linter** at build time. This can be far more costly in time... +**NOTE:** Using the line:`uses: docker://github/super-linter:v2.2.0` will pull the image down from **DockerHub** and run the **GitHub Super-Linter**. Using the line: `uses: github/super-linter@v2.2.0` will build and compile the **GitHub Super-Linter** at build time. This can be far more costly in time... ## Environment variables The super-linter allows you to pass the following `ENV` variables to be able to trigger different functionality. @@ -118,12 +121,14 @@ and won't run anything unexpected. | --- | --- | --- | | **VALIDATE_ALL_CODEBASE** | `true` | Will parse the entire repository and find all files to validate across all types. **NOTE:** When set to `false`, only **new** or **edited** files will be parsed for validation. | | **DEFAULT_BRANCH** | `master` | The name of the repository default branch. | +| **LINTER_RULES_PATH** | `.github/linters` | Directory for all linter configuration rules. | | **VALIDATE_YAML** | `true` |Flag to enable or disable the linting process of the language. | | **VALIDATE_JSON** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_XML** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_MD** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_BASH** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_PERL** | `true` | Flag to enable or disable the linting process of the language. | +| **VALIDATE_PHP** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_PYTHON** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_RUBY** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_COFFEE** | `true` | Flag to enable or disable the linting process of the language . | @@ -134,9 +139,11 @@ 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. | | **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/TEMPLATES/.ansible-lint.yml b/TEMPLATES/.ansible-lint.yml index 0007c68d..a84da4b0 100644 --- a/TEMPLATES/.ansible-lint.yml +++ b/TEMPLATES/.ansible-lint.yml @@ -29,9 +29,9 @@ quiet: true ################ skip_list: - '602' # Allow compare to empty string - - '204' # Allow string length greater that 160 chars + - '204' # Allow string length greater than 160 chars - '301' # False positives for running command shells - - '303' # Allow git commands for push add, etc... + - '303' # Allow git commands for push, add, etc... - '305' # Allow use of shell when you want - '503' # Allow step to run like handler 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/docs/disabling-linters.md b/docs/disabling-linters.md index 84107452..9c6ecf0a 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -1,6 +1,6 @@ # Disabling linters and Rules If you find you need to ignore certain **errors** and **warnings**, you will need to know the *format* to disable the **Super-Linter** rules. -Below is examples and documentation for each language and the various methods to disable. +Below are examples and documentation for each language and the various methods to disable. ## Table of Linters - [Ruby](#ruby) @@ -11,6 +11,7 @@ Below is examples and documentation for each language and the various methods to - [JSON](#json) - [Markdown](#markdown) - [Perl](#perl) +- [PHP](#php) - [XML](#xml) - [Coffeescript](#coffeescript) - [Javascript Eslint](#javascript-eslint) @@ -22,6 +23,7 @@ Below is examples and documentation for each language and the various methods to - [Terraform](#terraform) - [CSS](#stylelint) - [ENV](#dotenv-linter) +- [Kotlin](#kotlin) @@ -303,6 +305,23 @@ Here is more data -------------------------------------------------------------------------------- +## PHP +- [PHP](https://www.php.net/) + +### PHP Config file +- There is no top level *configuration file* available at this time + +### PHP disable single line +- There is currently **No** way to disable rules inline of the file(s) + +### PHP disable code block +- There is currently **No** way to disable rules inline of the file(s) + +### PHP disable entire file +- There is currently **No** way to disable rules inline of the file(s) + +-------------------------------------------------------------------------------- + ## XML - [XML](http://xmlsoft.org/) @@ -564,3 +583,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 5c9db08f..e422ad9d 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # shellcheck disable=SC1003,SC2016 ################################################################################ @@ -12,7 +12,7 @@ ########### # Default Vars DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location -LINTER_PATH='.github/linters' # Default linter path +LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter Path Directory # YAML Vars YAML_FILE_NAME='.yaml-lint.yml' # Name of the file YAML_LINTER_RULES="$DEFAULT_RULES_LOCATION/$YAML_FILE_NAME" # Path to the yaml lint rules @@ -48,25 +48,28 @@ 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-psscriptanalyzer.psd1' # Name of the file +POWERSHELL_LINTER_RULES="$DEFAULT_RULES_LOCATION/$POWERSHELL_FILE_NAME" # Path to the Powershell lint rules # CSS Vars CSS_FILE_NAME='.stylelintrc.json' # Name of the file CSS_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CSS_FILE_NAME" # Path to the CSS 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" - "stylelint" "dotenv-linter") + "stylelint" "dotenv-linter" "powershell" "ktlint") ############################# # Language array for prints # ############################# -LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RUBY' 'PYTHON' +LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'PHP' 'RUBY' 'PYTHON' 'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES' - 'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' 'CSS' "ENV") + 'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' + 'ENV' 'POWERSHELL' 'KOTLIN') ################### # GitHub ENV Vars # @@ -83,6 +86,7 @@ VALIDATE_XML="${VALIDATE_XML}" # Boolean to validate lang VALIDATE_MD="${VALIDATE_MD}" # Boolean to validate language VALIDATE_BASH="${VALIDATE_BASH}" # Boolean to validate language VALIDATE_PERL="${VALIDATE_PERL}" # Boolean to validate language +VALIDATE_PHP="${VALIDATE_PHP}" # Boolean to validate language VALIDATE_PYTHON="${VALIDATE_PYTHON}" # Boolean to validate language VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language VALIDATE_COFFEE="${VALIDATE_COFFEE}" # Boolean to validate language @@ -93,9 +97,11 @@ VALIDATE_TYPESCRIPT_ES="${VALIDATE_TYPESCRIPT_ES}" # Boolean to val VALIDATE_TYPESCRIPT_STANDARD="${VALIDATE_TYPESCRIPT_STANDARD}" # Boolean to validate language 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_CSS="${VALIDATE_CSS}" # Boolean to validate language VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate language +VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language +VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # 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 @@ -108,16 +114,16 @@ ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG}" # Boolean to see even more info ################ # Default Vars # ################ -DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files -DEFAULT_WORKSPACE="${DEFAULT_WORKSPACE:-/tmp/lint}" # Default workspace if running locally -DEFAULT_ANSIBLE_DIRECTORY="$GITHUB_WORKSPACE/ansible" # Default Ansible Directory -DEFAULT_RUN_LOCAL='false' # Default value for debugging locally -DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases -DEFAULT_ACTIONS_RUNNER_DEBUG='false' # Default value for debugging output -RAW_FILE_ARRAY=() # Array of all files that were changed -READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md -TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore -DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors +DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files +DEFAULT_WORKSPACE="${DEFAULT_WORKSPACE:-/tmp/lint}" # Default workspace if running locally +DEFAULT_ANSIBLE_DIRECTORY="$GITHUB_WORKSPACE/ansible" # Default Ansible Directory +DEFAULT_RUN_LOCAL='false' # Default value for debugging locally +DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases +DEFAULT_ACTIONS_RUNNER_DEBUG='false' # Default value for debugging output +RAW_FILE_ARRAY=() # Array of all files that were changed +READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md +TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore +DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors ########################## # Array of changed files # @@ -128,6 +134,7 @@ FILE_ARRAY_XML=() # Array of files to check FILE_ARRAY_MD=() # Array of files to check FILE_ARRAY_BASH=() # Array of files to check FILE_ARRAY_PERL=() # Array of files to check +FILE_ARRAY_PHP=() # Array of files to check FILE_ARRAY_RUBY=() # Array of files to check FILE_ARRAY_PYTHON=() # Array of files to check FILE_ARRAY_COFFEESCRIPT=() # Array of files to check @@ -138,8 +145,10 @@ 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 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 # @@ -150,6 +159,7 @@ ERRORS_FOUND_XML=0 # Count of errors found ERRORS_FOUND_MARKDOWN=0 # Count of errors found ERRORS_FOUND_BASH=0 # Count of errors found ERRORS_FOUND_PERL=0 # Count of errors found +ERRORS_FOUND_PHP=0 # Count of errors found ERRORS_FOUND_RUBY=0 # Count of errors found ERRORS_FOUND_PYTHON=0 # Count of errors found ERRORS_FOUND_COFFEESCRIPT=0 # Count of errors found @@ -161,8 +171,10 @@ 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 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 ##################################### @@ -250,14 +262,14 @@ GetLinterRules() ##################################### # Validate we have the linter rules # ##################################### - if [ -f "$GITHUB_WORKSPACE/$LINTER_PATH/$FILE_NAME" ]; then + if [ -f "$GITHUB_WORKSPACE/$LINTER_RULES_PATH/$FILE_NAME" ]; then echo "----------------------------------------------" echo "User provided file:[$FILE_NAME], setting rules file..." #################################### # Copy users into default location # #################################### - CP_CMD=$(cp "$GITHUB_WORKSPACE/$LINTER_PATH/$FILE_NAME" "$FILE_LOCATION" 2>&1) + CP_CMD=$(cp "$GITHUB_WORKSPACE/$LINTER_RULES_PATH/$FILE_NAME" "$FILE_LOCATION" 2>&1) ################### # Load Error code # @@ -277,7 +289,7 @@ GetLinterRules() # No user default provided, using the template default # ######################################################## if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then - echo " -> Codebase does NOT have file:[$LINTER_PATH/$FILE_NAME], using Default rules at:[$FILE_LOCATION]" + echo " -> Codebase does NOT have file:[$LINTER_RULES_PATH/$FILE_NAME], using Default rules at:[$FILE_LOCATION]" fi fi } @@ -728,6 +740,7 @@ GetValidationInfo() VALIDATE_MD=$(echo "$VALIDATE_MD" | awk '{print tolower($0)}') VALIDATE_BASH=$(echo "$VALIDATE_BASH" | awk '{print tolower($0)}') VALIDATE_PERL=$(echo "$VALIDATE_PERL" | awk '{print tolower($0)}') + VALIDATE_PHP=$(echo "$VALIDATE_PHP" | awk '{print tolower($0)}') VALIDATE_PYTHON=$(echo "$VALIDATE_PYTHON" | awk '{print tolower($0)}') VALIDATE_RUBY=$(echo "$VALIDATE_RUBY" | awk '{print tolower($0)}') VALIDATE_COFFEE=$(echo "$VALIDATE_COFFEE" | awk '{print tolower($0)}') @@ -739,8 +752,10 @@ 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)}') 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 # @@ -752,6 +767,7 @@ GetValidationInfo() -n "$VALIDATE_MD" || \ -n "$VALIDATE_BASH" || \ -n "$VALIDATE_PERL" || \ + -n "$VALIDATE_PHP" || \ -n "$VALIDATE_PYTHON" || \ -n "$VALIDATE_RUBY" || \ -n "$VALIDATE_COFFEE" || \ @@ -763,8 +779,10 @@ GetValidationInfo() -n "$VALIDATE_DOCKER" || \ -n "$VALIDATE_GO" || \ -n "$VALIDATE_TERRAFORM" || \ + -n "$VALIDATE_POWERSHELL" || \ -n "$VALIDATE_CSS" || \ - -n "$VALIDATE_ENV" ]]; then + -n "$VALIDATE_ENV" || \ + -n "$VALIDATE_KOTLIN" ]]; then ANY_SET="true" fi @@ -852,6 +870,20 @@ GetValidationInfo() VALIDATE_PERL="true" fi + #################################### + # Validate if we should check PHP # + #################################### + if [[ "$ANY_SET" == "true" ]]; then + # Some linter flags were set - only run those set to true + if [[ -z "$VALIDATE_PHP" ]]; then + # PHP flag was not set - default to false + VALIDATE_PHP="false" + fi + else + # No linter flags were set - default all to true + VALIDATE_PHP="true" + fi + ###################################### # Validate if we should check PYTHON # ###################################### @@ -1006,6 +1038,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 + ################################### # Validate if we should check CSS # ################################### @@ -1020,9 +1066,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 @@ -1034,6 +1080,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 # ####################################### @@ -1067,6 +1128,11 @@ GetValidationInfo() else PRINT_ARRAY+=("- Excluding [PERL] files in code base...") fi + if [[ "$VALIDATE_PHP" == "true" ]]; then + PRINT_ARRAY+=("- Validating [PHP] files in code base...") + else + PRINT_ARRAY+=("- Excluding [PHP] files in code base...") + fi if [[ "$VALIDATE_PYTHON" == "true" ]]; then PRINT_ARRAY+=("- Validating [PYTHON] files in code base...") else @@ -1122,6 +1188,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 if [[ "$VALIDATE_CSS" == "true" ]]; then PRINT_ARRAY+=("- Validating [CSS] files in code base...") else @@ -1132,6 +1203,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 # @@ -1376,6 +1452,18 @@ BuildFileList() ########################################################## READ_ONLY_CHANGE_FLAG=1 ###################### + # Get the PHP files # + ###################### + elif [ "$FILE_TYPE" == "php" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_PHP+=("$FILE") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ###################### # Get the RUBY files # ###################### elif [ "$FILE_TYPE" == "rb" ]; then @@ -1461,6 +1549,14 @@ 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") elif [ "$FILE_TYPE" == "css" ]; then ################################ # Append the file to the array # @@ -1479,6 +1575,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 # @@ -1704,10 +1809,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" || exit; $LINTER_COMMAND "$FILE"; exit $? 2>&1) + else + ################################ + # Lint the file with the rules # + ################################ + LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1) + fi ####################### # Load the error code # @@ -1874,6 +1995,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, also exit with exit code from inner subshell + LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE"; exit $? 2>&1) else ################################ # Lint the file with the rules # @@ -1980,6 +2107,7 @@ Footer() [ "$ERRORS_FOUND_MARKDOWN" -ne 0 ] || \ [ "$ERRORS_FOUND_BASH" -ne 0 ] || \ [ "$ERRORS_FOUND_PERL" -ne 0 ] || \ + [ "$ERRORS_FOUND_PHP" -ne 0 ] || \ [ "$ERRORS_FOUND_PYTHON" -ne 0 ] || \ [ "$ERRORS_FOUND_COFFEESCRIPT" -ne 0 ] || \ [ "$ERRORS_FOUND_ANSIBLE" -ne 0 ] || \ @@ -1990,9 +2118,11 @@ 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 ] || \ [ "$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 @@ -2039,6 +2169,7 @@ RunTestCases() TestCodebase "BASH" "shellcheck" "shellcheck" ".*\.\(sh\)\$" TestCodebase "PYTHON" "pylint" "pylint --rcfile $PYTHON_LINTER_RULES -E" ".*\.\(py\)\$" TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" + TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" TestCodebase "RUBY" "rubocop" "rubocop -c $RUBY_LINTER_RULES" ".*\.\(rb\)\$" TestCodebase "GO" "golangci-lint" "golangci-lint run -c $GO_LINTER_RULES" ".*\.\(go\)\$" TestCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f $COFFEESCRIPT_LINTER_RULES" ".*\.\(coffee\)\$" @@ -2049,8 +2180,10 @@ 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 "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" + TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" ################# # Footer prints # @@ -2105,6 +2238,8 @@ 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 PowerShell rules +GetLinterRules "$POWERSHELL_FILE_NAME" "$POWERSHELL_LINTER_RULES" # Get CSS rules GetLinterRules "$CSS_FILE_NAME" "$CSS_LINTER_RULES" @@ -2216,6 +2351,17 @@ if [ "$VALIDATE_PERL" == "true" ]; then LintCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "${FILE_ARRAY_PERL[@]}" fi +################ +# PHP LINTING # +################ +if [ "$VALIDATE_PHP" == "true" ]; then + ####################### + # Lint the PHP files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "${FILE_ARRAY_PHP[@]}" +fi + ################ # RUBY LINTING # ################ @@ -2336,15 +2482,26 @@ 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 + +################## +# 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 ################## @@ -2358,6 +2515,17 @@ 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 -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}" +fi + ########## # Footer # ########## diff --git a/lib/possum.sh b/lib/possum.sh index f23e60a7..dd87d952 100755 --- a/lib/possum.sh +++ b/lib/possum.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash cat <