Merge pull request #929 from GaboFDC/gf_better_validate_pwshmodule

Better pwsh module validation
This commit is contained in:
Lukas Gravley 2020-11-02 08:11:45 -06:00 committed by GitHub
commit 97e9df68dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 129 additions and 59 deletions

View file

@ -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 #

View file

@ -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 #

View file

@ -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 #

View file

@ -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 #
####################

View file

@ -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 #
######################

View file

@ -1139,7 +1139,6 @@ REPORT_OUTPUT_FOLDER="${GITHUB_WORKSPACE}/${OUTPUT_FOLDER}" # Location for
# Validate the environment #
############################
GetValidationInfo
ValidatePowershellModules
########################
# Get the linter rules #

View file

@ -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
View 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

View file

@ -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
}
################################################################################