diff --git a/.github/workflows/cleanup-DEV.yml b/.github/workflows/cleanup-DEV.yml deleted file mode 100644 index 53ef1f6a..00000000 --- a/.github/workflows/cleanup-DEV.yml +++ /dev/null @@ -1,53 +0,0 @@ ---- -########################## -########################## -## Cleanup Docker Image ## -########################## -########################## - -# -# Documentation: -# https://help.github.com/en/articles/workflow-syntax-for-github-actions -# - -######################################## -# Run job when PR is merged and closed # -######################################## - -on: - pull_request: - types: [closed] - -############### -# Set the Job # -############### -jobs: - build: - # Name the Job - name: Cleanup Docker Image - DEV - # 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 - with: - ref: ${{ github.event.pull_request.head.sha }} - - ###################### - # Run Removal script # - ###################### - - name: Remove old image from 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.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 d9af1b44..0f55b010 100644 --- a/.github/workflows/deploy-DEV.yml +++ b/.github/workflows/deploy-DEV.yml @@ -20,6 +20,7 @@ on: push: branches-ignore: - 'master' + pull_request: [] ############### # Set the Job # @@ -40,32 +41,16 @@ jobs: - name: Checkout Code uses: actions/checkout@v2 - ##################### - # Run Deploy script # - ##################### - - 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 + ################################### + # Build image locally for testing # + ################################### + - name: Build image shell: bash - run: .automation/upload-docker.sh - - ####################### - # Get the branch name # - ####################### - - name: Extract branch name - shell: bash - run: echo "::set-env name=BRANCH_NAME::$(echo ${GITHUB_REF#refs/heads/} | sed 's/[^[:alnum:]]//g')" + run: docker build --no-cache -t github/super-linter:${GITHUB_SHA} . ################################ # Run Linter against code base # ################################ - name: Run Test Cases shell: bash - run: | - docker pull github/super-linter:${BRANCH_NAME} - docker run -e RUN_LOCAL=true -e TEST_CASE_RUN=true -v ${GITHUB_WORKSPACE}:/tmp/lint github/super-linter:${BRANCH_NAME} + run: docker run -e RUN_LOCAL=true -e TEST_CASE_RUN=true -v ${GITHUB_WORKSPACE}:/tmp/lint github/super-linter:${GITHUB_SHA} diff --git a/.github/workflows/versioning.yml b/.github/workflows/versioning.yml index 01039a30..c95b118a 100644 --- a/.github/workflows/versioning.yml +++ b/.github/workflows/versioning.yml @@ -1,14 +1,42 @@ -name: Keep the versions up-to-date +--- +######################### +######################### +## Version GitHub Tags ## +######################### +######################### +# +# Documentation: +# https://help.github.com/en/articles/workflow-syntax-for-github-actions +# + +########################## +# Name of the action job # +########################## +name: Keep GitHub tag versions up-to-date + +##################################################### +# Run the job when a release is published or edited # +##################################################### on: release: types: [published, edited] +################# +# Start the job # +################# jobs: actions-tagger: runs-on: windows-latest steps: + ############################# + # Check out the latest code # + ############################# - uses: actions/checkout@v2 + + ###################### + # Run the tag action # + ###################### - uses: Actions-R-Us/actions-tagger@latest with: publish_latest_tag: true diff --git a/Dockerfile b/Dockerfile index 63fb9ac2..56bc44a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,15 +39,19 @@ RUN apk add --no-cache \ ######################################### # Reference: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7 # 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 \ +# If changing PWSH_VERSION='latest' to a specific version, use format PWSH_VERSION='tags/v7.0.2' +ARG PWSH_VERSION='latest' +ARG PWSH_DIRECTORY='/opt/microsoft/powershell' +ARG PSSA_VERSION='latest' +RUN mkdir -p ${PWSH_DIRECTORY} \ + && curl -s https://api.github.com/repos/powershell/powershell/releases/${PWSH_VERSION} \ | grep browser_download_url \ | grep 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 -Scope AllUsers -force' + | tar -xzC ${PWSH_DIRECTORY} \ + && ln -s ${PWSH_DIRECTORY}/pwsh /usr/bin/pwsh -f \ + && pwsh -c 'Install-Module -Name PSScriptAnalyzer -RequiredVersion ${PSSA_VERSION} -Scope AllUsers -Force' ##################### # Run Pip3 Installs # diff --git a/README.md b/README.md index d3c7b8a6..9288b4ba 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **YAML** | [YamlLint](https://github.com/adrienverge/yamllint) | ## How to use -How to gif +More in-depth [tutorial](https://www.youtube.com/watch?v=EDAmFKO4Zt0&t=118s) available To use this **GitHub** Action you will need to complete the following: 1. Create a new file in your repository called `.github/workflows/linter.yml` diff --git a/docs/how-to.gif b/docs/how-to.gif deleted file mode 100644 index aa2b9ca7..00000000 Binary files a/docs/how-to.gif and /dev/null differ diff --git a/lib/linter.sh b/lib/linter.sh index 01e937d3..72a4b451 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -84,10 +84,9 @@ CLOJURE_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CLOJURE_FILE_NAME" LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck" "pylint" "perl" "rubocop" "coffeelint" "eslint" "standard" "ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint" - "stylelint" "dotenv-linter" "powershell" "ktlint" "protolint" "clj-kondo" + "stylelint" "dotenv-linter" "pwsh" "ktlint" "protolint" "clj-kondo" "spectral" "cfn-lint") - ############################# # Language array for prints # ############################# @@ -644,6 +643,48 @@ GetGitHubVars() fi } ################################################################################ +#### Function ValidatePowershellModules ######################################## +function ValidatePowershellModules() +{ + VALIDATE_PSSA_MODULE=$(pwsh -c "(Get-Module -Name PSScriptAnalyzer -ListAvailable | Select-Object -First 1).Name" 2>&1) + # If module found, ensure Invoke-ScriptAnalyzer command is available + if [[ "$VALIDATE_PSSA_MODULE" == "PSScriptAnalyzer" ]]; then + VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1) + else + # Failed to find module + exit 1 + fi + + ######################################### + # validate we found the script analyzer # + ######################################### + if [[ "$VALIDATE_PSSA_CMD" != "Invoke-ScriptAnalyzer" ]]; then + # Failed to find module + exit 1 + fi + + ####################### + # Load the error code # + ####################### + ERROR_CODE=$? + + ############################## + # Check the shell for errors # + ############################## + if [ $ERROR_CODE -ne 0 ]; then + # Failed + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed find module [PSScriptAnalyzer] for [$LINTER_NAME] in system!" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[PSSA_MODULE $VALIDATE_PSSA_MODULE] [PSSA_CMD $VALIDATE_PSSA_CMD]" + exit 1 + else + # Success + if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then + echo "Successfully found module [$VALIDATE_PSSA_MODULE] in system" + echo "Successfully found command [$VALIDATE_PSSA_CMD] in system" + fi + fi +} +################################################################################ #### Function Footer ########################################################### Footer() { @@ -1090,11 +1131,16 @@ fi # POWERSHELL LINTING # ###################### if [ "$VALIDATE_POWERSHELL" == "true" ]; then + ############################################################### + # For POWERSHELL, ensure PSScriptAnalyzer module is available # + ############################################################### + ValidatePowershellModules + ############################# # 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[@]}" + LintCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}" fi ################### diff --git a/lib/worker.sh b/lib/worker.sh index 1c11cb4d..03db8460 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -35,9 +35,9 @@ function LintCodebase() PRINT_ARRAY+=("----------------------------------------------") PRINT_ARRAY+=("----------------------------------------------") - ####################################### - # Validate we have jsonlint installed # - ####################################### + ##################################### + # Validate we have linter installed # + ##################################### VALIDATE_INSTALL_CMD=$(command -v "$LINTER_NAME" 2>&1) ####################### @@ -56,7 +56,7 @@ function LintCodebase() else # Success if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then - echo -e "${NC}${F[B]}Successfully found binary in system${NC}" + echo -e "${NC}${F[B]}Successfully found binary for ${F[W]}[$LINTER_NAME]${F[B]} in system${NC}" echo "Location:[$VALIDATE_INSTALL_CMD]" fi fi @@ -166,8 +166,8 @@ function 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" || exit; $LINTER_COMMAND "$FILE"; exit $? 2>&1) + # Need to run PowerShell commands using pwsh -c, also exit with exit code from inner subshell + LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; pwsh -c "($LINTER_COMMAND $FILE)"; exit $? 2>&1) else ################################ # Lint the file with the rules # @@ -333,8 +333,8 @@ function 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) + # Need to run PowerShell commands using pwsh -c, also exit with exit code from inner subshell + LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; pwsh -c "($LINTER_COMMAND $FILE)"; exit $? 2>&1) else ################################ # Lint the file with the rules #