From 312c91ed92ec6a3582f39d2af8961a4f534970c0 Mon Sep 17 00:00:00 2001 From: jeanjerome Date: Tue, 29 Aug 2023 00:06:23 +0200 Subject: [PATCH] ref(15): Start testing wild integration with Jenkins --- src/lib/log.sh | 50 ++++++++++++++++++++-------------------- src/lib/workflow.sh | 56 ++++++++++++++++++++++----------------------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/lib/log.sh b/src/lib/log.sh index f13f558..971ceae 100644 --- a/src/lib/log.sh +++ b/src/lib/log.sh @@ -44,7 +44,7 @@ declare -r LOG_LEVEL_FATAL_COLOR="\e[0;35m" #@desc Constant that stores log level color off definition. declare -r LOG_COLOR_OFF="\e[0m" -log::_prerequisite() { +log__prerequisite() { local status=0 if [ -z "$LOG_PATH" ]; then @@ -59,7 +59,7 @@ log::_prerequisite() { } #@desc Log a message. -#@ex log::_log \"$LOG_LEVEL_DEBUG\" \"This is a debug message\" \"$LOG_LEVEL_DEBUG_COLOR\" \"$LOG_COLOR_OFF\" +#@ex log__log \"$LOG_LEVEL_DEBUG\" \"This is a debug message\" \"$LOG_LEVEL_DEBUG_COLOR\" \"$LOG_COLOR_OFF\" #@const LOG_LEVEL (read-only) #@const LOG_LEVELS (read-only) #@const LOG_LEVEL_DEBUG_COLOR (read-only) @@ -68,13 +68,13 @@ log::_prerequisite() { #@arg color: color to use for the message #@arg color_off: color to use to turn off the color #@sdtout Redirects and writes the message to stderr and file log/stdout.log -log::_log() { +log__log() { local level=$1 local message=$2 local color=$3 local color_off=$4 - if ! log::_prerequisite; then + if ! log__prerequisite; then return 2 fi @@ -85,7 +85,7 @@ log::_log() { #@desc Log a banner message. -#@ex log::_banner \"This is a banner message\" \"$LOG_LEVEL_INFO_COLOR\" \"$LOG_COLOR_OFF\" +#@ex log__banner \"This is a banner message\" \"$LOG_LEVEL_INFO_COLOR\" \"$LOG_COLOR_OFF\" #@const LOG_LEVEL_INFO (read-only) #@const LOG_LEVEL_INFO_COLOR (read-only) #@const LOG_COLOR_OFF (read-only) @@ -93,12 +93,12 @@ log::_log() { #@arg color: color to use for the message #@arg color_off: color to use to turn off the color #@stdout Writes the banner message to stdout -log::_banner() { +log__banner() { local message=$1 local color=$2 local color_off=$3 - if ! log::_prerequisite; then + if ! log__prerequisite; then return 2 fi @@ -109,77 +109,77 @@ log::_banner() { #@desc Log a debug message. -#@ex log::debug \"This is a debug message\" +#@ex log_debug \"This is a debug message\" #@const LOG_LEVEL_DEBUG (read-only) #@const LOG_LEVEL_DEBUG_COLOR (read-only) #@const LOG_COLOR_OFF (read-only) #@arg message: message to log #@stdout Writes the debug message to stdout -log::debug() { +log_debug() { local function_name [ -v FUNCNAME ] && [ "${#FUNCNAME[@]}" -gt 1 ] && \ function_name="${FUNCNAME[1]}" || \ function_name="unknown function" - log::_log "$LOG_LEVEL_DEBUG" "[${function_name}] $1" "$LOG_LEVEL_DEBUG_COLOR" "$LOG_COLOR_OFF" + log__log "$LOG_LEVEL_DEBUG" "[${function_name}] $1" "$LOG_LEVEL_DEBUG_COLOR" "$LOG_COLOR_OFF" } #@desc Log an info message. -#@ex log::info \"This is an info message\" +#@ex log_info \"This is an info message\" #@const LOG_LEVEL_INFO (read-only) #@const LOG_LEVEL_INFO_COLOR (read-only) #@const LOG_COLOR_OFF (read-only) #@arg message: message to log #@stdout Writes the info message to stdout -log::info() { - log::_log "$LOG_LEVEL_INFO" "$1" "$LOG_LEVEL_INFO_COLOR" "$LOG_COLOR_OFF" +log_info() { + log__log "$LOG_LEVEL_INFO" "$1" "$LOG_LEVEL_INFO_COLOR" "$LOG_COLOR_OFF" } #@desc Log a warning message. -#@ex log::warn \"This is a warning message\" +#@ex log_warn \"This is a warning message\" #@const LOG_LEVEL_WARN (read-only) #@const LOG_LEVEL_WARN_COLOR (read-only) #@const LOG_COLOR_OFF (read-only) #@arg message: message to log #@stdout Writes the warning message to stdout -log::warn() { - log::_log "$LOG_LEVEL_WARN" "$1" "$LOG_LEVEL_WARN_COLOR" "$LOG_COLOR_OFF" +log_warn() { + log__log "$LOG_LEVEL_WARN" "$1" "$LOG_LEVEL_WARN_COLOR" "$LOG_COLOR_OFF" } #@desc Log an error message. -#@ex log::error \"This is an error message\" +#@ex log_error \"This is an error message\" #@const LOG_LEVEL_ERROR (read-only) #@const LOG_LEVEL_ERROR_COLOR (read-only) #@const LOG_COLOR_OFF (read-only) #@arg message: message to log #@stdout Writes the error message to stdout -log::error() { - log::_log "$LOG_LEVEL_ERROR" "$1" "$LOG_LEVEL_ERROR_COLOR" "$LOG_COLOR_OFF" >&2 +log_error() { + log__log "$LOG_LEVEL_ERROR" "$1" "$LOG_LEVEL_ERROR_COLOR" "$LOG_COLOR_OFF" >&2 } #@desc Log a fatal message. -#@ex log::fatal \"This is a fatal message\" +#@ex log_fatal \"This is a fatal message\" #@const LOG_LEVEL_FATAL (read-only) #@const LOG_LEVEL_FATAL_COLOR (read-only) #@const LOG_COLOR_OFF (read-only) #@arg message: message to log #@stdout Writes the fatal message to stdout -log::fatal() { - log::_log "$LOG_LEVEL_FATAL" "$1" "$LOG_LEVEL_FATAL_COLOR" "$LOG_COLOR_OFF" >&2 +log_fatal() { + log__log "$LOG_LEVEL_FATAL" "$1" "$LOG_LEVEL_FATAL_COLOR" "$LOG_COLOR_OFF" >&2 } #@desc Log a banner message. -#@ex log::banner \"This is a banner message\" +#@ex log_banner \"This is a banner message\" #@const LOG_LEVEL_INFO_COLOR (read-only) #@const LOG_COLOR_OFF (read-only) #@arg message: message to log #@stdout Writes the banner message to stdout -log::banner() { - log::_banner "$*" "$LOG_LEVEL_INFO_COLOR" "$LOG_COLOR_OFF" +log_banner() { + log__banner "$*" "$LOG_LEVEL_INFO_COLOR" "$LOG_COLOR_OFF" } diff --git a/src/lib/workflow.sh b/src/lib/workflow.sh index 575e75a..aee9d0c 100644 --- a/src/lib/workflow.sh +++ b/src/lib/workflow.sh @@ -28,11 +28,11 @@ workflow_check_prerequisites () { fi log::debug "WILD_CWD is ${WILD_CWD}" - log::debug "jq command is ${JQ}" + log_debug "jq command is ${JQ}" } #@desc Check if the workflow definition file exists. -#@ex workflow::check_workflow_definition_path +#@ex workflow_check_workflow_definition_path #@arg workflow_definition_path: path to the workflow definition file #@stderr Writes the fatal message to stdout if the workflow definition file does not exist and exit 255 #@stdout Writes the info message to stdout if the workflow definition file exists @@ -40,24 +40,24 @@ workflow_check_prerequisites () { workflow_check_workflow_definition_path() { local path="${1:-}" - log::debug "Check workflow definition path" + log_debug "Check workflow definition path" if [ -z "${path}" ]; then - log::info "No workflow definition path provided, using default one" + log_info "No workflow definition path provided, using default one" path="config/workflow-default.json" fi if [ ! -f "${WILD_CWD}/${path}" ]; then - log::fatal "Workflow definition file in ${path} does not exist" + log_fatal "Workflow definition file in ${path} does not exist" exit 1 fi - log::info "Load workflow definition from ${path}" + log_info "Load workflow definition from ${path}" echo "$path" } #@desc Get containers' names from a JSON workflow definition. -#@ex workflow::workflow_get_workflows_containers_names \"config/workflow-default.json\" +#@ex workflow_workflow_get_workflows_containers_names \"config/workflow-default.json\" #@const JQ (read-only) #@const workflow_definition_path (read-only) #@stdout Writes debug messages to stdout @@ -71,17 +71,17 @@ workflow_get_workflows_containers_names() { done < <("$JQ" -r '.actions[].container' "${workflow_definition_path}") # shellcheck disable=SC2145 - #if log::is_debug... - log::debug "Workflow has ${#containers_names[@]} container(s):" + #if log_is_debug... + log_debug "Workflow has ${#containers_names[@]} container(s):" for container_name in "${containers_names[@]}"; do - log::debug "- Container name '${container_name}'" + log_debug "- Container name '${container_name}'" done echo "${containers_names[@]}" } #@desc Load step definition from an item and the workflow definition file. -#@ex workflow::load_step_definition \"step1\" \"config/workflow-default.json\" +#@ex workflow_load_step_definition \"step1\" \"config/workflow-default.json\" #@const JQ (read-only) #@const workflow_definition_path (read-only) #@arg item_id: id of the item to load @@ -97,13 +97,13 @@ workflow_load_workflow_definition() { step_definition=($("$JQ" <"${WILD_CWD}/${workflow_definition_path}" -rc ".actions[] | select(.id == \"${item_id}\")")) # shellcheck disable=SC2145 - log::debug "Step definition is: ${step_definition[@]}" + log_debug "Step definition is: ${step_definition[@]}" echo "${step_definition[@]}" } #@desc Load step values as environment variables from a step definition as JSON. -#@ex workflow::load_step_values \"[\"id\":\"step1\",\"name\":\"Step 1\",\"description\":\"Step 1 description\",\"type\":\"command\",\"command\":\"echo 'Step 1'\"]\" +#@ex workflow_load_step_values \"[\"id\":\"step1\",\"name\":\"Step 1\",\"description\":\"Step 1 description\",\"type\":\"command\",\"command\":\"echo 'Step 1'\"]\" #@const JQ (read-only) #@arg step_definition: step definition to load #@stdout Writes debug messages to stdout @@ -114,13 +114,13 @@ workflow_load_step_values() { # shellcheck disable=SC2128 disable=SC2086 initializer=$("$JQ" -r <<<$step_definition 'to_entries[] | "\(.key)=\(.value)"' | tr -d \") - log::debug "Step values are: $initializer" + log_debug "Step values are: $initializer" eval "$initializer" } #@desc Iterate over workflow. -#@ex workflow::iterate_over_workflow \"config/workflow-default.json\" \"action1 action2 action3\" +#@ex workflow_iterate_over_workflow \"config/workflow-default.json\" \"action1 action2 action3\" #@const workflow_definition_path (read-only) #@arg workflow_definition_path: path to the workflow definition file #@arg workflows_id: array of workflows id @@ -130,40 +130,40 @@ workflow_iterate_over_workflow() { local workflows_id=("$@") for item in "${workflows_id[@]}"; do - log::info "Loop over step $item" + log_info "Loop over step $item" local step_definition # shellcheck disable=SC2207 - step_definition=($(workflow::load_workflow_definition "$item" "$workflow_definition_path")) + step_definition=($(workflow_load_workflow_definition "$item" "$workflow_definition_path")) # shellcheck disable=SC2128 disable=SC2145 - log::debug "Step definition is ${step_definition[@]}" + log_debug "Step definition is ${step_definition[@]}" - workflow::load_step_values "${step_definition[@]}" + workflow_load_step_values "${step_definition[@]}" done } #@desc Load workflow definition from a file. -#@ex workflow::load \"config/workflow-default.json\" +#@ex workflow_load \"config/workflow-default.json\" #@const JQ (read-only) #@arg workflow_definition_path: path to the workflow definition file #@stdout Writes the workflow definition details to stdout -#workflow::load() { +#workflow_load() { # local workflow_definition_path="${1:-}" # -# workflow_definition_path=$(workflow::check_workflow_definition_path "$workflow_definition_path") -# workflow::check_prerequisites +# workflow_definition_path=$(workflow_check_workflow_definition_path "$workflow_definition_path") +# workflow_check_prerequisites # # local workflows_id=() # # shellcheck disable=SC2207 -# workflows_id+=($(workflow::get_workflows_id "$workflow_definition_path")) +# workflows_id+=($(workflow_get_workflows_id "$workflow_definition_path")) # # # shellcheck disable=SC2145 -# log::debug "Caller Workflows id are: ${workflows_id[@]}" -# log::debug "Length Workflows id are: ${#workflows_id[@]}" +# log_debug "Caller Workflows id are: ${workflows_id[@]}" +# log_debug "Length Workflows id are: ${#workflows_id[@]}" # -# workflow::iterate_over_workflow "$workflow_definition_path" "${workflows_id[@]}" +# workflow_iterate_over_workflow "$workflow_definition_path" "${workflows_id[@]}" #} # Call the load function with the specified workflow definition path -# workflow::load "config/workflow-default.json" +# workflow_load "config/workflow-default.json"