mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-29 04:01:02 -05:00
Merge pull request #929 from GaboFDC/gf_better_validate_pwshmodule
Better pwsh module validation
This commit is contained in:
commit
97e9df68dc
9 changed files with 129 additions and 59 deletions
|
@ -11,6 +11,8 @@ 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 #
|
||||
|
|
|
@ -22,6 +22,8 @@ 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 #
|
||||
|
|
|
@ -41,6 +41,8 @@ CONTAINER_URL='' # Final URL to upload
|
|||
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 #
|
||||
|
|
|
@ -13,7 +13,9 @@ 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 #
|
||||
####################
|
||||
|
|
|
@ -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 #
|
||||
######################
|
||||
|
|
|
@ -1139,7 +1139,6 @@ REPORT_OUTPUT_FOLDER="${GITHUB_WORKSPACE}/${OUTPUT_FOLDER}" # Location for
|
|||
# Validate the environment #
|
||||
############################
|
||||
GetValidationInfo
|
||||
ValidatePowershellModules
|
||||
|
||||
########################
|
||||
# Get the linter rules #
|
||||
|
|
|
@ -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 #
|
||||
|
|
84
lib/validate-docker.sh
Executable file
84
lib/validate-docker.sh
Executable file
|
@ -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
|
|
@ -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
|
||||
}
|
||||
################################################################################
|
||||
|
|
Loading…
Reference in a new issue