Simplify multi status checks (#4958)

This commit is contained in:
Marco Ferrari 2023-12-14 21:22:49 +01:00 committed by GitHub
parent b9d7d8d9ab
commit e6e6e1fa5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -384,6 +384,7 @@ LINTED_LANGUAGES_ARRAY=() # Will be filled at run time with all languages that w
# GitHub ENV Vars # # GitHub ENV Vars #
################### ###################
MULTI_STATUS="${MULTI_STATUS:-true}" # Multiple status are created for each check ran MULTI_STATUS="${MULTI_STATUS:-true}" # Multiple status are created for each check ran
MULTI_STATUS="${MULTI_STATUS,,}" # Convert string to lowercase
DEFAULT_BRANCH="${DEFAULT_BRANCH:-master}" # Default Git Branch to use (master by default) DEFAULT_BRANCH="${DEFAULT_BRANCH:-master}" # Default Git Branch to use (master by default)
IGNORE_GITIGNORED_FILES="${IGNORE_GITIGNORED_FILES:-false}" IGNORE_GITIGNORED_FILES="${IGNORE_GITIGNORED_FILES:-false}"
debug "IGNORE_GITIGNORED_FILES: ${IGNORE_GITIGNORED_FILES}" debug "IGNORE_GITIGNORED_FILES: ${IGNORE_GITIGNORED_FILES}"
@ -491,7 +492,8 @@ GetGitHubVars() {
pushd "${GITHUB_WORKSPACE}" >/dev/null || exit 1 pushd "${GITHUB_WORKSPACE}" >/dev/null || exit 1
VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}" VALIDATE_ALL_CODEBASE="${DEFAULT_VALIDATE_ALL_CODEBASE}"
info "Linting all files in mapped directory: ${GITHUB_WORKSPACE}. Setting VALIDATE_ALL_CODEBASE to: ${VALIDATE_ALL_CODEBASE}" info "Linting all files in mapped directory: ${GITHUB_WORKSPACE}"
debug "Setting VALIDATE_ALL_CODEBASE to ${VALIDATE_ALL_CODEBASE} because we are not running on GitHub Actions"
if [[ "${USE_FIND_ALGORITHM}" == "false" ]]; then if [[ "${USE_FIND_ALGORITHM}" == "false" ]]; then
ConfigureGitSafeDirectories ConfigureGitSafeDirectories
@ -506,6 +508,9 @@ GetGitHubVars() {
else else
debug "Skip the initalization of GITHUB_SHA because we don't need it" debug "Skip the initalization of GITHUB_SHA because we don't need it"
fi fi
MULTI_STATUS="false"
debug "Setting MULTI_STATUS to ${MULTI_STATUS} because we are not running on GitHub Actions"
else else
if [ -z "${GITHUB_WORKSPACE}" ]; then if [ -z "${GITHUB_WORKSPACE}" ]; then
error "Failed to get [GITHUB_WORKSPACE]!" error "Failed to get [GITHUB_WORKSPACE]!"
@ -580,34 +585,20 @@ GetGitHubVars() {
fi fi
fi fi
############################ if [ "${MULTI_STATUS}" == "true" ]; then
# Validate we have a value #
############################
if [ "${MULTI_STATUS}" == "true" ] && [ -z "${GITHUB_TOKEN}" ] && [[ ${RUN_LOCAL} == "false" ]]; then
error "Failed to get [GITHUB_TOKEN]!"
error "[${GITHUB_TOKEN}]"
error "Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!"
################################################################################ if [[ ${RUN_LOCAL} == "true" ]]; then
# Need to set MULTI_STATUS to false as we cant hit API endpoints without token # # Safety check. This shouldn't occur because we forcefully set MULTI_STATUS=false above
################################################################################ # when RUN_LOCAL=true
MULTI_STATUS='false' fatal "Cannot enable status reports when running locally."
else
info "Successfully found:${F[W]}[GITHUB_TOKEN]"
fi fi
############################### if [ -z "${GITHUB_TOKEN}" ]; then
# Convert string to lowercase # fatal "Failed to get [GITHUB_TOKEN]. Terminating because status reports were explicitly enabled, but GITHUB_TOKEN was not provided."
############################### else
MULTI_STATUS="${MULTI_STATUS,,}" info "Successfully found:${F[W]}[GITHUB_TOKEN]."
fi
#######################################################################
# Check to see if the multi status is set, and we have a token to use #
#######################################################################
if [ "${MULTI_STATUS}" == "true" ] && [ -n "${GITHUB_TOKEN}" ]; then
############################
# Validate we have a value #
############################
if [ -z "${GITHUB_REPOSITORY}" ]; then if [ -z "${GITHUB_REPOSITORY}" ]; then
error "Failed to get [GITHUB_REPOSITORY]!" error "Failed to get [GITHUB_REPOSITORY]!"
fatal "[${GITHUB_REPOSITORY}]" fatal "[${GITHUB_REPOSITORY}]"
@ -615,15 +606,14 @@ GetGitHubVars() {
info "Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]" info "Successfully found:${F[W]}[GITHUB_REPOSITORY]${F[B]}, value:${F[W]}[${GITHUB_REPOSITORY}]"
fi fi
############################
# Validate we have a value #
############################
if [ -z "${GITHUB_RUN_ID}" ]; then if [ -z "${GITHUB_RUN_ID}" ]; then
error "Failed to get [GITHUB_RUN_ID]!" error "Failed to get [GITHUB_RUN_ID]!"
fatal "[${GITHUB_RUN_ID}]" fatal "[${GITHUB_RUN_ID}]"
else else
info "Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]" info "Successfully found:${F[W]}[GITHUB_RUN_ID]${F[B]}, value:${F[W]}[${GITHUB_RUN_ID}]"
fi fi
else
debug "Skip GITHUB_TOKEN, GITHUB_REPOSITORY, and GITHUB_RUN_ID validation because we don't need these variables for GitHub Actions status reports. MULTI_STATUS: ${MULTI_STATUS}"
fi fi
} }
################################################################################ ################################################################################