diff --git a/.automation/clean-code-base-for-tests.sh b/.automation/clean-code-base-for-tests.sh index c7c00494..966f798c 100755 --- a/.automation/clean-code-base-for-tests.sh +++ b/.automation/clean-code-base-for-tests.sh @@ -7,10 +7,12 @@ ########### # Globals # ########### -GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace -GITHUB_SHA="${GITHUB_SHA}" # Sha used to create this branch -TEST_FOLDER='.automation/test' # Folder where test are stored -CLEAN_FOLDER='.automation/automation' # Folder to rename to prevent skip +GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace +GITHUB_SHA="${GITHUB_SHA}" # Sha used to create this branch +TEST_FOLDER='.automation/test' # Folder where test are stored +CLEAN_FOLDER='.automation/automation' # Folder to rename to prevent skip +(( LOG_TRACE=LOG_DEBUG=LOG_VERBOSE=LOG_NOTICE=LOG_WARN=LOG_ERROR="true" )) # Enable all loging +export LOG_TRACE LOG_DEBUG LOG_VERBOSE LOG_NOTICE LOG_WARN LOG_ERROR ############################ # Source additonal scripts # diff --git a/.automation/cleanup-docker.sh b/.automation/cleanup-docker.sh index 35e28878..d7c3080b 100755 --- a/.automation/cleanup-docker.sh +++ b/.automation/cleanup-docker.sh @@ -16,12 +16,14 @@ ########### # 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 +(( LOG_TRACE=LOG_DEBUG=LOG_VERBOSE=LOG_NOTICE=LOG_WARN=LOG_ERROR="true" )) # Enable all loging +export LOG_TRACE LOG_DEBUG LOG_VERBOSE LOG_NOTICE LOG_WARN LOG_ERROR ######################### # Source Function Files # diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index e1836836..8f14a92c 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -38,9 +38,11 @@ CONTAINER_URL='' # Final URL to upload ########################################################### # Dynamic build variables to pass to container when built # ########################################################### -BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') # Current build date EX> "2017-08-28T09:24:41Z" -BUILD_REVISION=$(git rev-parse --short HEAD) # Current git commit EX> "e89faa7" -BUILD_VERSION='' # Current version of the container being built +BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') # Current build date EX> "2017-08-28T09:24:41Z" +BUILD_REVISION=$(git rev-parse --short HEAD) # Current git commit EX> "e89faa7" +BUILD_VERSION='' # Current version of the container being built +(( LOG_TRACE=LOG_DEBUG=LOG_VERBOSE=LOG_NOTICE=LOG_WARN=LOG_ERROR="true" )) # Enable all loging +export LOG_TRACE LOG_DEBUG LOG_VERBOSE LOG_NOTICE LOG_WARN LOG_ERROR ######################### # Source Function Files # diff --git a/.automation/validate-docker-labels.sh b/.automation/validate-docker-labels.sh index cee8d4bd..100b9812 100755 --- a/.automation/validate-docker-labels.sh +++ b/.automation/validate-docker-labels.sh @@ -7,13 +7,15 @@ ########### # Globals # ########### -GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace -GITHUB_SHA="${GITHUB_SHA}" # Sha used to create this branch -BUILD_DATE="${BUILD_DATE}" # Date the container was built -BUILD_REVISION="${GITHUB_SHA}" # GitHub Sha -BUILD_VERSION="${GITHUB_SHA}" # Version of the container -ORG_REPO="github/super-linter" # Org/repo -ERROR=0 # Error count +GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace +GITHUB_SHA="${GITHUB_SHA}" # Sha used to create this branch +BUILD_DATE="${BUILD_DATE}" # Date the container was built +BUILD_REVISION="${GITHUB_SHA}" # GitHub Sha +BUILD_VERSION="${GITHUB_SHA}" # Version of the container +ORG_REPO="github/super-linter" # Org/repo +(( LOG_TRACE=LOG_DEBUG=LOG_VERBOSE=LOG_NOTICE=LOG_WARN=LOG_ERROR="true" )) # Enable all loging +ERROR=0 # Error count +export LOG_TRACE LOG_DEBUG LOG_VERBOSE LOG_NOTICE LOG_WARN LOG_ERROR ######################### # Source Function Files # @@ -73,6 +75,11 @@ Footer() { ################################## MAIN ######################################## ################################################################################ +########## +# Header # +########## +Header + #################### # Validate created # #################### diff --git a/Dockerfile b/Dockerfile index 08b3f8fd..689f3331 100644 --- a/Dockerfile +++ b/Dockerfile @@ -342,6 +342,11 @@ COPY TEMPLATES /action/lib/.automation ################################### RUN /action/lib/linterVersions.sh +##################################4 +# Run validations of built image # +################################## +RUN /action/lib/validate-docker.sh + ###################### # Set the entrypoint # ###################### diff --git a/lib/linter.sh b/lib/linter.sh index 5d159412..8e63b3bc 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1139,7 +1139,6 @@ REPORT_OUTPUT_FOLDER="${GITHUB_WORKSPACE}/${OUTPUT_FOLDER}" # Location for # Validate the environment # ############################ GetValidationInfo -ValidatePowershellModules ######################## # Get the linter rules # diff --git a/lib/linterVersions.sh b/lib/linterVersions.sh index 9046895c..010b10c2 100755 --- a/lib/linterVersions.sh +++ b/lib/linterVersions.sh @@ -6,6 +6,12 @@ ################################################################################ ################################################################################ +########### +# Globals # +########### +(( LOG_TRACE=LOG_DEBUG=LOG_VERBOSE=LOG_NOTICE=LOG_WARN=LOG_ERROR="true" )) # Enable all loging +export LOG_TRACE LOG_DEBUG LOG_VERBOSE LOG_NOTICE LOG_WARN LOG_ERROR + ######################### # Source Function Files # ######################### @@ -79,8 +85,8 @@ BuildLinterVersions() { # Check the shell for errors # ############################## if [ ${ERROR_CODE} -ne 0 ] || [ -z "${GET_VERSION_CMD[*]}" ]; then - warn "[${LINTER}]: Failed to get version info for:" WriteFile "${LINTER}" "Failed to get version info" + fatal "[${LINTER}]: Failed to get version info for:" else ########################## # Print the version info # diff --git a/lib/validate-docker.sh b/lib/validate-docker.sh new file mode 100755 index 00000000..6e9da08e --- /dev/null +++ b/lib/validate-docker.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash + +############################################################################# +############# Validate build docker image for possible extra errors ######### +############################################################################# + +########### +# Globals # +########### +(( LOG_TRACE=LOG_DEBUG=LOG_VERBOSE=LOG_NOTICE=LOG_WARN=LOG_ERROR="true" )) # Enable all loging +ERROR=0 # Error count + +export LOG_TRACE LOG_DEBUG LOG_VERBOSE LOG_NOTICE LOG_WARN LOG_ERROR + +######################### +# Source Function Files # +######################### +# shellcheck source=/dev/null +source /action/lib/log.sh + +################################################################################ +############################ FUNCTIONS BELOW ################################### +################################################################################ +################################################################################ +#### Function Header ########################################################### +Header() { + info "---------------------------------------" + info "----- Post-build validate docker ------" + info "---------------------------------------" +} +################################################################################ +#### Function ValidatePowershellModules ######################################## +function ValidatePowershellModules() { + VALIDATE_PSSA_MODULE=$(pwsh -c "(Get-Module -Name PSScriptAnalyzer -ListAvailable | Select-Object -First 1).Name" 2>&1) + VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1) + # If module found, ensure Invoke-ScriptAnalyzer command is available + if [[ ${VALIDATE_PSSA_MODULE} == "PSScriptAnalyzer" ]] && [[ ${VALIDATE_PSSA_CMD} == "Invoke-ScriptAnalyzer" ]]; then + # Success + debug "Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system" + debug "Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system" + else + # Failed + ERROR=1 + error "Failed find module [PSScriptAnalyzer] in system!" + error "[PSSA_MODULE: ${VALIDATE_PSSA_MODULE}] [PSSA_CMD: ${VALIDATE_PSSA_CMD}]" + fi +} +################################################################################ +#### Function ValidateLabel #################################################### +ValidateLibs() { + ValidatePowershellModules +} +################################################################################ +#### Function Footer ########################################################### +Footer() { + ##################################### + # Check if any errors were reported # + ##################################### + if [[ ${ERROR} -gt 0 ]]; then + fatal "There were some failed assertions. See above" + else + info "-------------------------------------------------------" + info "The step has completed" + info "-------------------------------------------------------" + fi +} +################################################################################ +################################## MAIN ######################################## +################################################################################ + +########## +# Header # +########## +Header + +################# +# Validate libs # +################# +ValidateLibs + +################# +# Report status # +################# +Footer diff --git a/lib/validation.sh b/lib/validation.sh index f5bcdf50..1f0e04b0 100755 --- a/lib/validation.sh +++ b/lib/validation.sh @@ -206,40 +206,3 @@ function GetValidationInfo() { debug "${PRINTENV}" debug "---------------------------------------------" } -################################################################################ -#### 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 - fatal "Failed to find module." - fi - - ######################################### - # validate we found the script analyzer # - ######################################### - if [[ ${VALIDATE_PSSA_CMD} != "Invoke-ScriptAnalyzer" ]]; then - fatal "Failed to find module." - fi - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ ${ERROR_CODE} -ne 0 ]; then - # Failed - error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!" - fatal "[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]" - else - # Success - debug "Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system" - debug "Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system" - fi -} -################################################################################