Skip to content

Commit

Permalink
ref(15): Start testing wild integration with Jenkins
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanjerome committed Aug 28, 2023
1 parent 8d328af commit 312c91e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
50 changes: 25 additions & 25 deletions src/lib/log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -85,20 +85,20 @@ 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)
#@arg message: message to 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

Expand All @@ -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"
}
56 changes: 28 additions & 28 deletions src/lib/workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,36 @@ 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
#@return workflow_definition_path: path to the workflow definition file
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"

0 comments on commit 312c91e

Please sign in to comment.