diff --git a/.automation/cleanup-docker.sh b/.automation/cleanup-docker.sh index 838119c4..ab0bb546 100755 --- a/.automation/cleanup-docker.sh +++ b/.automation/cleanup-docker.sh @@ -16,20 +16,19 @@ ########### # Globals # ########### -GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace -DOCKER_USERNAME="${DOCKER_USERNAME}" # Username to login to DockerHub -DOCKER_PASSWORD="${DOCKER_PASSWORD}" # Password to login to DockerHub -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 +GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace +DOCKER_USERNAME="${DOCKER_USERNAME}" # Username to login to DockerHub +DOCKER_PASSWORD="${DOCKER_PASSWORD}" # Password to login to DockerHub +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 ################################################################################ ############################ FUNCTIONS BELOW ################################### ################################################################################ ################################################################################ #### Function Header ########################################################### -Header() -{ +Header() { echo "" echo "-------------------------------------------------------" echo "----- GitHub Actions remove image from DockerHub ------" @@ -38,8 +37,7 @@ Header() } ################################################################################ #### Function ValidateInput #################################################### -ValidateInput() -{ +ValidateInput() { # Need to validate we have the basic variables ################ # Print header # @@ -54,8 +52,8 @@ ValidateInput() # Validate GITHUB_WORKSPACE # ############################ if [ -z "$GITHUB_WORKSPACE" ]; then - echo "ERROR! Failed to get [GITHUB_WORKSPACE]!" - echo "ERROR:[$GITHUB_WORKSPACE]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_WORKSPACE]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$GITHUB_WORKSPACE]${NC}" exit 1 else echo "Successfully found:[GITHUB_WORKSPACE], value:[$GITHUB_WORKSPACE]" @@ -66,15 +64,15 @@ ValidateInput() ####################### if [ -z "$IMAGE_REPO" ]; then # No repo was pulled - echo "ERROR! Failed to get [IMAGE_REPO]!" - echo "ERROR:[$IMAGE_REPO]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [IMAGE_REPO]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$IMAGE_REPO]${NC}" exit 1 - elif [[ "$IMAGE_REPO" == "github/super-linter" ]]; then + elif [[ $IMAGE_REPO == "github/super-linter" ]]; then # Found our main repo echo "Successfully found:[IMAGE_REPO], value:[$IMAGE_REPO]" else # This is a fork and we cant pull vars or any info - echo "WARN! No image to cleanup as this is a forked branch, and not being built with current automation!" + echo -e "${NC}${F[Y]}WARN!${NC} No image to cleanup as this is a forked branch, and not being built with current automation!${NC}" exit 0 fi @@ -82,8 +80,8 @@ ValidateInput() # Validate IMAGE_VERSION # ########################## if [ -z "$IMAGE_VERSION" ]; then - echo "ERROR! Failed to get [IMAGE_VERSION]!" - echo "ERROR:[$IMAGE_VERSION]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [IMAGE_VERSION]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$IMAGE_VERSION]${NC}" exit 1 else echo "Successfully found:[IMAGE_VERSION], value:[$IMAGE_VERSION]" @@ -93,8 +91,8 @@ ValidateInput() # Validate DOCKER_USERNAME # ############################ if [ -z "$DOCKER_USERNAME" ]; then - echo "ERROR! Failed to get [DOCKER_USERNAME]!" - echo "ERROR:[$DOCKER_USERNAME]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKER_USERNAME]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$DOCKER_USERNAME]${NC}" exit 1 else echo "Successfully found:[DOCKER_USERNAME], value:[$DOCKER_USERNAME]" @@ -104,8 +102,8 @@ ValidateInput() # Validate DOCKER_PASSWORD # ############################ if [ -z "$DOCKER_PASSWORD" ]; then - echo "ERROR! Failed to get [DOCKER_PASSWORD]!" - echo "ERROR:[$DOCKER_PASSWORD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKER_PASSWORD]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$DOCKER_PASSWORD]${NC}" exit 1 else echo "Successfully found:[DOCKER_PASSWORD], value:[********]" @@ -114,7 +112,7 @@ ValidateInput() ################################################## # Check if we need to get the name of the branch # ################################################## - if [[ "$IMAGE_VERSION" != "latest" ]]; then + if [[ $IMAGE_VERSION != "latest" ]]; then ################################## # Remove non alpha-numeric chars # ################################## @@ -131,8 +129,7 @@ ValidateInput() } ################################################################################ #### Function LoginToDocker #################################################### -LoginToDocker() -{ +LoginToDocker() { ################ # Print header # ################ @@ -157,8 +154,8 @@ LoginToDocker() ############################## if [ $ERROR_CODE -ne 0 ]; then # ERROR - echo "ERROR! Failed to authenticate to DockerHub!" - echo "ERROR:[$LOGIN_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to authenticate to DockerHub!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$LOGIN_CMD]${NC}" exit 1 else # SUCCESS @@ -167,8 +164,7 @@ LoginToDocker() } ################################################################################ #### Function RemoveImage ###################################################### -RemoveImage() -{ +RemoveImage() { ################ # Print header # ################ @@ -187,23 +183,23 @@ RemoveImage() -d "{\"username\": \"$DOCKER_USERNAME\", \"password\": \"$DOCKER_PASSWORD\"}" \ "https://hub.docker.com/v2/users/login/" | jq -r .token 2>&1) - ####################### - # Load the ERROR_CODE # - ####################### - ERROR_CODE=$? + ####################### + # Load the ERROR_CODE # + ####################### + ERROR_CODE=$? - ############################## - # Check the shell for errors # - ############################## - if [ $ERROR_CODE -ne 0 ]; then - # ERROR - echo "ERROR! Failed to gain token from DockerHub!" - echo "ERROR:[$TOKEN]" - exit 1 - else - # SUCCESS - echo "Successfully gained auth token from DockerHub!" - fi + ############################## + # Check the shell for errors # + ############################## + if [ $ERROR_CODE -ne 0 ]; then + # ERROR + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to gain token from DockerHub!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$TOKEN]${NC}" + exit 1 + else + # SUCCESS + echo "Successfully gained auth token from DockerHub!" + fi ################################# # Remove the tag from DockerHub # @@ -222,8 +218,8 @@ RemoveImage() ############################## if [ $ERROR_CODE -ne 0 ]; then # ERROR - echo "ERROR! Failed to remove tag from DockerHub!" - echo "ERROR:[$REMOVE_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to remove tag from DockerHub!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$REMOVE_CMD]${NC}" exit 1 else # SUCCESS @@ -232,8 +228,7 @@ RemoveImage() } ################################################################################ #### Function Footer ########################################################### -Footer() -{ +Footer() { echo "" echo "-------------------------------------------------------" echo "The step has completed" 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 f33f0475..0fe1e1e0 100644 --- a/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh +++ b/.automation/test/ansible/ghe-initialize/templates/ghe-config-apply.sh @@ -53,8 +53,8 @@ CheckGHEPid() # Check the shell for errors # ############################## if [ $ERROR_CODE -ne 0 ]; then - echo "ERROR! Failed to sleep!" - echo "ERROR:[$SLEEP_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to sleep!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$SLEEP_CMD]${NC}" echo "Will try to call apply as last effort..." #################################### # Call config apply as last effort # @@ -117,8 +117,8 @@ CheckGHEProcess() # Check the shell for errors # ############################## if [ $ERROR_CODE -ne 0 ]; then - echo "ERROR! Failed to sleep!" - echo "ERROR:[$SLEEP_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to sleep!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$SLEEP_CMD]${NC}" echo "Will try to call apply as last effort..." #################################### # Call config apply as last effort # @@ -161,12 +161,12 @@ RunConfigApply() ############################## if [ $ERROR_CODE -ne 0 ]; then # Errors - echo "ERROR! Failed to run config apply command!" - echo "ERROR:[$APPLY_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to run config apply command!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$APPLY_CMD]${NC}" exit 1 else # Success - echo "Successfully ran $GHE_APPLY_COMMAND" + echo -e "${NC}${F[B]}Successfully ran ${F[C]}$GHE_APPLY_COMMAND${NC}" fi } ################################################################################ diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index 55719d6b..1c982c63 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -17,25 +17,24 @@ ########### # Globals # ########### -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 -MAJOR_TAG='' # Major tag version if we need to update it -UPDATE_MAJOR_TAG=0 # Flag to deploy the major tag version as well +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 +MAJOR_TAG='' # Major tag version if we need to update it +UPDATE_MAJOR_TAG=0 # Flag to deploy the major tag version as well ################################################################################ ############################ FUNCTIONS BELOW ################################### ################################################################################ ################################################################################ #### Function Header ########################################################### -Header() -{ +Header() { echo "" echo "-------------------------------------------------------" echo "---- GitHub Actions Upload image to [$REGISTRY] ----" @@ -44,8 +43,7 @@ Header() } ################################################################################ #### Function ValidateInput #################################################### -ValidateInput() -{ +ValidateInput() { # Need to validate we have the basic variables ################ # Print header # @@ -60,97 +58,96 @@ ValidateInput() # Validate GITHUB_WORKSPACE # ############################# if [ -z "$GITHUB_WORKSPACE" ]; then - echo "ERROR! Failed to get [GITHUB_WORKSPACE]!" - echo "ERROR:[$GITHUB_WORKSPACE]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_WORKSPACE]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$GITHUB_WORKSPACE]${NC}" exit 1 else - echo "Successfully found:[GITHUB_WORKSPACE], value:[$GITHUB_WORKSPACE]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[$GITHUB_WORKSPACE]${NC}" fi ##################### # Validate REGISTRY # ##################### if [ -z "$REGISTRY" ]; then - echo "ERROR! Failed to get [REGISTRY]!" - echo "ERROR:[$REGISTRY]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [REGISTRY]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$REGISTRY]${NC}" exit 1 else - echo "Successfully found:[REGISTRY], value:[$REGISTRY]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[REGISTRY]${F[B]}, value:${F[W]}[$REGISTRY]${NC}" fi ##################################################### # See if we need values for GitHub package Registry # ##################################################### - if [[ "$REGISTRY" == "GPR" ]]; then + if [[ $REGISTRY == "GPR" ]]; then ######################### # Validate GPR_USERNAME # ######################### if [ -z "$GPR_USERNAME" ]; then - echo "ERROR! Failed to get [GPR_USERNAME]!" - echo "ERROR:[$GPR_USERNAME]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GPR_USERNAME]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$GPR_USERNAME]${NC}" exit 1 else - echo "Successfully found:[GPR_USERNAME], value:[$GPR_USERNAME]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[GPR_USERNAME]${F[B]}, value:${F[W]}[$GPR_USERNAME]${NC}" fi ###################### # Validate GPR_TOKEN # ###################### if [ -z "$GPR_TOKEN" ]; then - echo "ERROR! Failed to get [GPR_TOKEN]!" - echo "ERROR:[$GPR_TOKEN]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GPR_TOKEN]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$GPR_TOKEN]${NC}" exit 1 else - echo "Successfully found:[GPR_TOKEN], value:[********]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[GPR_TOKEN]${F[B]}, value:${F[W]}[********]${NC}" fi ######################################## # See if we need values for Ducker hub # ######################################## - elif [[ "$REGISTRY" == "Docker" ]]; then + elif [[ $REGISTRY == "Docker" ]]; then ############################ # Validate DOCKER_USERNAME # ############################ if [ -z "$DOCKER_USERNAME" ]; then - echo "ERROR! Failed to get [DOCKER_USERNAME]!" - echo "ERROR:[$DOCKER_USERNAME]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKER_USERNAME]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$DOCKER_USERNAME]${NC}" exit 1 else - echo "Successfully found:[DOCKER_USERNAME], value:[$DOCKER_USERNAME]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[DOCKER_USERNAME]${F[B]}, value:${F[W]}[$DOCKER_USERNAME]${NC}" fi ############################ # Validate DOCKER_PASSWORD # ############################ if [ -z "$DOCKER_PASSWORD" ]; then - echo "ERROR! Failed to get [DOCKER_PASSWORD]!" - echo "ERROR:[$DOCKER_PASSWORD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKER_PASSWORD]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$DOCKER_PASSWORD]${NC}" exit 1 else - echo "Successfully found:[DOCKER_PASSWORD], value:[********]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[DOCKER_PASSWORD]${F[B]}, value:${F[B]}[********]${NC}" fi ########################################### # We were not passed a registry to update # ########################################### else - echo "ERROR! Failed to find a valid registry!" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find a valid registry!${NC}" echo "Registry:[$REGISTRY]" exit 1 fi - ####################### # Validate IMAGE_REPO # ####################### if [ -z "$IMAGE_REPO" ]; then - echo "ERROR! Failed to get [IMAGE_REPO]!" - echo "ERROR:[$IMAGE_REPO]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [IMAGE_REPO]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$IMAGE_REPO]${NC}" exit 1 else - echo "Successfully found:[IMAGE_REPO], value:[$IMAGE_REPO]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[IMAGE_REPO]${F[B]}, value:${F[W]}[$IMAGE_REPO]${NC}" ############################################### # Need to see if GPR registry and update name # ############################################### - if [[ "$REGISTRY" == "GPR" ]]; then + if [[ $REGISTRY == "GPR" ]]; then NAME="docker.pkg.github.com/$IMAGE_REPO/super-linter" IMAGE_REPO="$NAME" echo "Updated [IMAGE_REPO] to:[$IMAGE_REPO] for GPR" @@ -161,12 +158,12 @@ ValidateInput() # Validate IMAGE_VERSION # ########################## if [ -z "$IMAGE_VERSION" ]; then - echo "WARN! Failed to get [IMAGE_VERSION]!" + echo -e "${NC}${F[Y]}WARN!${NC} Failed to get [IMAGE_VERSION]!${NC}" echo "Pulling from Branch Name..." ############################## # Get the name of the branch # ############################## - BRANCH_NAME=$(git -C "$GITHUB_WORKSPACE" branch --contains "$GITHUB_SHA" |awk '{print $2}' 2>&1) + BRANCH_NAME=$(git -C "$GITHUB_WORKSPACE" branch --contains "$GITHUB_SHA" | awk '{print $2}' 2>&1) ####################### # Load the error code # @@ -177,8 +174,8 @@ ValidateInput() # Check the shell for errors # ############################## if [ $ERROR_CODE -ne 0 ]; then - echo "ERROR! Failed to get branch name!" - echo "ERROR:[$BRANCH_NAME]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get branch name!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$BRANCH_NAME]${NC}" exit 1 fi @@ -193,7 +190,7 @@ ValidateInput() IMAGE_VERSION="$BRANCH_NAME" echo "Tag:[$IMAGE_VERSION]" else - echo "Successfully found:[IMAGE_VERSION], value:[$IMAGE_VERSION]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[IMAGE_VERSION]${F[B]}, value:${F[W]}[$IMAGE_VERSION]${NC}" fi ################################## @@ -204,7 +201,7 @@ ValidateInput() ###################################################################### # Check if this is a latest to a versioned release at create new tag # ###################################################################### - if [[ "$IMAGE_VERSION" =~ $REGEX ]]; then + if [[ $IMAGE_VERSION =~ $REGEX ]]; then # Need to get the major version, and set flag to update ##################### @@ -224,24 +221,23 @@ ValidateInput() # Validate DOCKERFILE_PATH # ############################ if [ -z "$DOCKERFILE_PATH" ]; then - echo "ERROR! Failed to get [DOCKERFILE_PATH]!" - echo "ERROR:[$DOCKERFILE_PATH]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [DOCKERFILE_PATH]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$DOCKERFILE_PATH]${NC}" exit 1 else - echo "Successfully found:[DOCKERFILE_PATH], value:[$DOCKERFILE_PATH]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[DOCKERFILE_PATH]${F[B]}, value:${F[W]}[$DOCKERFILE_PATH]${NC}" fi } ################################################################################ #### Function Authenticate ##################################################### -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 + 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 # @@ -267,18 +263,17 @@ Authenticate() ############################## if [ $ERROR_CODE -ne 0 ]; then # ERROR - echo "ERROR! Failed to authenticate to $NAME!" - echo "ERROR:[$LOGIN_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to authenticate to $NAME!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$LOGIN_CMD]${NC}" exit 1 else # SUCCESS - echo "Successfully authenticated to $NAME!" + echo -e "${NC}${F[B]}Successfully authenticated to ${F[C]}$NAME${F[B]}!${NC}" fi } ################################################################################ #### Function BuildImage ####################################################### -BuildImage() -{ +BuildImage() { ################ # Print header # ################ @@ -293,7 +288,7 @@ BuildImage() ################################ if [ ! -f "$DOCKERFILE_PATH" ]; then # No file found - echo "ERROR! failed to find Dockerfile at:[$DOCKERFILE_PATH]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to find Dockerfile at:[$DOCKERFILE_PATH]${NC}" echo "Please make sure you give full path!" echo "Example:[/configs/Dockerfile] or [Dockerfile] if at root directory" exit 1 @@ -314,11 +309,11 @@ BuildImage() ############################## if [ $ERROR_CODE -ne 0 ]; then # ERROR - echo "ERROR! failed to [build] Dockerfile!" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to [build] Dockerfile!${NC}" exit 1 else # SUCCESS - echo "Successfully Built image!" + echo -e "${NC}${F[B]}Successfully Built image!${NC}" fi ######################################################## @@ -338,18 +333,17 @@ BuildImage() ############################## if [ $ERROR_CODE -ne 0 ]; then # ERROR - echo "ERROR! failed to [tag] Dockerfile!" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to [tag] Dockerfile!${NC}" exit 1 else # SUCCESS - echo "Successfully tagged image!" + echo -e "${NC}${F[B]}Successfully tagged image!${NC}" fi fi } ################################################################################ #### Function UploadImage ###################################################### -UploadImage() -{ +UploadImage() { ################ # Print header # ################ @@ -374,11 +368,11 @@ UploadImage() ############################## if [ $ERROR_CODE -ne 0 ]; then # ERROR - echo "ERROR! failed to [upload] Dockerfile!" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to [upload] Dockerfile!${NC}" exit 1 else # SUCCESS - echo "Successfully Uploaded Docker image:[$IMAGE_VERSION] to $REGISTRY!" + echo -e "${NC}${F[B]}Successfully Uploaded Docker image:${F[W]}[$IMAGE_VERSION]${F[B]} to ${F[C]}$REGISTRY${F[B]}!${NC}" fi ######################### @@ -397,8 +391,8 @@ UploadImage() ############################## if [ $ERROR_CODE -ne 0 ]; then # ERROR - echo "ERROR! Failed to get information about built Image!" - echo "ERROR:[$GET_INFO_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get information about built Image!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$GET_INFO_CMD]${NC}" exit 1 else ################ @@ -440,18 +434,17 @@ UploadImage() ############################## if [ $ERROR_CODE -ne 0 ]; then # ERROR - echo "ERROR! failed to [upload] MAJOR_TAG:[$MAJOR_TAG] Dockerfile!" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} failed to [upload] MAJOR_TAG:[$MAJOR_TAG] Dockerfile!${NC}" exit 1 else # SUCCESS - echo "Successfully Uploaded TAGOR_TAG:[$MAJOR_TAG] Docker image to $REGISTRY!" + echo -e "${NC}${F[B]}Successfully Uploaded TAGOR_TAG:${F[W]}[$MAJOR_TAG]${F[B]} Docker image to ${F[C]}$REGISTRY${F[B]}!${NC}" fi fi } ################################################################################ #### Function Footer ########################################################### -Footer() -{ +Footer() { echo "" echo "-------------------------------------------------------" echo "The step has completed" @@ -480,14 +473,14 @@ BuildImage ###################### # Login to DockerHub # ###################### -if [[ "$REGISTRY" == "Docker" ]]; then +if [[ $REGISTRY == "Docker" ]]; then # Authenticate "Username" "Password" "Url" "Name" Authenticate "$DOCKER_USERNAME" "$DOCKER_PASSWORD" "" "Dockerhub" #################################### # Login to GitHub Package Registry # #################################### -elif [[ "$REGISTRY" == "GPR" ]]; then +elif [[ $REGISTRY == "GPR" ]]; then # Authenticate "Username" "Password" "Url" "Name" Authenticate "$GPR_USERNAME" "$GPR_TOKEN" "https://docker.pkg.github.com" "GitHub Package Registry" @@ -495,7 +488,7 @@ else ######### # ERROR # ######### - echo "ERROR! Registry not set correctly!" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Registry not set correctly!${NC}" echo "Registry:[$REGISTRY]" exit 1 fi diff --git a/.github/workflows/deploy-DEV.yml b/.github/workflows/deploy-DEV.yml index 0f55b010..2372e17b 100644 --- a/.github/workflows/deploy-DEV.yml +++ b/.github/workflows/deploy-DEV.yml @@ -31,6 +31,8 @@ jobs: name: Deploy Docker Image - DEV # Set the agent to run on runs-on: ubuntu-latest + # Prevent duplicate run from happening when a forked push is committed + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository ################## # Load all steps # ################## diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 00000000..cff0986d --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,61 @@ +--- +############################### +############################### +## StaleBot for Super-Linter ## +############################### +############################### +on: + schedule: + # every day at 0:00 UTC + - cron: "0 0 * * *" + issue_comment: + types: [created, deleted, edited] + +################### +# Name of the Job # +################### +name: "Stale[bot]" + +############### +# Run the job # +############### +jobs: + ####################### + # Mark an Issue Stale # + ####################### + markstale: + runs-on: ubuntu-latest + # only run on schedule + if: "github.event_name == 'schedule'" + steps: + - name: Mark issue stale + uses: actions/stale@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: "This issue has been automatically marked as stale because it has not had recent activity.\nIt will be closed in 14 days if no further activity occurs.\nThank you for your contributions.\n\nIf you think this issue should stay open, please remove the `O: stale 🤖` label or comment on the issue." + stale-pr-message: "This pull request has been automatically marked as stale because it has not had recent activity.\nIt will be closed in 14 days if no further activity occurs.\nThank you for your contributions.\n\nIf you think this pull request should stay open, please remove the `O: stale 🤖` label or comment on the pull request." + days-before-stale: 30 + days-before-close: 14 + stale-issue-label: "O: stale 🤖" + exempt-issue-label: "O: backlog 🤖" + stale-pr-label: "O: stale 🤖" + exempt-pr-label: "O: backlog 🤖" + + ################## + # Mark not stale # + ################## + marknotstale: + runs-on: ubuntu-latest + # do not run on schedule + if: "github.event_name == 'issue_comment' && contains(github.event.issue.labels.*.name, 'O: stale 🤖') && github.event.issue.user.type != 'Bot'" + steps: + - name: Mark issue not stale + uses: actions/github-script@v2 + with: + script: | + github.issues.removeLabel({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + name: 'O: stale 🤖' + }) diff --git a/README.md b/README.md index b77f9e2a..8bb7ecdf 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,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` @@ -96,8 +96,10 @@ name: Lint Code Base ############################# on: push: - branches-ignore: - - 'master' + branches-ignore: [master] + # Remove the line above to run when pushing to master + pull_request: + branches: [master] ############### # Set the Job # @@ -126,7 +128,8 @@ jobs: uses: docker://github/super-linter:v3 env: VALIDATE_ALL_CODEBASE: false - VALIDATE_ANSIBLE: false + DEFAULT_BRANCH: master + ... ``` diff --git a/TEMPLATES/.tflint.hcl b/TEMPLATES/.tflint.hcl index 5bc2209b..9a32d3aa 100644 --- a/TEMPLATES/.tflint.hcl +++ b/TEMPLATES/.tflint.hcl @@ -1,6 +1,6 @@ // https://github.com/terraform-linters/tflint/blob/master/docs/guides/config.md config { - module = true + module = false deep_check = false force = false 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/buildFileList.sh b/lib/buildFileList.sh index 550097f6..0bba876f 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -9,15 +9,14 @@ ################################################################################ ################################################################################ #### Function BuildFileList #################################################### -function BuildFileList() -{ +function BuildFileList() { # Need to build a list of all files changed # This can be pulled from the GITHUB_EVENT_PATH payload ################ # print header # ################ - if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then + if [[ $ACTIONS_RUNNER_DEBUG == "true" ]]; then echo "" echo "----------------------------------------------" echo "Pulling in code history and branches..." @@ -26,7 +25,10 @@ function BuildFileList() ################################################################################# # Switch codebase back to the default branch to get a list of all files changed # ################################################################################# - SWITCH_CMD=$(cd "$GITHUB_WORKSPACE" || exit; git pull --quiet; git checkout "$DEFAULT_BRANCH" 2>&1) + SWITCH_CMD=$( + git -C "$GITHUB_WORKSPACE" pull --quiet + git -C "$GITHUB_WORKSPACE" checkout "$DEFAULT_BRANCH" 2>&1 + ) ####################### # Load the error code # @@ -39,14 +41,14 @@ function BuildFileList() if [ $ERROR_CODE -ne 0 ]; then # Error echo "Failed to switch to $DEFAULT_BRANCH branch to get files changed!" - echo "ERROR:[$SWITCH_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$SWITCH_CMD]${NC}" exit 1 fi ################ # print header # ################ - if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then + if [[ $ACTIONS_RUNNER_DEBUG == "true" ]]; then echo "" echo "----------------------------------------------" echo "Generating Diff with:[git diff --name-only '$DEFAULT_BRANCH..$GITHUB_SHA' --diff-filter=d]" @@ -67,8 +69,8 @@ function BuildFileList() ############################## if [ $ERROR_CODE -ne 0 ]; then # Error - echo "ERROR! Failed to gain a list of all files changed!" - echo "ERROR:[${RAW_FILE_ARRAY[*]}]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to gain a list of all files changed!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${RAW_FILE_ARRAY[*]}]${NC}" exit 1 fi @@ -78,8 +80,7 @@ function BuildFileList() echo "" echo "----------------------------------------------" echo "Files that have been modified in the commit(s):" - for FILE in "${RAW_FILE_ARRAY[@]}" - do + for FILE in "${RAW_FILE_ARRAY[@]}"; do ############## # Print file # ############## @@ -100,11 +101,11 @@ function BuildFileList() ##################### # Get the CFN files # ##################### - if [ "$FILE_TYPE" == "json" ] || [ "$FILE_TYPE" == "yml" ] || [ "$FILE_TYPE" == "yaml" ] && DetectCloudFormationFile "$FILE"; then + if [ "$FILE_TYPE" == "yml" ] || [ "$FILE_TYPE" == "yaml" ]; then ################################ # Append the file to the array # ################################ - FILE_ARRAY_CFN+=("$FILE") + FILE_ARRAY_YML+=("$FILE") ########################################################## # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## @@ -118,11 +119,12 @@ function BuildFileList() # Append the file to the array # ################################ FILE_ARRAY_CFN+=("$FILE") + + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 fi - ########################################################## - # Set the READ_ONLY_CHANGE_FLAG since this could be exec # - ########################################################## - READ_ONLY_CHANGE_FLAG=1 ###################### # Get the JSON files # ###################### @@ -351,7 +353,7 @@ function BuildFileList() # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## READ_ONLY_CHANGE_FLAG=1 - elif [ "$FILE" == "Dockerfile" ]; then + elif [ "$FILE" == "dockerfile" ]; then ################################ # Append the file to the array # ################################ @@ -378,11 +380,11 @@ function BuildFileList() ################# # Check if bash # ################# - if [[ "$GET_FILE_TYPE_CMD" == *"Bourne-Again shell script"* ]]; then + if [[ $GET_FILE_TYPE_CMD == *"Bourne-Again shell script"* ]]; then ####################### # It is a bash script # ####################### - echo "WARN! Found bash script without extension:[.sh]" + echo -e "${NC}${F[Y]}WARN!${NC} Found bash script without extension:[.sh]${NC}" echo "Please update file with proper extensions." ################################ # Append the file to the array # @@ -392,11 +394,11 @@ function BuildFileList() # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## READ_ONLY_CHANGE_FLAG=1 - elif [[ "$GET_FILE_TYPE_CMD" == *"Ruby script"* ]]; then + elif [[ $GET_FILE_TYPE_CMD == *"Ruby script"* ]]; then ####################### # It is a Ruby script # ####################### - echo "WARN! Found ruby script without extension:[.rb]" + echo -e "${NC}${F[Y]}WARN!${NC} Found ruby script without extension:[.rb]${NC}" echo "Please update file with proper extensions." ################################ # Append the file to the array # @@ -410,7 +412,7 @@ function BuildFileList() ############################ # Extension was not found! # ############################ - echo " - WARN! Failed to get filetype for:[$FILE]!" + echo -e "${NC}${F[Y]} - WARN!${NC} Failed to get filetype for:[$FILE]!${NC}" ########################################################## # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## @@ -419,12 +421,12 @@ function BuildFileList() fi done - echo ${READ_ONLY_CHANGE_FLAG} > /dev/null 2>&1 || true # Workaround SC2034 + echo ${READ_ONLY_CHANGE_FLAG} > /dev/null 2>&1 || true # Workaround SC2034 ######################################### # Need to switch back to branch of code # ######################################### - SWITCH2_CMD=$(cd "$GITHUB_WORKSPACE" || exit; git checkout --progress --force "$GITHUB_SHA" 2>&1) + SWITCH2_CMD=$(git -C "$GITHUB_WORKSPACE" checkout --progress --force "$GITHUB_SHA" 2>&1) ####################### # Load the error code # @@ -437,7 +439,7 @@ function BuildFileList() if [ $ERROR_CODE -ne 0 ]; then # Error echo "Failed to switch back to branch!" - echo "ERROR:[$SWITCH2_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$SWITCH2_CMD]${NC}" exit 1 fi @@ -446,5 +448,5 @@ function BuildFileList() ################ echo "" echo "----------------------------------------------" - echo "Successfully gathered list of files..." + echo -e "${NC}${F[B]}Successfully gathered list of files...${NC}" } diff --git a/lib/linter.sh b/lib/linter.sh index a71ad512..b575192a 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -10,11 +10,13 @@ # Source Function Files # ######################### # shellcheck source=/dev/null -source /action/lib/buildFileList.sh # Source the function script(s) +source /action/lib/termColors.sh # Source the function script(s) # shellcheck source=/dev/null -source /action/lib/validation.sh # Source the function script(s) +source /action/lib/buildFileList.sh # Source the function script(s) # shellcheck source=/dev/null -source /action/lib/worker.sh # Source the function script(s) +source /action/lib/validation.sh # Source the function script(s) +# shellcheck source=/dev/null +source /action/lib/worker.sh # Source the function script(s) ########### # GLOBALS # @@ -99,138 +101,137 @@ LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'PHP' 'RUBY' 'PYTHON ################### # GitHub ENV Vars # ################### -GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit -GITHUB_EVENT_PATH="${GITHUB_EVENT_PATH}" # Github Event Path -GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace -DEFAULT_BRANCH="${DEFAULT_BRANCH:-master}" # Default Git Branch to use (master by default) -ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY}" # Ansible Directory -VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE}" # Boolean to validate all files -VALIDATE_YAML="${VALIDATE_YAML}" # Boolean to validate language -VALIDATE_JSON="${VALIDATE_JSON}" # Boolean to validate language -VALIDATE_XML="${VALIDATE_XML}" # Boolean to validate language -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_CLOUDFORMATION="${VALIDATE_CLOUDFORMATION}" # Boolean to validate language -VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language -VALIDATE_COFFEE="${VALIDATE_COFFEE}" # Boolean to validate language -VALIDATE_ANSIBLE="${VALIDATE_ANSIBLE}" # Boolean to validate language -VALIDATE_JAVASCRIPT_ES="${VALIDATE_JAVASCRIPT_ES}" # Boolean to validate language -VALIDATE_JAVASCRIPT_STANDARD="${VALIDATE_JAVASCRIPT_STANDARD}" # Boolean to validate language -VALIDATE_TYPESCRIPT_ES="${VALIDATE_TYPESCRIPT_ES}" # Boolean to validate language -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_CSS="${VALIDATE_CSS}" # Boolean to validate language -VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate language -VALIDATE_CLOJURE="${VALIDATE_CLOJURE}" # Boolean to validate language -VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language -VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language -VALIDATE_ARM="${VALIDATE_ARM}" # Boolean to validate language -VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language -VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # 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 +GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit +GITHUB_EVENT_PATH="${GITHUB_EVENT_PATH}" # Github Event Path +GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace +DEFAULT_BRANCH="${DEFAULT_BRANCH:-master}" # Default Git Branch to use (master by default) +ANSIBLE_DIRECTORY="${ANSIBLE_DIRECTORY}" # Ansible Directory +VALIDATE_ALL_CODEBASE="${VALIDATE_ALL_CODEBASE}" # Boolean to validate all files +VALIDATE_YAML="${VALIDATE_YAML}" # Boolean to validate language +VALIDATE_JSON="${VALIDATE_JSON}" # Boolean to validate language +VALIDATE_XML="${VALIDATE_XML}" # Boolean to validate language +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_CLOUDFORMATION="${VALIDATE_CLOUDFORMATION}" # Boolean to validate language +VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language +VALIDATE_COFFEE="${VALIDATE_COFFEE}" # Boolean to validate language +VALIDATE_ANSIBLE="${VALIDATE_ANSIBLE}" # Boolean to validate language +VALIDATE_JAVASCRIPT_ES="${VALIDATE_JAVASCRIPT_ES}" # Boolean to validate language +VALIDATE_JAVASCRIPT_STANDARD="${VALIDATE_JAVASCRIPT_STANDARD}" # Boolean to validate language +VALIDATE_TYPESCRIPT_ES="${VALIDATE_TYPESCRIPT_ES}" # Boolean to validate language +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_CSS="${VALIDATE_CSS}" # Boolean to validate language +VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate language +VALIDATE_CLOJURE="${VALIDATE_CLOJURE}" # Boolean to validate language +VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language +VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language +VALIDATE_ARM="${VALIDATE_ARM}" # Boolean to validate language +VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language +VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # 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 ############## # Debug Vars # ############## -RUN_LOCAL="${RUN_LOCAL}" # Boolean to see if we are running locally -ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG:-false}" # Boolean to see even more info (debug) +RUN_LOCAL="${RUN_LOCAL}" # Boolean to see if we are running locally +ACTIONS_RUNNER_DEBUG="${ACTIONS_RUNNER_DEBUG:-false}" # Boolean to see even more info (debug) ################ # 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_RUN_LOCAL='false' # Default value for debugging locally -DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases -DEFAULT_IFS="$IFS" # Get the Default IFS for updating +DEFAULT_VALIDATE_ALL_CODEBASE='true' # Default value for validate all files +DEFAULT_WORKSPACE="${DEFAULT_WORKSPACE:-/tmp/lint}" # Default workspace if running locally +DEFAULT_RUN_LOCAL='false' # Default value for debugging locally +DEFAULT_TEST_CASE_RUN='false' # Flag to tell code to run only test cases +DEFAULT_IFS="$IFS" # Get the Default IFS for updating ############################################################### # Default Vars that are called in Subs and need to be ignored # ############################################################### -DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors -echo "${DEFAULT_DISABLE_ERRORS}" > /dev/null 2>&1 || true # Workaround SC2034 -RAW_FILE_ARRAY=() # Array of all files that were changed -echo "${RAW_FILE_ARRAY[*]}" > /dev/null 2>&1 || true # Workaround SC2034 -READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md -echo "${READ_ONLY_CHANGE_FLAG}" > /dev/null 2>&1 || true # Workaround SC2034 -TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore -echo "${TEST_CASE_FOLDER}" > /dev/null 2>&1 || true # Workaround SC2034 -DEFAULT_ANSIBLE_DIRECTORY="$GITHUB_WORKSPACE/ansible" # Default Ansible Directory +DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors +echo "${DEFAULT_DISABLE_ERRORS}" > /dev/null 2>&1 || true # Workaround SC2034 +RAW_FILE_ARRAY=() # Array of all files that were changed +echo "${RAW_FILE_ARRAY[*]}" > /dev/null 2>&1 || true # Workaround SC2034 +READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md +echo "${READ_ONLY_CHANGE_FLAG}" > /dev/null 2>&1 || true # Workaround SC2034 +TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore +echo "${TEST_CASE_FOLDER}" > /dev/null 2>&1 || true # Workaround SC2034 +DEFAULT_ANSIBLE_DIRECTORY="$GITHUB_WORKSPACE/ansible" # Default Ansible Directory echo "${DEFAULT_ANSIBLE_DIRECTORY}" > /dev/null 2>&1 || true # Workaround SC2034 ########################## # Array of changed files # ########################## -FILE_ARRAY_YML=() # Array of files to check -FILE_ARRAY_JSON=() # Array of files to check -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_CFN=() # Array of files to check -FILE_ARRAY_COFFEESCRIPT=() # Array of files to check -FILE_ARRAY_JAVASCRIPT_ES=() # Array of files to check -FILE_ARRAY_JAVASCRIPT_STANDARD=() # Array of files to check -FILE_ARRAY_TYPESCRIPT_ES=() # Array of files to check -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_ARM=() # Array of files to check -FILE_ARRAY_CSS=() # Array of files to check -FILE_ARRAY_ENV=() # Array of files to check -FILE_ARRAY_CLOJURE=() # Array of files to check -FILE_ARRAY_KOTLIN=() # Array of files to check -FILE_ARRAY_PROTOBUF=() # Array of files to check -FILE_ARRAY_OPENAPI=() # Array of files to check +FILE_ARRAY_YML=() # Array of files to check +FILE_ARRAY_JSON=() # Array of files to check +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_CFN=() # Array of files to check +FILE_ARRAY_COFFEESCRIPT=() # Array of files to check +FILE_ARRAY_JAVASCRIPT_ES=() # Array of files to check +FILE_ARRAY_JAVASCRIPT_STANDARD=() # Array of files to check +FILE_ARRAY_TYPESCRIPT_ES=() # Array of files to check +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_ARM=() # Array of files to check +FILE_ARRAY_CSS=() # Array of files to check +FILE_ARRAY_ENV=() # Array of files to check +FILE_ARRAY_CLOJURE=() # Array of files to check +FILE_ARRAY_KOTLIN=() # Array of files to check +FILE_ARRAY_PROTOBUF=() # Array of files to check +FILE_ARRAY_OPENAPI=() # Array of files to check ############ # Counters # ############ -ERRORS_FOUND_YML=0 # Count of errors found -ERRORS_FOUND_JSON=0 # Count of errors found -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_CFN=0 # Count of errors found -ERRORS_FOUND_COFFEESCRIPT=0 # Count of errors found -ERRORS_FOUND_ANSIBLE=0 # Count of errors found -ERRORS_FOUND_JAVASCRIPT_STANDARD=0 # Count of errors found -ERRORS_FOUND_JAVASCRIPT_ES=0 # Count of errors found -ERRORS_FOUND_TYPESCRIPT_STANDARD=0 # Count of errors found -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_ARM=0 # Count of errors found -ERRORS_FOUND_CSS=0 # Count of errors found -ERRORS_FOUND_ENV=0 # Count of errors found -ERRORS_FOUND_CLOJURE=0 # Count of errors found -ERRORS_FOUND_KOTLIN=0 # Count of errors found -ERRORS_FOUND_PROTOBUF=0 # Count of errors found -ERRORS_FOUND_OPENAPI=0 # Count of errors found +ERRORS_FOUND_YML=0 # Count of errors found +ERRORS_FOUND_JSON=0 # Count of errors found +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_CFN=0 # Count of errors found +ERRORS_FOUND_COFFEESCRIPT=0 # Count of errors found +ERRORS_FOUND_ANSIBLE=0 # Count of errors found +ERRORS_FOUND_JAVASCRIPT_STANDARD=0 # Count of errors found +ERRORS_FOUND_JAVASCRIPT_ES=0 # Count of errors found +ERRORS_FOUND_TYPESCRIPT_STANDARD=0 # Count of errors found +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_ARM=0 # Count of errors found +ERRORS_FOUND_CSS=0 # Count of errors found +ERRORS_FOUND_ENV=0 # Count of errors found +ERRORS_FOUND_CLOJURE=0 # Count of errors found +ERRORS_FOUND_KOTLIN=0 # Count of errors found +ERRORS_FOUND_PROTOBUF=0 # Count of errors found +ERRORS_FOUND_OPENAPI=0 # Count of errors found ################################################################################ ########################## FUNCTIONS BELOW ##################################### ################################################################################ ################################################################################ #### Function Header ########################################################### -Header() -{ +Header() { ############################### # Give them the possum action # ############################### @@ -251,8 +252,7 @@ Header() } ################################################################################ #### Function GetLinterVersions ################################################ -GetLinterVersions() -{ +GetLinterVersions() { ######################### # Print version headers # ######################### @@ -263,8 +263,8 @@ GetLinterVersions() ########################################################## # Go through the array of linters and print version info # ########################################################## - for LINTER in "${LINTER_ARRAY[@]}" - do + for LINTER in "${LINTER_ARRAY[@]}"; do + echo "[$LINTER]:" ################### # Get the version # ################### @@ -287,7 +287,7 @@ GetLinterVersions() # Check the shell for errors # ############################## if [ $ERROR_CODE -ne 0 ] || [ -z "${GET_VERSION_CMD[*]}" ]; then - echo "[$LINTER]: WARN! Failed to get version info for:[$LINTER]" + echo -e "${NC}${F[Y]}WARN!${NC} Failed to get version info for:[$LINTER]${NC}" else ########################## # Print the version info # @@ -303,54 +303,43 @@ GetLinterVersions() } ################################################################################ #### Function GetLinterRules ################################################### -GetLinterRules() -{ +GetLinterRules() { # Need to validate the rules files exist ################ # Pull in vars # ################ - FILE_NAME="$1" # Name fo the linter file - FILE_LOCATION="$2" # Location of the linter file + LANGUAGE_NAME="$1" # Name of the language were looking for + + ####################################################### + # Need to create the variables for the real variables # + ####################################################### + LANGUAGE_FILE_NAME="${LANGUAGE_NAME}_FILE_NAME" + LANGUAGE_LINTER_RULES="${LANGUAGE_NAME}_LINTER_RULES" ##################################### # Validate we have the linter rules # ##################################### - if [ -f "$GITHUB_WORKSPACE/$LINTER_RULES_PATH/$FILE_NAME" ]; then + if [ -f "$GITHUB_WORKSPACE/$LINTER_RULES_PATH/${!LANGUAGE_FILE_NAME}" ]; then echo "----------------------------------------------" - echo "User provided file:[$FILE_NAME], setting rules file..." + echo "User provided file:[${!LANGUAGE_FILE_NAME}], setting rules file..." - #################################### - # Copy users into default location # - #################################### - CP_CMD=$(cp "$GITHUB_WORKSPACE/$LINTER_RULES_PATH/$FILE_NAME" "$FILE_LOCATION" 2>&1) - - ################### - # Load Error code # - ################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ $ERROR_CODE -ne 0 ]; then - echo "ERROR! Failed to set file:[$FILE_NAME] as default!" - echo "ERROR:[$CP_CMD]" - exit 1 - fi + ######################################## + # Update the path to the file location # + ######################################## + declare -g "${LANGUAGE_LINTER_RULES}=$GITHUB_WORKSPACE/$LINTER_RULES_PATH/${!LANGUAGE_FILE_NAME}" else ######################################################## # No user default provided, using the template default # ######################################################## - if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then - echo " -> Codebase does NOT have file:[$LINTER_RULES_PATH/$FILE_NAME], using Default rules at:[$FILE_LOCATION]" + if [[ $ACTIONS_RUNNER_DEBUG == "true" ]]; then + echo " -> Codebase does NOT have file:[$LINTER_RULES_PATH/${!LANGUAGE_FILE_NAME}], using Default rules at:[${!LANGUAGE_LINTER_RULES}]" fi fi } ################################################################################ #### Function GetStandardRules ################################################# -GetStandardRules() -{ +GetStandardRules() { ################ # Pull In Vars # ################ @@ -369,9 +358,9 @@ GetStandardRules() ######################################### # Only env vars that are marked as true GET_ENV_ARRAY=() - if [[ "$LINTER" == "javascript" ]]; then + if [[ $LINTER == "javascript" ]]; then mapfile -t GET_ENV_ARRAY < <(yq .env "$JAVASCRIPT_LINTER_RULES" | grep true) - elif [[ "$LINTER" == "typescript" ]]; then + elif [[ $LINTER == "typescript" ]]; then mapfile -t GET_ENV_ARRAY < <(yq .env "$TYPESCRIPT_LINTER_RULES" | grep true) fi @@ -385,8 +374,8 @@ GetStandardRules() ############################## if [ $ERROR_CODE -ne 0 ]; then # ERROR - echo "ERROR! Failed to gain list of ENV vars to load!" - echo "ERROR:[${GET_ENV_ARRAY[*]}]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to gain list of ENV vars to load!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GET_ENV_ARRAY[*]}]${NC}" exit 1 fi @@ -404,8 +393,7 @@ GetStandardRules() ############################# # Pull out the envs to load # ############################# - for ENV in "${GET_ENV_ARRAY[@]}" - do + for ENV in "${GET_ENV_ARRAY[@]}"; do ############################# # remove spaces from return # ############################# @@ -421,16 +409,15 @@ GetStandardRules() ######################################### # Remove trailing and ending whitespace # ######################################### - if [[ "$LINTER" == "javascript" ]]; then + if [[ $LINTER == "javascript" ]]; then JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" - elif [[ "$LINTER" == "typescript" ]]; then + elif [[ $LINTER == "typescript" ]]; then TYPESCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" fi } ################################################################################ #### Function DetectOpenAPIFile ################################################ -DetectOpenAPIFile() -{ +DetectOpenAPIFile() { ################ # Pull in vars # ################ @@ -439,7 +426,7 @@ DetectOpenAPIFile() ############################### # Check the file for keywords # ############################### - grep -E '"openapi":|"swagger":|^openapi:|^swagger:' "$GITHUB_WORKSPACE/$FILE" > /dev/null + grep -E '"openapi":|"swagger":|^openapi:|^swagger:' "$FILE" > /dev/null ####################### # Load the error code # @@ -453,12 +440,12 @@ DetectOpenAPIFile() ######################## # Found string in file # ######################## - return 0 + return 0 else ################### # No string match # ################### - return 1 + return 1 fi } ################################################################################ @@ -497,8 +484,7 @@ DetectARMFile() } ################################################################################ #### Function DetectCloudFormationFile ######################################### -DetectCloudFormationFile() -{ +DetectCloudFormationFile() { ################ # Pull in Vars # ################ @@ -527,7 +513,7 @@ DetectCloudFormationFile() ############################### if jq -e 'has("Resources")' > /dev/null 2>&1 < "$FILE"; then # Check if AWS Alexa or custom - if jq ".Resources[].Type" 2>/dev/null | grep -q -E "(AWS|Alexa|Custom)" < "$FILE"; then + if jq ".Resources[].Type" 2> /dev/null | grep -q -E "(AWS|Alexa|Custom)" < "$FILE"; then # Found it return 0 fi @@ -549,8 +535,7 @@ DetectCloudFormationFile() ################################################################################ #### Function GetGitHubVars #################################################### -GetGitHubVars() -{ +GetGitHubVars() { ########## # Prints # ########## @@ -590,7 +575,7 @@ GetGitHubVars() ################################# # Check if were running locally # ################################# - if [[ "$RUN_LOCAL" != "false" ]]; then + if [[ $RUN_LOCAL != "false" ]]; then ########################################## # We are running locally for a debug run # ########################################## @@ -611,7 +596,6 @@ GetGitHubVars() # No need to touch or set the GITHUB_ORG # No need to touch or set the GITHUB_REPO - ################################# # Set the VALIDATE_ALL_CODEBASE # ################################# @@ -621,33 +605,33 @@ GetGitHubVars() # Validate we have a value # ############################ if [ -z "$GITHUB_SHA" ]; then - echo "ERROR! Failed to get [GITHUB_SHA]!" - echo "ERROR:[$GITHUB_SHA]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_SHA]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$GITHUB_SHA]${NC}" exit 1 else - echo "Successfully found:[GITHUB_SHA], value:[$GITHUB_SHA]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_SHA]${F[B]}, value:${F[W]}[$GITHUB_SHA]${NC}" fi ############################ # Validate we have a value # ############################ if [ -z "$GITHUB_WORKSPACE" ]; then - echo "ERROR! Failed to get [GITHUB_WORKSPACE]!" - echo "ERROR:[$GITHUB_WORKSPACE]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_WORKSPACE]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$GITHUB_WORKSPACE]${NC}" exit 1 else - echo "Successfully found:[GITHUB_WORKSPACE], value:[$GITHUB_WORKSPACE]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[$GITHUB_WORKSPACE]${NC}" fi ############################ # Validate we have a value # ############################ if [ -z "$GITHUB_EVENT_PATH" ]; then - echo "ERROR! Failed to get [GITHUB_EVENT_PATH]!" - echo "ERROR:[$GITHUB_EVENT_PATH]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_EVENT_PATH]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$GITHUB_EVENT_PATH]${NC}" exit 1 else - echo "Successfully found:[GITHUB_EVENT_PATH], value:[$GITHUB_EVENT_PATH]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_EVENT_PATH]${F[B]}, value:${F[W]}[$GITHUB_EVENT_PATH]${F[B]}${NC}" fi ################################################## @@ -657,43 +641,42 @@ GetGitHubVars() ###################### # Get the GitHub Org # ###################### - GITHUB_ORG=$(jq -r '.repository.owner.login' < "$GITHUB_EVENT_PATH" ) + GITHUB_ORG=$(jq -r '.repository.owner.login' < "$GITHUB_EVENT_PATH") ############################ # Validate we have a value # ############################ if [ -z "$GITHUB_ORG" ]; then - echo "ERROR! Failed to get [GITHUB_ORG]!" - echo "ERROR:[$GITHUB_ORG]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_ORG]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$GITHUB_ORG]${NC}" exit 1 else - echo "Successfully found:[GITHUB_ORG], value:[$GITHUB_ORG]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_ORG]${F[B]}, value:${F[W]}[$GITHUB_ORG]${NC}" fi ####################### # Get the GitHub Repo # ####################### - GITHUB_REPO=$(jq -r '.repository.name' < "$GITHUB_EVENT_PATH" ) + GITHUB_REPO=$(jq -r '.repository.name' < "$GITHUB_EVENT_PATH") ############################ # Validate we have a value # ############################ if [ -z "$GITHUB_REPO" ]; then - echo "ERROR! Failed to get [GITHUB_REPO]!" - echo "ERROR:[$GITHUB_REPO]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_REPO]!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$GITHUB_REPO]${NC}" exit 1 else - echo "Successfully found:[GITHUB_REPO], value:[$GITHUB_REPO]" + echo -e "${NC}${F[B]}Successfully found:${F[W]}[GITHUB_REPO]${F[B]}, value:${F[W]}[$GITHUB_REPO]${NC}" fi fi } ################################################################################ #### Function ValidatePowershellModules ######################################## -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 + 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 @@ -703,7 +686,7 @@ function ValidatePowershellModules() ######################################### # validate we found the script analyzer # ######################################### - if [[ "$VALIDATE_PSSA_CMD" != "Invoke-ScriptAnalyzer" ]]; then + if [[ $VALIDATE_PSSA_CMD != "Invoke-ScriptAnalyzer" ]]; then # Failed to find module exit 1 fi @@ -718,21 +701,20 @@ function ValidatePowershellModules() ############################## if [ $ERROR_CODE -ne 0 ]; then # Failed - echo "ERROR! Failed find module [PSScriptAnalyzer] for [$LINTER_NAME] in system!" - echo "ERROR:[PSSA_MODULE $VALIDATE_PSSA_MODULE] [PSSA_CMD $VALIDATE_PSSA_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed find module [PSScriptAnalyzer] for [$LINTER_NAME] in system!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[PSSA_MODULE $VALIDATE_PSSA_MODULE] [PSSA_CMD $VALIDATE_PSSA_CMD]${NC}" 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" + if [[ $ACTIONS_RUNNER_DEBUG == "true" ]]; then + echo -e "${NC}${F[B]}Successfully found module ${F[W]}[$VALIDATE_PSSA_MODULE]${F[B]} in system${NC}" + echo -e "${NC}${F[B]}Successfully found command ${F[W]}[$VALIDATE_PSSA_CMD]${F[B]} in system${NC}" fi fi } ################################################################################ #### Function Footer ########################################################### -Footer() -{ +Footer() { echo "" echo "----------------------------------------------" echo "----------------------------------------------" @@ -744,8 +726,7 @@ Footer() ############################## # Prints for errors if found # ############################## - for LANGUAGE in "${LANGUAGE_ARRAY[@]}" - do + for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do ########################### # Build the error counter # ########################### @@ -756,7 +737,7 @@ Footer() ################## if [ "${!ERROR_COUNTER}" -ne 0 ]; then # Print the goods - echo "ERRORS FOUND in $LANGUAGE:[${!ERROR_COUNTER}]" + echo -e "${NC}${B[R]}${F[W]}ERRORS FOUND${NC} in $LANGUAGE:[${!ERROR_COUNTER}]${NC}" fi done @@ -764,47 +745,47 @@ Footer() # Exit with 0 if errors disabled # ################################## if [ "$DISABLE_ERRORS" == "true" ]; then - echo "WARN! Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[$DISABLE_ERRORS]" + echo -e "${NC}${F[Y]}WARN!${NC} Exiting with exit code:[0] as:[DISABLE_ERRORS] was set to:[$DISABLE_ERRORS]${NC}" exit 0 ############################### # Exit with 1 if errors found # ############################### - elif [ "$ERRORS_FOUND_YML" -ne 0 ] || \ - [ "$ERRORS_FOUND_JSON" -ne 0 ] || \ - [ "$ERRORS_FOUND_XML" -ne 0 ] || \ - [ "$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 ] || \ - [ "$ERRORS_FOUND_JAVASCRIPT_ES" -ne 0 ] || \ - [ "$ERRORS_FOUND_JAVASCRIPT_STANDARD" -ne 0 ] || \ - [ "$ERRORS_FOUND_TYPESCRIPT_ES" -ne 0 ] || \ - [ "$ERRORS_FOUND_TYPESCRIPT_STANDARD" -ne 0 ] || \ - [ "$ERRORS_FOUND_DOCKER" -ne 0 ] || \ - [ "$ERRORS_FOUND_GO" -ne 0 ] || \ - [ "$ERRORS_FOUND_TERRAFORM" -ne 0 ] || \ - [ "$ERRORS_FOUND_POWERSHELL" -ne 0 ] || \ - [ "$ERRORS_FOUND_ARM" -ne 0 ] || \ - [ "$ERRORS_FOUND_RUBY" -ne 0 ] || \ - [ "$ERRORS_FOUND_CSS" -ne 0 ] || \ - [ "$ERRORS_FOUND_CFN" -ne 0 ] || \ - [ "$ERRORS_FOUND_ENV" -ne 0 ] || \ - [ "$ERRORS_FOUND_OPENAPI" -ne 0 ] || \ - [ "$ERRORS_FOUND_PROTOBUF" -ne 0 ] || \ - [ "$ERRORS_FOUND_CLOJURE" -ne 0 ] || \ - [ "$ERRORS_FOUND_KOTLIN" -ne 0 ]; then + elif [ "$ERRORS_FOUND_YML" -ne 0 ] || + [ "$ERRORS_FOUND_JSON" -ne 0 ] || + [ "$ERRORS_FOUND_XML" -ne 0 ] || + [ "$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 ] || + [ "$ERRORS_FOUND_JAVASCRIPT_ES" -ne 0 ] || + [ "$ERRORS_FOUND_JAVASCRIPT_STANDARD" -ne 0 ] || + [ "$ERRORS_FOUND_TYPESCRIPT_ES" -ne 0 ] || + [ "$ERRORS_FOUND_TYPESCRIPT_STANDARD" -ne 0 ] || + [ "$ERRORS_FOUND_DOCKER" -ne 0 ] || + [ "$ERRORS_FOUND_GO" -ne 0 ] || + [ "$ERRORS_FOUND_TERRAFORM" -ne 0 ] || + [ "$ERRORS_FOUND_POWERSHELL" -ne 0 ] || + [ "$ERRORS_FOUND_ARM" -ne 0 ] || + [ "$ERRORS_FOUND_RUBY" -ne 0 ] || + [ "$ERRORS_FOUND_CSS" -ne 0 ] || + [ "$ERRORS_FOUND_CFN" -ne 0 ] || + [ "$ERRORS_FOUND_ENV" -ne 0 ] || + [ "$ERRORS_FOUND_OPENAPI" -ne 0 ] || + [ "$ERRORS_FOUND_PROTOBUF" -ne 0 ] || + [ "$ERRORS_FOUND_CLOJURE" -ne 0 ] || + [ "$ERRORS_FOUND_KOTLIN" -ne 0 ]; then # Failed exit - echo "Exiting with errors found!" + echo -e "${NC}${F[R]}Exiting with errors found!${NC}" exit 1 else ################# # Footer prints # ################# echo "" - echo "All file(s) linted successfully with no errors detected" + echo -e "${NC}${F[G]}All file(s) linted successfully with no errors detected${NC}" echo "----------------------------------------------" echo "" # Successful exit @@ -836,40 +817,40 @@ GetValidationInfo # Get the linter rules # ######################## # Get YML rules -GetLinterRules "$YAML_FILE_NAME" "$YAML_LINTER_RULES" +GetLinterRules "YAML" # Get Markdown rules -GetLinterRules "$MD_FILE_NAME" "$MD_LINTER_RULES" +GetLinterRules "MD" # Get Python rules -GetLinterRules "$PYTHON_FILE_NAME" "$PYTHON_LINTER_RULES" +GetLinterRules "PYTHON" # Get Ruby rules -GetLinterRules "$RUBY_FILE_NAME" "$RUBY_LINTER_RULES" +GetLinterRules "RUBY" # Get Coffeescript rules -GetLinterRules "$COFFEE_FILE_NAME" "$COFFEESCRIPT_LINTER_RULES" +GetLinterRules "COFFEESCRIPT" # Get Ansible rules -GetLinterRules "$ANSIBLE_FILE_NAME" "$ANSIBLE_LINTER_RULES" +GetLinterRules "ANSIBLE" # Get JavaScript rules -GetLinterRules "$JAVASCRIPT_FILE_NAME" "$JAVASCRIPT_LINTER_RULES" +GetLinterRules "JAVASCRIPT" # Get TypeScript rules -GetLinterRules "$TYPESCRIPT_FILE_NAME" "$TYPESCRIPT_LINTER_RULES" +GetLinterRules "TYPESCRIPT" # Get Golang rules -GetLinterRules "$GO_FILE_NAME" "$GO_LINTER_RULES" +GetLinterRules "GO" # Get Docker rules -GetLinterRules "$DOCKER_FILE_NAME" "$DOCKER_LINTER_RULES" +GetLinterRules "DOCKER" # Get Terraform rules -GetLinterRules "$TERRAFORM_FILE_NAME" "$TERRAFORM_LINTER_RULES" +GetLinterRules "TERRAFORM" # Get PowerShell rules -GetLinterRules "$POWERSHELL_FILE_NAME" "$POWERSHELL_LINTER_RULES" +GetLinterRules "POWERSHELL" # Get ARM rules -GetLinterRules "$ARM_FILE_NAME" "$ARM_LINTER_RULES" +GetLinterRules "ARM" # Get CSS rules -GetLinterRules "$CSS_FILE_NAME" "$CSS_LINTER_RULES" +GetLinterRules "CSS" # Get CFN rules -GetLinterRules "$CFN_FILE_NAME" "$CFN_LINTER_RULES" +GetLinterRules "CFN" ################################# # Check if were in verbose mode # ################################# -if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then +if [[ $ACTIONS_RUNNER_DEBUG == "true" ]]; then ################################## # Get and print all version info # ################################## @@ -879,7 +860,7 @@ fi ########################################### # Check to see if this is a test case run # ########################################### -if [[ "$TEST_CASE_RUN" != "false" ]]; then +if [[ $TEST_CASE_RUN != "false" ]]; then ########################### # Run only the test cases # ########################### @@ -949,7 +930,7 @@ if [ "$VALIDATE_BASH" == "true" ]; then # Lint the bash files # ####################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "BASH" "shellcheck" "shellcheck" ".*\.\(sh\)\$" "${FILE_ARRAY_BASH[@]}" + LintCodebase "BASH" "shellcheck" "shellcheck --color" ".*\.\(sh\)\$" "${FILE_ARRAY_BASH[@]}" fi ################## @@ -1050,7 +1031,7 @@ if [ "$VALIDATE_ANSIBLE" == "true" ]; then # Due to the nature of how we want to validate Ansible, we cannot use the # standard loop, since it looks for an ansible folder, excludes certain # files, and looks for additional changes, it should be an outlier - LintAnsibleFiles + LintAnsibleFiles "$ANSIBLE_LINTER_RULES" # Passing rules but not needed, dont want to exclude unused var fi ###################### @@ -1214,8 +1195,7 @@ if [ "$VALIDATE_OPENAPI" == "true" ]; then IFS=$'\n' mapfile -t LIST_FILES < <(find "$GITHUB_WORKSPACE" -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1) - for FILE in "${LIST_FILES[@]}" - do + for FILE in "${LIST_FILES[@]}"; do if DetectOpenAPIFile "$FILE"; then FILE_ARRAY_OPENAPI+=("$FILE") fi diff --git a/lib/possum.sh b/lib/possum.sh index dd87d952..d867332b 100755 --- a/lib/possum.sh +++ b/lib/possum.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -cat <&1) + LINT_CMD=$( + cd "$GITHUB_WORKSPACE" || exit + pwsh -NoProfile -NoLogo -Command "$LINTER_COMMAND $FILE; if (\$Error.Count) { exit 1 }" + exit $? 2>&1 + ) else ################################ # Lint the file with the rules # ################################ - LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1) + LINT_CMD=$( + cd "$GITHUB_WORKSPACE" || exit + $LINTER_COMMAND "$FILE" 2>&1 + ) fi ####################### @@ -189,32 +193,31 @@ function LintCodebase() ######### # Error # ######### - echo "ERROR! Found errors in [$LINTER_NAME] linter!" - echo "ERROR:[$LINT_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Found errors in [$LINTER_NAME] linter!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$LINT_CMD]${NC}" # Increment the error count (("ERRORS_FOUND_$FILE_TYPE++")) else ########### # Success # ########### - echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully" + echo -e "${NC}${F[B]} - File:${F[W]}[$FILE_NAME]${F[B]} was linted with ${F[W]}[$LINTER_NAME]${F[B]} successfully${NC}" fi done fi } ################################################################################ #### Function TestCodebase ##################################################### -function TestCodebase() -{ +function TestCodebase() { #################### # Pull in the vars # #################### - FILE_TYPE="$1" # Pull the variable and remove from array path (Example: JSON) - LINTER_NAME="$2" # Pull the variable and remove from array path (Example: jsonlint) - LINTER_COMMAND="$3" # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file) - FILE_EXTENSIONS="$4" # Pull the variable and remove from array path (Example: *.json) - INDVIDUAL_TEST_FOLDER="$5" # Folder for specific tests - TESTS_RAN=0 # Incremented when tests are ran, this will help find failed finds + FILE_TYPE="$1" # Pull the variable and remove from array path (Example: JSON) + LINTER_NAME="$2" # Pull the variable and remove from array path (Example: jsonlint) + LINTER_COMMAND="$3" # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file) + FILE_EXTENSIONS="$4" # Pull the variable and remove from array path (Example: *.json) + INDVIDUAL_TEST_FOLDER="$5" # Folder for specific tests + TESTS_RAN=0 # Incremented when tests are ran, this will help find failed finds ################ # print header # @@ -242,12 +245,12 @@ function TestCodebase() ############################## if [ $ERROR_CODE -ne 0 ]; then # Failed - echo "ERROR! Failed to find [$LINTER_NAME] in system!" - echo "ERROR:[$VALIDATE_INSTALL_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find [$LINTER_NAME] in system!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$VALIDATE_INSTALL_CMD]${NC}" exit 1 else # Success - echo "Successfully found binary in system" + echo -e "${NC}${F[B]}Successfully found binary in system${NC}" echo "Location:[$VALIDATE_INSTALL_CMD]" fi @@ -264,8 +267,7 @@ function TestCodebase() ################## # Lint the files # ################## - for FILE in "${LIST_FILES[@]}" - do + for FILE in "${LIST_FILES[@]}"; do ##################### # Get the file name # ##################### @@ -275,12 +277,12 @@ function TestCodebase() # Get the file pass status # ############################ # Example: markdown_good_1.md -> good - FILE_STATUS=$(echo "$FILE_NAME" |cut -f2 -d'_') + FILE_STATUS=$(echo "$FILE_NAME" | cut -f2 -d'_') ######################################################### # If not found, assume it should be linted successfully # ######################################################### - if [ -z "$FILE_STATUS" ] || [[ "$FILE" == *"README"* ]]; then + if [ -z "$FILE_STATUS" ] || [[ $FILE == *"README"* ]]; then ################################## # Set to good for proper linting # ################################## @@ -301,8 +303,8 @@ function TestCodebase() ####################################### # Check if docker and get folder name # ####################################### - if [[ "$FILE_TYPE" == "DOCKER" ]]; then - if [[ "$FILE" == *"good"* ]]; then + if [[ $FILE_TYPE == "DOCKER" ]]; then + if [[ $FILE == *"good"* ]]; then ############# # Good file # ############# @@ -318,7 +320,7 @@ function TestCodebase() ##################### # Check for ansible # ##################### - if [[ "$FILE_TYPE" == "ANSIBLE" ]]; then + if [[ $FILE_TYPE == "ANSIBLE" ]]; then ######################################## # Make sure we dont lint certain files # ######################################## @@ -330,18 +332,28 @@ function TestCodebase() ################################ # Lint the file with the rules # ################################ - LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER/$INDVIDUAL_TEST_FOLDER" || exit; $LINTER_COMMAND "$FILE" 2>&1) - elif [[ "$FILE_TYPE" == "POWERSHELL" ]]; then + LINT_CMD=$( + cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER/$INDVIDUAL_TEST_FOLDER" || exit + $LINTER_COMMAND "$FILE" 2>&1 + ) + elif [[ $FILE_TYPE == "POWERSHELL" ]]; then ################################ # Lint the file with the rules # ################################ # 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) + LINT_CMD=$( + cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit + pwsh -c "($LINTER_COMMAND $FILE)" + exit $? 2>&1 + ) else ################################ # Lint the file with the rules # ################################ - LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE" 2>&1) + LINT_CMD=$( + cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit + $LINTER_COMMAND "$FILE" 2>&1 + ) fi ####################### @@ -352,7 +364,7 @@ function TestCodebase() ######################################## # Check for if it was supposed to pass # ######################################## - if [[ "$FILE_STATUS" == "good" ]]; then + if [[ $FILE_STATUS == "good" ]]; then ############################## # Check the shell for errors # ############################## @@ -360,9 +372,9 @@ function TestCodebase() ######### # Error # ######### - echo "ERROR! Found errors in [$LINTER_NAME] linter!" - echo "ERROR:[$LINT_CMD]" - echo "ERROR: Linter CMD:[$LINTER_COMMAND $FILE]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Found errors in [$LINTER_NAME] linter!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$LINT_CMD]${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC} Linter CMD:[$LINTER_COMMAND $FILE]${NC}" # Increment the error count (("ERRORS_FOUND_$FILE_TYPE++")) # Increment counter that check was ran @@ -371,7 +383,7 @@ function TestCodebase() ########### # Success # ########### - echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully" + echo -e "${NC}${F[B]} - File:${F[W]}[$FILE_NAME]${F[B]} was linted with ${F[W]}[$LINTER_NAME]${F[B]} successfully${NC}" # Increment counter that check was ran ((TESTS_RAN++)) fi @@ -386,10 +398,10 @@ function TestCodebase() ######### # Error # ######### - echo "ERROR! Found errors in [$LINTER_NAME] linter!" - echo "ERROR! This file should have failed test case!" - echo "ERROR:[$LINT_CMD]" - echo "ERROR: Linter CMD:[$LINTER_COMMAND $FILE]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Found errors in [$LINTER_NAME] linter!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} This file should have failed test case!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$LINT_CMD]${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC} Linter CMD:[$LINTER_COMMAND $FILE]${NC}" # Increment the error count (("ERRORS_FOUND_$FILE_TYPE++")) # Increment counter that check was ran @@ -398,7 +410,7 @@ function TestCodebase() ########### # Success # ########### - echo " - File:[$FILE_NAME] failed test case with [$LINTER_NAME] successfully" + echo -e "${NC}${F[B]} - File:${F[W]}[$FILE_NAME]${F[B]} failed test case with ${F[W]}[$LINTER_NAME]${F[B]} successfully${NC}" # Increment counter that check was ran ((TESTS_RAN++)) fi @@ -412,15 +424,14 @@ function TestCodebase() ################################################# # We failed to find files and no tests were ran # ################################################# - echo "ERROR! Failed to find any tests ran for the Linter:[$LINTER_NAME]"! + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find any tests ran for the Linter:[$LINTER_NAME]${NC}"! echo "Please validate logic or that tests exist!" exit 1 fi } ################################################################################ #### Function RunTestCases ##################################################### -function RunTestCases() -{ +function RunTestCases() { # This loop will run the test cases and exclude user code # This is called from the automation process to validate new code # When a PR is opened, the new code is validated with the default branch @@ -446,7 +457,7 @@ function RunTestCases() TestCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "json" TestCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "xml" TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c $MD_LINTER_RULES" ".*\.\(md\)\$" "markdown" - TestCodebase "BASH" "shellcheck" "shellcheck" ".*\.\(sh\)\$" "shell" + TestCodebase "BASH" "shellcheck" "shellcheck --color" ".*\.\(sh\)\$" "shell" TestCodebase "PYTHON" "pylint" "pylint --rcfile $PYTHON_LINTER_RULES" ".*\.\(py\)\$" "python" TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "perl" TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "php" @@ -479,8 +490,7 @@ function RunTestCases() } ################################################################################ #### Function LintAnsibleFiles ################################################# -function LintAnsibleFiles() -{ +function LintAnsibleFiles() { ###################### # Create Print Array # ###################### @@ -516,14 +526,14 @@ function LintAnsibleFiles() ############################## if [ $ERROR_CODE -ne 0 ]; then # Failed - echo "ERROR! Failed to find $LINTER_NAME in system!" - echo "ERROR:[$VALIDATE_INSTALL_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to find $LINTER_NAME in system!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$VALIDATE_INSTALL_CMD]${NC}" exit 1 else # Success - if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then + if [[ $ACTIONS_RUNNER_DEBUG == "true" ]]; then # Success - echo "Successfully found binary in system" + echo -e "${NC}${F[B]}Successfully found binary in system${NC}" echo "Location:[$VALIDATE_INSTALL_CMD]" fi fi @@ -571,8 +581,7 @@ function LintAnsibleFiles() # Check if we have data to look at # #################################### if [ $SKIP_FLAG -eq 0 ]; then - for LINE in "${PRINT_ARRAY[@]}" - do + for LINE in "${PRINT_ARRAY[@]}"; do ######################### # Print the header line # ######################### @@ -583,8 +592,7 @@ function LintAnsibleFiles() ################## # Lint the files # ################## - for FILE in "${LIST_FILES[@]}" - do + for FILE in "${LIST_FILES[@]}"; do ######################################## # Make sure we dont lint certain files # @@ -622,26 +630,26 @@ function LintAnsibleFiles() ######### # Error # ######### - echo "ERROR! Found errors in [$LINTER_NAME] linter!" - echo "ERROR:[$LINT_CMD]" + echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Found errors in [$LINTER_NAME] linter!${NC}" + echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[$LINT_CMD]${NC}" # Increment error count ((ERRORS_FOUND_ANSIBLE++)) else ########### # Success # ########### - echo " - File:[$FILE_NAME] was linted with [$LINTER_NAME] successfully" + echo -e "${NC}${F[B]} - File:${F[W]}[$FILE_NAME]${F[B]} was linted with ${F[W]}[$LINTER_NAME]${F[B]} successfully${NC}" fi done else # No ansible directory found in path ############################### # Check to see if debug is on # ############################### - if [[ "$ACTIONS_RUNNER_DEBUG" == "true" ]]; then + if [[ $ACTIONS_RUNNER_DEBUG == "true" ]]; then ######################## # No Ansible dir found # ######################## - echo "WARN! No Ansible base directory found at:[$ANSIBLE_DIRECTORY]" + echo -e "${NC}${F[Y]}WARN!${NC} No Ansible base directory found at:[$ANSIBLE_DIRECTORY]${NC}" echo "skipping ansible lint" fi fi