diff --git a/Jenkinsfile b/Jenkinsfile index 15b116a..f716695 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,4 @@ -library identifier: "wild@15-test-wild-on-jenkins", retriever: modernSCM( +library identifier: "wild@17-add-more-configurations-on-workflow-pipeline", retriever: modernSCM( [$class: 'GitSCMSource', remote: 'https://github.com/scalastic/wild.git', credentialsId: 'wild-github-token']) _ diff --git a/README.md b/README.md index d915253..7f9f2f3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -![Wild](docs/images/wild.png) +![Wizard](docs/images/wizard.png) [![License](https://img.shields.io/github/license/scalastic/wild.svg?style=flat-square)](https://github.com/scalastic/wild/blob/master/LICENSE) [![bash](https://img.shields.io/badge/bash-4.4%2B-brightgreen)](https://www.gnu.org/software/bash/) @@ -9,15 +9,15 @@ [![GitHub stars](https://img.shields.io/github/stars/scalastic/wild?style=social)](https://img.shields.io/github/stars/scalastic/wild?style=social) [![GitHub forks](https://img.shields.io/github/forks/scalastic/wild?style=social)](https://img.shields.io/github/forks/scalastic/wild?style=social) -# Wide Integration with Lightweight Delivery +# Wizard - The Magical Integration Framework -`Wild` is a framework that allows you to run the same integration scripts locally and on the server. It is designed to be used by developers and CI/CD platforms. +Welcome to Wizard, a versatile and magical framework that empowers you to effortlessly execute uniform integration scripts both locally and on your server. It caters to the needs of both developers and CI/CD platforms, weaving a touch of magic into your workflow. -`Wild` stands for **Wide Integration with Lightweight Delivery**. Due to its ***Wild*** nature, it fills the gap between the developer and the CI/CD platform by allowing to run the exact same integration and deployment scripts locally and on the server. +The acronym `WIZARD` represents its essence: **Wide Integration Zone And Runner Deployment**. Thanks to its unconventional and almost mystical nature, `Wizard` bridges the gap between developers and CI/CD platforms, enabling the seamless execution of identical integration and deployment scripts, whether on your local machine or the server. -Developers can test the operation of the CI/CD chain on their local station and no longer have to wait and wonder what will happen once their code is pushed on the integration servers. +With `Wizard`, developers gain the magical ability to thoroughly test their CI/CD pipeline's functionality directly on their local workstations, eliminating the need to speculate about the outcomes once their code is pushed to the integration servers. -`Wild` fills the missing link of the DevOps approach and its *shift-left* principal herein. +Embrace the enchantment of Wizard to fill the void in the DevOps approach and embody the "shift-left" principle with a sprinkle of magic. ---- @@ -28,7 +28,7 @@ Developers can test the operation of the CI/CD chain on their local station and - [Requirements](#requirements) - [Installation](#installation) - [Tutorial](#tutorial) -- [Wild CLI](#wild-cli) +- [Wizard CLI](#wizard-cli) - [Command options](#command-options) - [Project directory](#project-directory) - [Typical directory structure](#typical-directory-structure) @@ -39,21 +39,23 @@ Developers can test the operation of the CI/CD chain on their local station and ## Supported platforms -Actualy `Wild` is designed to be used on the following platforms: +## Compatible Platforms -- Local +Currently, `Wizard` is tailored for seamless use on the following platforms: + +- Your local environment (Unix-based systems) - Jenkins - GitLab-CI -## Supported technologies and extensibility +Please note that our magical integration framework may expand its compatibility with more platforms in the future. Stay tuned for updates! -## Requirements +## Prerequisites -To use `Wild` on your local station you need: +In order to utilize `Wizard` on your local machine, the following prerequisites must be met: -- [Bash](https://www.gnu.org/software/bash/) 4.4 or higher -- [Git](https://git-scm.com/) 2.0 or higher -- [Docker](https://www.docker.com/) 19.03 or higher +- [Bash](https://www.gnu.org/software/bash/) version 4.4 or newer +- [Git](https://git-scm.com/) version 2.0 or higher +- [Docker](https://www.docker.com/) version 19.03 or later ## Installation @@ -61,7 +63,7 @@ To use `Wild` on your local station you need: ```bash brew tap scalastic/tap -brew install wild +brew install wizard ``` ### Install with Git @@ -72,12 +74,12 @@ git clone ## Tutorial -## Wild CLI +## Wizard CLI ### Usage ```bash -wild [options] [command] +wizard [options] [command] ``` ### Command options diff --git a/config/json-schema/workflow-schema.json b/config/json-schema/workflow-schema.json index 0323bae..0b14476 100644 --- a/config/json-schema/workflow-schema.json +++ b/config/json-schema/workflow-schema.json @@ -49,9 +49,29 @@ "description": "Container where to execute the action", "type": "string" }, + "pre_script": { + "description": "The Bash script filename defining the pre-action", + "type": "string" + }, "script": { "description": "The Bash script filename defining the action", "type": "string" + }, + "post_script": { + "description": "The Bash script filename defining the post-action", + "type": "string" + }, + "condition": { + "description": "Condition to execute this action", + "type": "string" + }, + "resume": { + "description": "Resume this action at the end", + "type": "boolean" + }, + "log_level": { + "description": "The log level to log", + "type": "string" } }, "required": ["id", "name", "container", "script"] diff --git a/config/workflow-default.json b/config/workflow-default.json index adb0200..2249c3e 100644 --- a/config/workflow-default.json +++ b/config/workflow-default.json @@ -7,7 +7,10 @@ "id": "action1", "name": "Action 1", "container": "bash", - "script": "test/action/bash-version.sh" + "pre_script": "test/action/bash-version.sh", + "script": "test/action/bash-version.sh", + "post_script": "test/action/bash-version.sh", + "log_level": "DEBUG" }, { "id": "action2", diff --git a/contrib/make_doc.sh b/contrib/make_doc.sh index 593db40..07db161 100755 --- a/contrib/make_doc.sh +++ b/contrib/make_doc.sh @@ -8,6 +8,7 @@ rm -rf docs/src mkdir -p docs/src export LOG_PATH="./log" +export LOG_LEVEL="1" # shellcheck disable=SC2046 disable=SC2038 ./src/lib/ext/gendoc.sh $(find src/lib -path src/lib/ext -prune -o -name '*.sh' -print | xargs echo) diff --git a/docs/src/lib/common.md b/docs/src/lib/common.md index 005a8bc..bb95253 100644 --- a/docs/src/lib/common.md +++ b/docs/src/lib/common.md @@ -3,4 +3,4 @@ Common functions used in stage scripts --------------------------------------- -*Generated from [src/lib/common.sh](../../../src/lib/common.sh) on 11.08.2023 (writen with ✨ by [gendoc](../../../src/lib/ext/gendoc.sh))* +*Generated from [src/lib/common.sh](../../../src/lib/common.sh) on 08.09.2023 (writen with ✨ by [gendoc](../../../src/lib/ext/gendoc.sh))* diff --git a/docs/src/lib/ext/gendoc.md b/docs/src/lib/ext/gendoc.md deleted file mode 100644 index 90ca2ff..0000000 --- a/docs/src/lib/ext/gendoc.md +++ /dev/null @@ -1,150 +0,0 @@ -# LIBRARY `./src/lib/ext/gendoc.sh` - -This script is used to generate documentation for bash scripts used in Wild. - -## GLOBAL VARIABLES - -### ``MARKER_COMMENT_START`` - -* *Constant that marks the start of a comment line.* - -### ``MARKER_VARIABLE_DEFINITION`` - -* *Constant that marks a variable definition.* - -### ``MARKER_FUNCTION_DEFINITION`` - -* *Constant that marks a function definition.* - -### ``MARKER_FUNCTION_PRIVATE`` - -* *Constant that marks a private function definition.* - -### ``MARKER_BLOCK_END`` - -* *Constant that marks the end of a block.* - -### ``ANNOTATION_DESCRIPTION`` - -* *Constant that defines a desciption annotation.* - -### ``ANNOTATION_CONSTANT`` - -* *Constant that defines a constant annotation.* - -### ``ANNOTATION_ARGUMENT`` - -* *Constant that defines an argument annotation.* - -### ``ANNOTATION_EXAMPLE`` - -* *Constant that defines an example annotation.* - -### ``ANNOTATION_STDOUT`` - -* *Constant that defines a stdout annotation.* - -### ``ANNOTATION_RETURN`` - -* *Constant that defines a return annotation.* - -### ``LABEL_LIBRARY`` - -* *Constant that defines the library label.* - -### ``LABEL_CONSTANT`` - -* *Constant that defines the constant label.* - -### ``LABEL_FUNCTION`` - -* *Constant that defines the function label.* - -### ``buffer`` - -* ** - -## FUNCTIONS - -### `doc::_buffer_reset 🚫 (private)` - -* Reset the buffer. - -### `doc::_buffer_write 🚫 (private)` - -* Write a value to the buffer by key. - -* Argument - - 1. `$1 The key to write.`: $1 The key to write. - - 1. `$2 The value to write.`: $2 The value to write. - -### `doc::buffer_read ✅ (public)` - -* Read a value from the buffer by key. - -* Argument - - 1. `$1 The key to read.`: $1 The key to read. - -* Return Code - - * `return`: The value of the key. - -### `doc::buffer_print ✅ (public)` - -* Print the buffer as key, value pairs. - -* Output - - * `stdout`: The buffer content - -### `doc::startswith ✅ (public)` - -* Check if a line starts with a pattern. - -* Argument - - 1. `$1 The line to check.`: $1 The line to check. - - 1. `$2 The pattern to check.`: $2 The pattern to check. - -* Return Code - - * `return`: 0 if the line starts with the pattern - - * `return`: 1 otherwise. - -### `doc::contains ✅ (public)` - -* Check if a line contains a pattern. - -* Argument - - 1. `$1 The line to check.`: $1 The line to check. - - 1. `$2 The pattern to check.`: $2 The pattern to check. - -* Return Code - - * `return`: 0 if the line contains the pattern - - * `return`: 1 otherwise. - -### `doc::_write_constant 🚫 (private)` - -* Writes the constant part of the documentation. - -* Output - - * `stdout`: The constant part of the documentation. - -### `doc::_write_multiple_annotation 🚫 (private)` - -### `doc::_write_function 🚫 (private)` - -### `doc::main ✅ (public)` - ---------------------------------------- -*Generated from [./src/lib/ext/gendoc.sh](../../../../src/lib/ext/gendoc.sh) on 11.08.2023 (writen with ✨ by [gendoc](../../../../src/lib/ext/gendoc.sh))* diff --git a/docs/src/lib/log.md b/docs/src/lib/log.md index f5039fc..591a905 100644 --- a/docs/src/lib/log.md +++ b/docs/src/lib/log.md @@ -58,9 +58,9 @@ Logger functions for bash scripts ## FUNCTIONS -### `log::_prerequisite 🚫 (private)` +### `log__prerequisite 🚫 (private)` -### `log::_log 🚫 (private)` +### `log__log 🚫 (private)` * Log a message. @@ -77,10 +77,10 @@ Logger functions for bash scripts * Example ```bash -log::_log "$LOG_LEVEL_DEBUG" "This is a debug message" "$LOG_LEVEL_DEBUG_COLOR" "$LOG_COLOR_OFF" +log__log "$LOG_LEVEL_DEBUG" "This is a debug message" "$LOG_LEVEL_DEBUG_COLOR" "$LOG_COLOR_OFF" ``` -### `log::_banner 🚫 (private)` +### `log__banner 🚫 (private)` * Log a banner message. @@ -95,14 +95,14 @@ log::_log "$LOG_LEVEL_DEBUG" "This is a debug message" "$LOG_LEVEL_DEBUG_COLOR" * Example ```bash -log::_banner "This is a banner message" "$LOG_LEVEL_INFO_COLOR" "$LOG_COLOR_OFF" +log__banner "This is a banner message" "$LOG_LEVEL_INFO_COLOR" "$LOG_COLOR_OFF" ``` * Output * `stdout`: Writes the banner message to stdout -### `log::debug ✅ (public)` +### `log_debug ✅ (public)` * Log a debug message. @@ -113,14 +113,14 @@ log::_banner "This is a banner message" "$LOG_LEVEL_INFO_COLOR" "$LOG_COLOR_OFF" * Example ```bash -log::debug "This is a debug message" +log_debug "This is a debug message" ``` * Output * `stdout`: Writes the debug message to stdout -### `log::info ✅ (public)` +### `log_info ✅ (public)` * Log an info message. @@ -131,14 +131,14 @@ log::debug "This is a debug message" * Example ```bash -log::info "This is an info message" +log_info "This is an info message" ``` * Output * `stdout`: Writes the info message to stdout -### `log::warn ✅ (public)` +### `log_warn ✅ (public)` * Log a warning message. @@ -149,14 +149,14 @@ log::info "This is an info message" * Example ```bash -log::warn "This is a warning message" +log_warn "This is a warning message" ``` * Output * `stdout`: Writes the warning message to stdout -### `log::error ✅ (public)` +### `log_error ✅ (public)` * Log an error message. @@ -167,14 +167,14 @@ log::warn "This is a warning message" * Example ```bash -log::error "This is an error message" +log_error "This is an error message" ``` * Output * `stdout`: Writes the error message to stdout -### `log::fatal ✅ (public)` +### `log_fatal ✅ (public)` * Log a fatal message. @@ -185,14 +185,14 @@ log::error "This is an error message" * Example ```bash -log::fatal "This is a fatal message" +log_fatal "This is a fatal message" ``` * Output * `stdout`: Writes the fatal message to stdout -### `log::banner ✅ (public)` +### `log_banner ✅ (public)` * Log a banner message. @@ -203,7 +203,7 @@ log::fatal "This is a fatal message" * Example ```bash -log::banner "This is a banner message" +log_banner "This is a banner message" ``` * Output @@ -211,4 +211,4 @@ log::banner "This is a banner message" * `stdout`: Writes the banner message to stdout --------------------------------------- -*Generated from [src/lib/log.sh](../../../src/lib/log.sh) on 11.08.2023 (writen with ✨ by [gendoc](../../../src/lib/ext/gendoc.sh))* +*Generated from [src/lib/log.sh](../../../src/lib/log.sh) on 08.09.2023 (writen with ✨ by [gendoc](../../../src/lib/ext/gendoc.sh))* diff --git a/docs/src/lib/platform.md b/docs/src/lib/platform.md index be6de9a..a82a178 100644 --- a/docs/src/lib/platform.md +++ b/docs/src/lib/platform.md @@ -18,14 +18,14 @@ Platform functions for bash scripts ## FUNCTIONS -### `platform::_is_jenkins 🚫 (private)` +### `platform__is_jenkins 🚫 (private)` * Test if the script is running on jenkins. * Example ```bash -platform::_is_jenkins +platform__is_jenkins ``` * Return Code @@ -34,14 +34,14 @@ platform::_is_jenkins * `return`: false otherwise -### `platform::_is_gitlab 🚫 (private)` +### `platform__is_gitlab 🚫 (private)` * Test if the script is running on gitlab. * Example ```bash -project::_is_local +project__is_local ``` * Return Code @@ -50,14 +50,14 @@ project::_is_local * `return`: false otherwise -### `platform::_is_local 🚫 (private)` +### `platform__is_local 🚫 (private)` * Test if the script is running locally. * Example ```bash -project::_is_local +project__is_local ``` * Return Code @@ -66,14 +66,16 @@ project::_is_local * `return`: false otherwise -### `platform::get_platform ✅ (public)` +### `platform_is_macos ✅ (public)` + +### `platform_get_platform ✅ (public)` * Get the platform where the script is running. * Example ```bash -platform::get_platform +platform_get_platform ``` * Output @@ -81,4 +83,4 @@ platform::get_platform * `stdout`: The platform where the script is running --------------------------------------- -*Generated from [src/lib/platform.sh](../../../src/lib/platform.sh) on 11.08.2023 (writen with ✨ by [gendoc](../../../src/lib/ext/gendoc.sh))* +*Generated from [src/lib/platform.sh](../../../src/lib/platform.sh) on 08.09.2023 (writen with ✨ by [gendoc](../../../src/lib/ext/gendoc.sh))* diff --git a/docs/src/lib/project.md b/docs/src/lib/project.md index c23cd72..13863ef 100644 --- a/docs/src/lib/project.md +++ b/docs/src/lib/project.md @@ -4,7 +4,7 @@ Project definition functions for bash scripts ## FUNCTIONS -### `project::get_configuration_path ✅ (public)` +### `project_get_configuration_path ✅ (public)` * Get the project configuration path. @@ -15,21 +15,21 @@ Project definition functions for bash scripts * Example ```bash -project::get_configuration_path +project_get_configuration_path ``` * Output * `stdout`: path to the project configuration file (default: config/project.sh) -### `project::print_configuration ✅ (public)` +### `project_print_configuration ✅ (public)` * Print the project configuration. * Example ```bash -project::print_configuration +project_print_configuration ``` * Output @@ -40,14 +40,14 @@ project::print_configuration * `return`: 1 if the project configuration is not defined yet -### `project::_architecture_print_layers 🚫 (private)` +### `project__architecture_print_layers 🚫 (private)` * Print the project architecture layers. * Example ```bash -project::_architecture_print_layers +project__architecture_print_layers ``` * Output @@ -55,4 +55,4 @@ project::_architecture_print_layers * `stdout`: The project architecture layers as a formatted string --------------------------------------- -*Generated from [src/lib/project.sh](../../../src/lib/project.sh) on 11.08.2023 (writen with ✨ by [gendoc](../../../src/lib/ext/gendoc.sh))* +*Generated from [src/lib/project.sh](../../../src/lib/project.sh) on 08.09.2023 (writen with ✨ by [gendoc](../../../src/lib/ext/gendoc.sh))* diff --git a/docs/src/lib/sequence.md b/docs/src/lib/sequence.md deleted file mode 100644 index 1534d1e..0000000 --- a/docs/src/lib/sequence.md +++ /dev/null @@ -1,142 +0,0 @@ -# LIBRARY `src/lib/sequence.sh` - -Sequence definition functions for bash scripts - -## FUNCTIONS - -### `sequence::_check_prerequisites 🚫 (private)` - -* Check prerequisites for sequence. - -* Example - -```bash -sequence::_check_prerequisites -``` - -* Return Code - - * `return`: 255 if the prerequisites are not met - -### `sequence::_check_sequence_definition_path 🚫 (private)` - -* Check if the sequence definition file exists. - -* Argument - - 1. `sequence_definition_path`: path to the sequence definition file - -* Example - -```bash -sequence::_check_sequence_definition_path -``` - -* Output - - * `stdout`: Writes the info message to stdout if the sequence definition file exists - -* Return Code - - * `return`: sequence_definition_path: path to the sequence definition file - -### `sequence::_load_sequences_id 🚫 (private)` - -* Load sequences id from a file. - -* Example - -```bash -sequence::_load_sequences_id "config/sequence-default.json" -``` - -* Output - - * `stdout`: Writes debug messages to stdout - -* Return Code - - * `return`: id of the sequences as array - -### `sequence::_load_step_definition 🚫 (private)` - -* Load step definition from an item and the sequence definition file. - -* Argument - - 1. `item_id`: id of the item to load - - 1. `sequence_definition_path`: path to the sequence definition file - -* Example - -```bash -sequence::_load_step_definition "step1" "config/sequence-default.json" -``` - -* Output - - * `stdout`: Writes debug messages to stdout - -* Return Code - - * `return`: Step definition as array - -### `sequence::_load_step_values 🚫 (private)` - -* Load step values as environment variables from a step definition as JSON. - -* Argument - - 1. `step_definition`: step definition to load - -* Example - -```bash -sequence::_load_step_values "["id":"step1","name":"Step 1","description":"Step 1 description","type":"command","command":"echo Step 1"]" -``` - -* Output - - * `stdout`: Writes debug messages to stdout - -* Return Code - - * `return`: The step values - -### `sequence::_iterate_over_sequence 🚫 (private)` - -* Iterate over sequence. - -* Argument - - 1. `sequence_definition_path`: path to the sequence definition file - - 1. `sequences_id`: array of sequences id - -* Example - -```bash -sequence::_iterate_over_sequence "config/sequence-default.json" "step1 step2 step3" -``` - -### `sequence::load ✅ (public)` - -* Load sequence definition from a file. - -* Argument - - 1. `sequence_definition_path`: path to the sequence definition file - -* Example - -```bash -sequence::load "config/sequence-default.json" -``` - -* Output - - * `stdout`: Writes the sequence definition details to stdout - ---------------------------------------- -*Generated from [src/lib/sequence.sh](../../../src/lib/sequence.sh) on 11.08.2023 (writen with ✨ by [gendoc](../../../src/lib/ext/gendoc.sh))* diff --git a/docs/src/lib/tooling.md b/docs/src/lib/tooling.md index ecf8a54..8c80013 100644 --- a/docs/src/lib/tooling.md +++ b/docs/src/lib/tooling.md @@ -4,7 +4,7 @@ Check if a command exists ## FUNCTIONS -### `tooling::_check_command 🚫 (private)` +### `tooling__check_command 🚫 (private)` * Argument @@ -13,14 +13,14 @@ Check if a command exists * Example ```bash -tooling::_check_command jq +tooling__check_command jq ``` * Output * `stdout`: true if the command exists otherwise false -### `tooling::_get_command 🚫 (private)` +### `tooling__get_command 🚫 (private)` * Argument @@ -29,22 +29,24 @@ tooling::_check_command jq * Example ```bash -tooling::_get_command jq +tooling__get_command jq ``` * Output * `stdout`: The path of the command -### `tooling::set_jq ✅ (public)` +### `tooling_set_jq ✅ (public)` * Set the jq command * Example ```bash -tooling::set_jq +tooling_set_jq ``` +### `tooling_get_ip ✅ (public)` + --------------------------------------- -*Generated from [src/lib/tooling.sh](../../../src/lib/tooling.sh) on 11.08.2023 (writen with ✨ by [gendoc](../../../src/lib/ext/gendoc.sh))* +*Generated from [src/lib/tooling.sh](../../../src/lib/tooling.sh) on 08.09.2023 (writen with ✨ by [gendoc](../../../src/lib/ext/gendoc.sh))* diff --git a/docs/src/lib/workflow.md b/docs/src/lib/workflow.md new file mode 100644 index 0000000..e5ef0f9 --- /dev/null +++ b/docs/src/lib/workflow.md @@ -0,0 +1,86 @@ +# LIBRARY `src/lib/workflow.sh` + +Workflow definition functions for bash scripts + +## FUNCTIONS + +### `workflow_check_prerequisites ✅ (public)` + +* Check prerequisites for workflow. + +* Example + +```bash +workflow_check_prerequisites +``` + +* Return Code + + * `return`: 255 if the prerequisites are not met + +### `workflow_check_workflow_definition_path ✅ (public)` + +* Check if the workflow definition file exists. + +* Argument + + 1. `workflow_definition_path`: path to the workflow definition file + +* Example + +```bash +workflow_check_workflow_definition_path +``` + +* Output + + * `stdout`: Writes the info message to stdout if the workflow definition file exists + +* Return Code + + * `return`: workflow_definition_path: path to the workflow definition file + +### `workflow_get_workflows_containers_names ✅ (public)` + +* Get containers names from a JSON workflow definition. + +* Example + +```bash +workflow_workflow_get_workflows_containers_names "config/workflow-default.json" +``` + +* Output + + * `stdout`: Writes debug messages to stdout + +* Return Code + + * `return`: All found containers names of the workflow as array + +### `workflow_load_action_definition ✅ (public)` + +* Load action definition from an action_id and the workflow definition file. + +* Argument + + 1. `action_id`: id of the action to load + + 1. `workflow_definition_path`: path to the workflow definition file + +* Example + +```bash +workflow_load_action_definition "action1" "config/workflow-default.json" +``` + +* Output + + * `stdout`: Writes debug messages to stdout + +* Return Code + + * `return`: Action definition as an array + +--------------------------------------- +*Generated from [src/lib/workflow.sh](../../../src/lib/workflow.sh) on 08.09.2023 (writen with ✨ by [gendoc](../../../src/lib/ext/gendoc.sh))* diff --git a/makefile b/makefile index 1f7d3d6..7a44fbb 100644 --- a/makefile +++ b/makefile @@ -32,4 +32,4 @@ test: shellspec -s bash dev: - shellspec -s bash spec/**/workflow_spec.sh + shellspec -s bash spec/**/**/gendoc_spec.sh diff --git a/package.json b/package.json index 9b36962..9591f3f 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "src/lib/log.sh", "src/lib/platform.sh", "src/lib/project.sh", - "src/lib/sequence.sh", "src/lib/tooling.sh", + "src/lib/workflow.sh", "src/wild.sh" ], "install": "make install" diff --git a/spec/lib/ext/gendoc_spec.sh b/spec/lib/ext/gendoc_spec.sh deleted file mode 100644 index d89fef0..0000000 --- a/spec/lib/ext/gendoc_spec.sh +++ /dev/null @@ -1,94 +0,0 @@ -# shellcheck disable=SC2148 -# -# Description: Unit tests for gendoc.sh - -Describe 'Script Documentation Generation' - - setup() { - export WILD_CWD="${PWD}" - export LOG_PATH="${WILD_CWD}/tmp/log" - export LOG_LEVEL="${LOG_LEVEL_DEBUG}" - } - BeforeAll 'setup' - - It 'generates documentation' - When call "./src/lib/ext/gendoc.sh" "./src/lib/ext/gendoc.sh" - - Dump - - #The stdout should include "## LIBRARY" - #The stdout should include "## GLOBAL VARIABLES" - #The stdout should include "## FUNCTIONS" - The status should be success - End - - It 'generates documentation for a script with shebang' - - Skip "Skip!" - - When run "./src/lib/ext/gendoc.sh" "./src/lib/ext/gendoc.sh" - The output should include "# LIBRARY \`script_with_shebang.sh\`" - The status should be success - End - - It 'generates documentation for a script with constant' - - Skip "Skip!" - - When run "./src/lib/ext/gendoc.sh" "./src/lib/ext/gendoc.sh" - The output should include "### \`CONSTANT_NAME\`" - The output should include "* *Constant description*" - The status should be success - End - - It 'generates documentation for a script with argument' - - Skip "Skip!" - - When run "./src/lib/ext/gendoc.sh" "./src/lib/ext/gendoc.sh" - The output should include "### \`function_name\`" - The output should include "* Function description" - The output should include "Argument" - The output should include " 1. \`argument_name\`: Argument description" - The status should be success - End - - It 'generates documentation for a script with example' - - Skip "Skip!" - - When run "./src/lib/ext/gendoc.sh" "./src/lib/ext/gendoc.sh" - The output should include "### \`function_name\`" - The output should include "* Function description" - The output should include "* Example" - The output should include "\`\`\`bash" - The output should include "Example code" - The output should include "\`\`\`" - The status should be success - End - - It 'generates documentation for a script with stdout' - - Skip "Skip!" - - When run "./src/lib/ext/gendoc.sh" "./src/lib/ext/gendoc.sh" - The output should include "### \`function_name\`" - The output should include "* Function description" - The output should include "Output" - The output should include " * \`stdout\`: Standard output description" - The status should be success - End - - It 'generates documentation for a script with return value' - - Skip "Skip!" - - When run "./src/lib/ext/gendoc.sh" "./src/lib/ext/gendoc.sh" - The output should include "### \`function_name\`" - The output should include "* Function description" - The output should include "Return Code" - The output should include " * \`return\`: Return value description" - The status should be success - End - -End diff --git a/spec/lib/log_spec.sh b/spec/lib/log_spec.sh index 101a6e2..2d27240 100644 --- a/spec/lib/log_spec.sh +++ b/spec/lib/log_spec.sh @@ -14,17 +14,17 @@ Describe "Test that log.sh" BeforeAll 'setup' - Describe "log::_log" + Describe "log__log" It "logs a message at the specified level" - When call log::_log "${LOG_LEVEL_INFO}" "Test message" "$LOG_LEVEL_INFO_COLOR" "$LOG_COLOR_OFF" + When call log__log "${LOG_LEVEL_INFO}" "Test message" "$LOG_LEVEL_INFO_COLOR" "$LOG_COLOR_OFF" The status should be success The output should eq "" The error should include "[INFO] Test message" End It "does not log a message at a lower level" - When call log::_log "${LOG_LEVEL_DEBUG}" "Test message" "$LOG_LEVEL_DEBUG_COLOR" "$LOG_COLOR_OFF" + When call log__log "${LOG_LEVEL_DEBUG}" "Test message" "$LOG_LEVEL_DEBUG_COLOR" "$LOG_COLOR_OFF" The status should be success The output should eq "" The error should not include "[INFO] Test message" @@ -32,12 +32,12 @@ Describe "Test that log.sh" End - Describe "log::debug" + Describe "log_debug" BeforeCall LOG_LEVEL="${LOG_LEVEL_DEBUG}" It "logs a message at the debug level" - When call log::debug "Test message" + When call log_debug "Test message" The status should be success The output should eq "" The error should include "[DEBUG] [shellspec_evaluation_call_function] Test message" @@ -46,7 +46,7 @@ Describe "Test that log.sh" BeforeCall LOG_LEVEL="${LOG_LEVEL_INFO}" It "does not log a message at a lower level" - When call log::debug "Test message" + When call log_debug "Test message" The status should be success The output should eq "" The error should not include "[DEBUG] [shellspec_evaluation_call_function] Test message" @@ -54,10 +54,10 @@ Describe "Test that log.sh" End - Describe "log::info" + Describe "log_info" It "logs a message at the info level" - When call log::info "Test message" + When call log_info "Test message" The status should be success The output should eq "" The error should include "[INFO] Test message" @@ -65,10 +65,10 @@ Describe "Test that log.sh" End - Describe "log::warn" + Describe "log_warn" It "logs a message at the warn level" - When call log::warn "Test message" + When call log_warn "Test message" The status should be success The output should eq "" The error should include "[WARN] Test message" @@ -76,10 +76,10 @@ Describe "Test that log.sh" End - Describe "log::error" + Describe "log_error" It "logs a message at the error level" - When call log::error "Test message" + When call log_error "Test message" The status should be success The output should eq "" The error should include "[ERROR] Test message" @@ -87,10 +87,10 @@ Describe "Test that log.sh" End - Describe "log::fatal" + Describe "log_fatal" It "logs a message at the fatal level" - When call log::fatal "Test message" + When call log_fatal "Test message" The status should be success The output should eq "" The error should include "[FATAL] Test message" @@ -98,10 +98,10 @@ Describe "Test that log.sh" End - Describe "log::banner" + Describe "log_banner" It "logs a message as a banner" - When call log::banner "Test message" + When call log_banner "Test message" The status should be success The output should eq "" The error should include "################################" diff --git a/spec/lib/platform_spec.sh b/spec/lib/platform_spec.sh index d3c5866..01f1866 100644 --- a/spec/lib/platform_spec.sh +++ b/spec/lib/platform_spec.sh @@ -6,7 +6,7 @@ Describe "Test that platform.sh" Include "./src/lib/platform.sh" - Describe "platform::_is_jenkins()" + Describe "platform__is_jenkins()" It "should success when all Jenkins env variables are set" @@ -14,7 +14,7 @@ Describe "Test that platform.sh" BeforeCall 'BUILD_ID=FAKE_ID' BeforeCall 'WORKSPACE=FAKE_WORKSPACE' - When call platform::_is_jenkins + When call platform__is_jenkins The status should be success End @@ -23,36 +23,36 @@ Describe "Test that platform.sh" BeforeCall 'JENKINS_URL=FAKE_URL' BeforeCall 'BUILD_ID=FAKE_ID' - When call platform::_is_jenkins + When call platform__is_jenkins The status should be failure The status should eq 1 End It "returns false when no Jenkins env variables are set" - When call platform::_is_jenkins + When call platform__is_jenkins The status should be failure The status should eq 1 End End - Describe "platform::_is_gitlab()" + Describe "platform__is_gitlab()" It "returns false when no Gitlab env variables are set" - When call platform::_is_gitlab + When call platform__is_gitlab The status should be failure The status should eq 1 End End - Describe "platform::_is_local()" + Describe "platform__is_local()" It "returns true when no Jenkins nor Gitlab env variables are set" - When call platform::_is_local + When call platform__is_local The status should be success End @@ -62,14 +62,14 @@ Describe "Test that platform.sh" BeforeCall 'BUILD_ID=FAKE_ID' BeforeCall 'WORKSPACE=FAKE_WORKSPACE' - When call platform::_is_local + When call platform__is_local The status should be failure The status should eq 1 End End - Describe "platform::get_platform()" + Describe "platform_get_platform()" It "returns 'JENKINS' when all Jenkins env variables are set" @@ -77,13 +77,13 @@ Describe "Test that platform.sh" BeforeCall 'BUILD_ID=FAKE_ID' BeforeCall 'WORKSPACE=FAKE_WORKSPACE' - When call platform::get_platform + When call platform_get_platform The stdout should eq "JENKINS" End It "returns 'LOCAL' when no Jenkins nor Gitlab env variables are set" - When call platform::get_platform + When call platform_get_platform The stdout should eq "LOCAL" End diff --git a/spec/lib/project_spec.sh b/spec/lib/project_spec.sh index 25dcdbd..dc122c9 100644 --- a/spec/lib/project_spec.sh +++ b/spec/lib/project_spec.sh @@ -16,11 +16,11 @@ Describe "Test that project.sh" BeforeAll 'setup' - Describe "project::get_configuration_path" + Describe "project_get_configuration_path" It "returns the default configuration path if no path is specified" export CONFIG_PATH="${WILD_CWD}/config" - When call project::get_configuration_path + When call project_get_configuration_path The status should be success The output should include "config/workflow-default.json" The error should include "No project configuration file specified, use default" @@ -28,14 +28,14 @@ Describe "Test that project.sh" It "returns the specified configuration path if a path is specified" export CONFIG_PATH="${WILD_CWD}/test/config" - When call project::get_configuration_path "${CONFIG_PATH}/workflow-action.json" + When call project_get_configuration_path "${CONFIG_PATH}/workflow-action.json" The status should be success The output should include "${CONFIG_PATH}/workflow-action.json" The error should include "Read project configuration" End It "exits if the specified configuration path does not exist" - When run project::get_configuration_path "${CONFIG_PATH}/a_bad_project.json" + When run project_get_configuration_path "${CONFIG_PATH}/a_bad_project.json" The status should be failure The status should eq 1 The output should eq "" diff --git a/spec/lib/tooling_spec.sh b/spec/lib/tooling_spec.sh index 0ca01f0..bf6959f 100644 --- a/spec/lib/tooling_spec.sh +++ b/spec/lib/tooling_spec.sh @@ -15,11 +15,11 @@ Describe "Test that tooling.sh" Include "./src/lib/tooling.sh" - Describe "tooling::_check_command" + Describe "tooling__check_command" It "returns true when the command is available on the system" - When call tooling::_check_command "ls" + When call tooling__check_command "ls" The status should be success The status should eq 0 @@ -27,7 +27,7 @@ Describe "Test that tooling.sh" It "returns false when the command is not available on the system" - When call tooling::_check_command "FAKE_COMMAND" + When call tooling__check_command "FAKE_COMMAND" The status should be failure The status should eq 1 @@ -35,11 +35,11 @@ Describe "Test that tooling.sh" End - Describe "tooling::_get_command" + Describe "tooling__get_command" It "returns the command when the command is available on the system" - When call tooling::_get_command "ls" + When call tooling__get_command "ls" The status should be success The output should eq "$(command -v ls)" @@ -47,7 +47,7 @@ Describe "Test that tooling.sh" It "returns an empty string when the command is not available on the system" - When call tooling::_get_command "FAKE_COMMAND" + When call tooling__get_command "FAKE_COMMAND" The status should be failure The output should eq "" @@ -55,16 +55,16 @@ Describe "Test that tooling.sh" End - Describe "tooling::set_jq" + Describe "tooling_set_jq" # shellcheck disable=SC2317 - tooling::_check_command() { if [ "$1" = "jq" ]; then { true; } else { false;} fi } + tooling__check_command() { if [ "$1" = "jq" ]; then { true; } else { false;} fi } # shellcheck disable=SC2317 - tooling::_get_command() { echo "FAKE_JQ"; } + tooling__get_command() { echo "FAKE_JQ"; } It "returns a status success when jq is available on the system" - When call tooling::set_jq + When call tooling_set_jq The status should be success The variable JQ should eq "FAKE_JQ" @@ -73,12 +73,12 @@ Describe "Test that tooling.sh" End # shellcheck disable=SC2317 - tooling::_check_command() { if [ "$1" = "docker" ]; then { true; } else { false;} fi } - tooling::_get_command() { echo "FAKE_DOCKER"; } + tooling__check_command() { if [ "$1" = "docker" ]; then { true; } else { false;} fi } + tooling__get_command() { echo "FAKE_DOCKER"; } It "returns a status success when docker is available on the system" - When call tooling::set_jq + When call tooling_set_jq The status should be success The variable JQ should eq "FAKE_DOCKER run -i scalastic/wild:latest" @@ -86,11 +86,11 @@ Describe "Test that tooling.sh" The stderr should be present # for logs redirected into stderr End - tooling::_check_command() { false; } + tooling__check_command() { false; } It "returns a status failure when jq and docker are not available on the system" - When run tooling::set_jq + When run tooling_set_jq The status should be failure The stderr should be present diff --git a/spec/lib/workflow_spec.sh b/spec/lib/workflow_spec.sh index 7af2ea4..d1136b7 100644 --- a/spec/lib/workflow_spec.sh +++ b/spec/lib/workflow_spec.sh @@ -4,27 +4,29 @@ Describe "Test that workflow.sh" - Include "./src/lib/log.sh" - setup() { export WILD_CWD="${PWD}" export LOG_PATH="${WILD_CWD}/tmp/log" - export LOG_LEVEL="${LOG_LEVEL_INFO}" + export LOG_LEVEL="${LOG_LEVEL_DEBUG}" export CONFIG_PATH="${WILD_CWD}/config" + + mkdir -p "${WILD_CWD}/tmp/config" } + BeforeAll 'setup' Include "./src/lib/workflow.sh" - Describe "workflow::_check_prerequisites" + Describe "workflow_check_prerequisites" It "returns a status success when all prerequisites are met" BeforeRun 'JQ=FAKE_JQ' - When run workflow::_check_prerequisites + When run workflow_check_prerequisites The status should be success + The stderr should be present # for logs redirected into stderr End It "returns a status failure when WILD_CWD is not set" @@ -32,7 +34,7 @@ Describe "Test that workflow.sh" BeforeRun 'unset WILD_CWD' BeforeRun 'JQ=FAKE_JQ' - When run workflow::_check_prerequisites + When run workflow_check_prerequisites The stderr should be present The status should be failure @@ -40,7 +42,7 @@ Describe "Test that workflow.sh" It "returns a status failure when JQ is not set" - When run workflow::_check_prerequisites + When run workflow_check_prerequisites The stderr should be present The status should be failure @@ -48,11 +50,11 @@ Describe "Test that workflow.sh" End - Describe "workflow::_check_workflow_definition_path" + Describe "workflow_check_workflow_definition_path" It "returns a status success when no workflow definition is specified and default one is present on filesystem" - When call workflow::_check_workflow_definition_path + When call workflow_check_workflow_definition_path The status should be success The stdout should eq "config/workflow-default.json" @@ -61,12 +63,12 @@ Describe "Test that workflow.sh" It "returns a status success when a workflow definition is specified and is present on filesystem" - FAKE_DEFINITION_PATH="config/fake_definition.json" + FAKE_DEFINITION_PATH="tmp/config/fake_definition.json" BeforeRun "touch ${FAKE_DEFINITION_PATH}" AfterRun "rm ${FAKE_DEFINITION_PATH}" - When run workflow::_check_workflow_definition_path "${FAKE_DEFINITION_PATH}" + When run workflow_check_workflow_definition_path "${FAKE_DEFINITION_PATH}" The status should be success The output should eq "${FAKE_DEFINITION_PATH}" @@ -75,7 +77,7 @@ Describe "Test that workflow.sh" It "returns a status failure when a workflow definition is specified but is not present on filesystem" - When run workflow::_check_workflow_definition_path "config/fake_definition.json" + When run workflow_check_workflow_definition_path "tmp/config/fake_definition.json" The status should be failure The stderr should be present # for logs redirected into stderr @@ -83,137 +85,42 @@ Describe "Test that workflow.sh" End - Describe "workflow::_get_workflows_containers_names" + Describe "workflow_get_workflows_containers_names" Include "./src/lib/tooling.sh" It "returns all actions containers' names from a workflow definition file" - FAKE_DEFINITION_PATH="test/config/workflow-default.json" + TEST_WORKFLOW_DEFINITION_FILENAME="test/config/test-workflow-default.json" - BeforeRun "tooling::set_jq" - #BeforeRun "echo '{\"id\": \"fake_id\", \"name\": \"Fake name\", \"version\": \"1.0.0\", \"actions\": []}' > ${FAKE_DEFINITION_PATH}" - #AfterRun "rm ${FAKE_DEFINITION_PATH}" + BeforeRun "tooling_set_jq" - When run workflow::_get_workflows_containers_names "${FAKE_DEFINITION_PATH}" + When run workflow_get_workflows_containers_names "${TEST_WORKFLOW_DEFINITION_FILENAME}" The status should be success - The output should eq "bash maven" + The output should eq "wild maven" The stderr should be present # for logs redirected into stderr End End - Describe "workflow::_load_workflow_definition" + Describe "workflow_load_action_definition" Include "./src/lib/tooling.sh" It "returns an action definition from a workflow definition file" - FAKE_DEFINITION_PATH="config/fake_definition.json" - - BeforeRun "tooling::set_jq" - BeforeRun echo "'{\"id\": \"fake_id\", \"name\": \"Fake name\", \"version\": \"1.0.0\", \"actions\": [ ' \ - '{ - \"id\": \"action1\", - \"name\": \"Action 1\", - \"container\": \"bash\", - \"action\": \"test/action/test.sh\" - }' \ - ']}' > ${FAKE_DEFINITION_PATH}" - AfterRun "rm ${FAKE_DEFINITION_PATH}" - - When run workflow::_load_workflow_definition "action1" "${FAKE_DEFINITION_PATH}" + TEST_WORKFLOW_DEFINITION_FILENAME="test/config/test-workflow-default.json" - The status should be success - The output should eq "{\"id\":\"action1\",\"name\":\"Action 1\",\"container\":\"bash\",\"action\":\"test/action/test.sh\"}" - The stderr should be present # for logs redirected into stderr - End - - End + BeforeRun "tooling_set_jq" - Describe "workflow::_load_step_values" - - Include "./src/lib/tooling.sh" - - It "returns step values from a workflow definition file" - - FAKE_DEFINITION_PATH="config/fake_definition.json" - - BeforeCall "tooling::set_jq" - step_definition="{\"id\":\"action1\",\"name\":\"Action 1\",\"container\":\"bash\",\"action\":\"test/action/test.sh\"}" - - # shellcheck disable=SC2154 - When call workflow::_load_step_values "${step_definition}" + When run workflow_load_action_definition "action1" "${TEST_WORKFLOW_DEFINITION_FILENAME}" The status should be success - The variable id should eq "action1" - The variable name should eq "Action 1" - The variable container should eq "bash" - The variable action should eq "test/action/test.sh" + The output should eq "{\"id\":\"action1\",\"name\":\"Action 1\",\"container\":\"wild\",\"script\":\"test/action/bash-version.sh\"}" The stderr should be present # for logs redirected into stderr End End - Describe "workflow::_iterate_over_workflow" - - Include "./src/lib/tooling.sh" - - It "returns a status success when all steps are executed" - - FAKE_DEFINITION_PATH="config/fake_definition.json" - - BeforeCall "tooling::set_jq" - BeforeCall "echo '{\"actions\": [ \ - {\"id\": \"action1\", \"name\": \"Action 1\", \"container\": \"bash\", \"action\": \"test/action/test.sh\"}, \ - {\"id\": \"action2\", \"name\": \"Action 2\", \"container\": \"maven\", \"action\": \"test/action/maven.sh\"} \ - ]}' > ${FAKE_DEFINITION_PATH}" - AfterCall "rm ${FAKE_DEFINITION_PATH}" - - actions_id=("action1" "action2") - - # shellcheck disable=SC2154 - When call workflow::_iterate_over_workflow "${FAKE_DEFINITION_PATH}" "${actions_id[@]}" - - The status should be success - The stderr should include "Loop over step action1" - The stderr should include "Loop over step action2" - The variable id should eq "action2" - The variable name should eq "Action 2" - The variable container should eq "maven" - The variable action should eq "test/action/maven.sh" - End - - End - - Describe "workflow::load" - - Include "./src/lib/tooling.sh" - - It "returns a status success when all steps are executed" - - FAKE_DEFINITION_PATH="config/fake_definition.json" - - BeforeCall "tooling::set_jq" - BeforeCall "echo '{\"actions\": [ \ - {\"id\": \"action1\", \"name\": \"Action 1\", \"container\": \"bash\", \"action\": \"test/action/test.sh\"}, \ - {\"id\": \"action2\", \"name\": \"Action 2\", \"container\": \"maven\", \"action\": \"test/action/maven.sh\"} \ - ]}' > ${FAKE_DEFINITION_PATH}" - AfterCall "rm ${FAKE_DEFINITION_PATH}" - - # shellcheck disable=SC2154 - When call workflow::load "${FAKE_DEFINITION_PATH}" - - The status should be success - The stderr should include "Loop over step action1" - The stderr should include "Loop over step action2" - The variable id should eq "action2" - The variable name should eq "Action 2" - The variable container should eq "maven" - The variable action should eq "test/action/maven.sh" - End - - End - End diff --git a/src/lib/ext/gendoc.sh b/src/lib/ext/gendoc.sh index e2a43ac..b8d5bba 100755 --- a/src/lib/ext/gendoc.sh +++ b/src/lib/ext/gendoc.sh @@ -16,7 +16,7 @@ declare -r MARKER_VARIABLE_DEFINITION='=' declare -r MARKER_FUNCTION_DEFINITION='()' #@desc Constant that marks a private function definition. -declare -r MARKER_FUNCTION_PRIVATE='::_' +declare -r MARKER_FUNCTION_PRIVATE='__' #@desc Constant that marks the end of a block. declare -r MARKER_BLOCK_END='}' @@ -51,14 +51,14 @@ declare -r LABEL_FUNCTION='FUNCTIONS' declare -A buffer=() #@desc Reset the buffer. -doc::_buffer_reset() { +doc__buffer_reset() { buffer=() } #@desc Write a value to the buffer by key. #@arg $1 The key to write. #@arg $2 The value to write. -doc::_buffer_write() { +doc__buffer_write() { local key="$1" local value="$2" @@ -72,7 +72,7 @@ doc::_buffer_write() { #@desc Read a value from the buffer by key. #@arg $1 The key to read. #@return The value of the key. -doc::buffer_read() { +doc_buffer_read() { local key="$1" if [ ${buffer[$key]+_} ]; then @@ -84,7 +84,7 @@ doc::buffer_read() { #@desc Print the buffer as key, value pairs. #@stdout The buffer content -doc::buffer_print() { +doc_buffer_print() { for key in "${!buffer[@]}"; do echo "$key: ${buffer[$key]}" done @@ -95,7 +95,7 @@ doc::buffer_print() { #@arg $2 The pattern to check. #@return 0 if the line starts with the pattern #@return 1 otherwise. -doc::startswith() { +doc_startswith() { local line="$1" local pattern="$2" @@ -114,7 +114,7 @@ doc::startswith() { #@arg $2 The pattern to check. #@return 0 if the line contains the pattern #@return 1 otherwise. -doc::contains() { +doc_contains() { local line="$1" local pattern="$2" @@ -126,19 +126,19 @@ doc::contains() { #@desc Writes the constant part of the documentation. #@stdout The constant part of the documentation. -doc::_write_constant() { - constant_name=$(doc::buffer_read "$ANNOTATION_CONSTANT") - constant_description=$(doc::buffer_read "$ANNOTATION_DESCRIPTION") +doc__write_constant() { + constant_name=$(doc_buffer_read "$ANNOTATION_CONSTANT") + constant_description=$(doc_buffer_read "$ANNOTATION_DESCRIPTION") { echo -e "### \`${constant_name}\`\n" echo -e "* *${constant_description}*\n" } - doc::_buffer_reset + doc__buffer_reset } -doc::_write_multiple_annotation() { +doc__write_multiple_annotation() { local label="$1" local ordered_values="$2" local separated_values="$3" @@ -152,44 +152,44 @@ doc::_write_multiple_annotation() { fi } -doc::_write_function() { +doc__write_function() { local function_name="$1" local line_number="$2" local function_description - function_description=$(doc::buffer_read "$ANNOTATION_DESCRIPTION") + function_description=$(doc_buffer_read "$ANNOTATION_DESCRIPTION") local function_arguments - function_arguments=$(doc::buffer_read "$ANNOTATION_ARGUMENT") + function_arguments=$(doc_buffer_read "$ANNOTATION_ARGUMENT") local function_example - function_example=$(doc::buffer_read "$ANNOTATION_EXAMPLE") + function_example=$(doc_buffer_read "$ANNOTATION_EXAMPLE") local function_stdout - function_stdout=$(doc::buffer_read "$ANNOTATION_STDOUT") + function_stdout=$(doc_buffer_read "$ANNOTATION_STDOUT") local function_return - function_return=$(doc::buffer_read "$ANNOTATION_RETURN") + function_return=$(doc_buffer_read "$ANNOTATION_RETURN") { echo -e "### \`$function_name\`\n" [ -n "${function_description}" ] && echo -e "* $function_description\n" - doc::_write_multiple_annotation "Argument" true "${function_arguments}" + doc__write_multiple_annotation "Argument" true "${function_arguments}" [ -n "${function_example}" ] && echo -e "* Example\n" [ -n "${function_example}" ] && echo -e "$function_example\n" - doc::_write_multiple_annotation "Output" false "${function_stdout}" - doc::_write_multiple_annotation "Return Code" false "${function_return}" + doc__write_multiple_annotation "Output" false "${function_stdout}" + doc__write_multiple_annotation "Return Code" false "${function_return}" } - doc::_buffer_reset + doc__buffer_reset } -doc::main() { +doc_main() { if test "$*" = ""; then echo "Usage: $0 " exit 1 fi - log::debug "Starting the documentation generation..." + log_debug "Starting the documentation generation..." for file in "$@"; do @@ -199,11 +199,11 @@ doc::main() { line_number=0 if test ! -f "$file"; then - log::fatal "Fatal bazooka: ${file} does not exist" + log_fatal "Fatal bazooka: ${file} does not exist" exit 2 fi - log::debug "Starting the documentation generation of script ${file}..." + log_debug "Starting the documentation generation of script ${file}..." is_shebang=true has_constant_section=false @@ -214,82 +214,82 @@ doc::main() { line_number=$((line_number + 1)) - log::debug "Line is: $line" + log_debug "Line is: $line" - if doc::startswith "$line" "$MARKER_COMMENT_START"; then - log::debug "This is an annotation" + if doc_startswith "$line" "$MARKER_COMMENT_START"; then + log_debug "This is an annotation" ###### Description ###### - if doc::contains "$line" "$ANNOTATION_DESCRIPTION"; then - log::debug "This is a description annotation" + if doc_contains "$line" "$ANNOTATION_DESCRIPTION"; then + log_debug "This is a description annotation" # shellcheck disable=SC2154 disable=SC2295 description=$(echo "${line#$ANNOTATION_DESCRIPTION}" | xargs) if "$is_shebang"; then - log::debug "This is a shebang" + log_debug "This is a shebang" echo -e "# ${LABEL_LIBRARY} \`$file\`\n" echo -e "${description}\n" is_shebang=false else - doc::_buffer_write "$ANNOTATION_DESCRIPTION" "$description" + doc__buffer_write "$ANNOTATION_DESCRIPTION" "$description" fi - log::debug "Description: $description" + log_debug "Description: $description" ###### Constant ###### - elif doc::contains "$line" "$ANNOTATION_CONSTANT"; then - log::debug "This is a constant annotation" + elif doc_contains "$line" "$ANNOTATION_CONSTANT"; then + log_debug "This is a constant annotation" ###### Argument ###### - elif doc::contains "$line" "$ANNOTATION_ARGUMENT"; then - log::debug "This is an argument annotation" + elif doc_contains "$line" "$ANNOTATION_ARGUMENT"; then + log_debug "This is an argument annotation" # shellcheck disable=SC2295 argument=$(echo "${line#$ANNOTATION_ARGUMENT}" | xargs) argument_name=$(echo "$argument" | cut -d ':' -f1 | xargs) argument_description=$(echo "$argument" | cut -d ':' -f2 | xargs) - log::debug "Argument name: $argument_name, description: $argument_description" - doc::_buffer_write "$ANNOTATION_ARGUMENT" "\`${argument_name}\`: ${argument_description}" + log_debug "Argument name: $argument_name, description: $argument_description" + doc__buffer_write "$ANNOTATION_ARGUMENT" "\`${argument_name}\`: ${argument_description}" ###### Example ###### - elif doc::contains "$line" "$ANNOTATION_EXAMPLE"; then - log::debug "This is an example annotation" + elif doc_contains "$line" "$ANNOTATION_EXAMPLE"; then + log_debug "This is an example annotation" # shellcheck disable=SC2295 example="\ \`\`\`bash\n\ $(echo "${line#$ANNOTATION_EXAMPLE}" | xargs)\n\ \`\`\`" - log::debug "Example: $example" - doc::_buffer_write "$ANNOTATION_EXAMPLE" "$example" + log_debug "Example: $example" + doc__buffer_write "$ANNOTATION_EXAMPLE" "$example" ###### Stdout ###### - elif doc::contains "$line" "$ANNOTATION_STDOUT"; then - log::debug "This is a stdout annotation" + elif doc_contains "$line" "$ANNOTATION_STDOUT"; then + log_debug "This is a stdout annotation" # shellcheck disable=SC2154 disable=SC2295 stdout=$(echo "${line#$ANNOTATION_STDOUT}" | xargs) - log::debug "Stdout: $stdout" - doc::_buffer_write "$ANNOTATION_STDOUT" "\`stdout\`: ${stdout}" + log_debug "Stdout: $stdout" + doc__buffer_write "$ANNOTATION_STDOUT" "\`stdout\`: ${stdout}" ###### Return ###### - elif doc::contains "$line" "$ANNOTATION_RETURN"; then - log::debug "This is a return annotation" + elif doc_contains "$line" "$ANNOTATION_RETURN"; then + log_debug "This is a return annotation" # shellcheck disable=SC2154 disable=SC2295 return=$(echo "${line#$ANNOTATION_RETURN}" | xargs) - log::debug "Return: $return" - doc::_buffer_write "$ANNOTATION_RETURN" "\`return\`: ${return}" + log_debug "Return: $return" + doc__buffer_write "$ANNOTATION_RETURN" "\`return\`: ${return}" fi ###### starts with blank ###### - elif doc::startswith "$line" " "; then + elif doc_startswith "$line" " "; then continue ###### Variable ###### - elif doc::contains "$line" "$MARKER_VARIABLE_DEFINITION"; then - log::debug "This is a variable definition" + elif doc_contains "$line" "$MARKER_VARIABLE_DEFINITION"; then + log_debug "This is a variable definition" if ! "$has_constant_section" && ! "$is_function"; then echo -e "## ${LABEL_CONSTANT}\n" @@ -300,13 +300,13 @@ $(echo "${line#$ANNOTATION_EXAMPLE}" | xargs)\n\ # shellcheck disable=SC2295 variable=$(echo "$line" | cut -d "$MARKER_VARIABLE_DEFINITION" -f1 | xargs) name=${variable##* } - doc::_buffer_write "$ANNOTATION_CONSTANT" "\`${name}\`" - doc::_write_constant + doc__buffer_write "$ANNOTATION_CONSTANT" "\`${name}\`" + doc__write_constant fi ###### Function ###### - elif doc::contains "$line" "$MARKER_FUNCTION_DEFINITION"; then - log::debug "This is a function definition" + elif doc_contains "$line" "$MARKER_FUNCTION_DEFINITION"; then + log_debug "This is a function definition" is_function=true if ! "$has_function_section"; then @@ -316,22 +316,22 @@ $(echo "${line#$ANNOTATION_EXAMPLE}" | xargs)\n\ function_name=$(echo "$line" | cut -d '(' -f1 | xargs) - if doc::contains "$function_name" "$MARKER_FUNCTION_PRIVATE"; then - log::debug "This is a private function definition" - doc::_write_function "$function_name 🚫 (private)" "$line_number" + if doc_contains "$function_name" "$MARKER_FUNCTION_PRIVATE"; then + log_debug "This is a private function definition" + doc__write_function "$function_name 🚫 (private)" "$line_number" else - log::debug "This is a public function definition" - doc::_write_function "$function_name ✅ (public)" "$line_number" + log_debug "This is a public function definition" + doc__write_function "$function_name ✅ (public)" "$line_number" fi fi ###### Block ###### - if doc::startswith "$line" "$MARKER_BLOCK_END"; then - log::debug "This is a block end" + if doc_startswith "$line" "$MARKER_BLOCK_END"; then + log_debug "This is a block end" is_function=false - doc::_buffer_reset + doc__buffer_reset fi @@ -346,4 +346,8 @@ $(echo "${line#$ANNOTATION_EXAMPLE}" | xargs)\n\ done } -doc::main "$@" +# Check if the script is being executed directly +if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then + doc_main "$@" +fi + diff --git a/src/lib/workflow.sh b/src/lib/workflow.sh index d4a7f3f..693a774 100644 --- a/src/lib/workflow.sh +++ b/src/lib/workflow.sh @@ -10,26 +10,26 @@ source "./src/lib/log.sh" #@const JQ (read-only) #@return 255 if the prerequisites are not met workflow_check_prerequisites () { - log::debug "Check prerequisites for workflow" + log_debug "Check prerequisites for workflow" local status=0 if [ -z "${WILD_CWD:-}" ]; then - log::error "Missing WILD_CWD environment variable" + log_error "Missing WILD_CWD environment variable" status=1 fi if [ -z "${JQ:-}" ]; then - log::error "Missing jq command" + log_error "Missing jq command" status=1 fi if [ $status -ne 0 ]; then - log::fatal "Prerequisites for workflow are not met" + log_fatal "Prerequisites for workflow are not met" return 1 fi - log::debug "WILD_CWD is ${WILD_CWD}" + log_debug "WILD_CWD is ${WILD_CWD}" log_debug "jq command is ${JQ}" } @@ -58,16 +58,16 @@ workflow_check_workflow_definition_path() { echo "$path" } -#@desc Get containers' names from a JSON workflow definition. +#@desc Get containers names from a JSON workflow definition. #@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 -#@return All found containers' names of the workflow as array +#@return All found containers names of the workflow as array workflow_get_workflows_containers_names() { local workflow_definition_path="${1}" - local containers_names=() + local containers_names=() while IFS= read -r line; do containers_names+=("$line") done < <("$JQ" -r '.actions[].container' "${workflow_definition_path}") @@ -82,90 +82,27 @@ workflow_get_workflows_containers_names() { 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\" +#@desc Load action definition from an action_id and the workflow definition file. +#@ex workflow_load_action_definition \"action1\" \"config/workflow-default.json\" #@const JQ (read-only) #@const workflow_definition_path (read-only) -#@arg item_id: id of the item to load +#@arg action_id: id of the action to load #@arg workflow_definition_path: path to the workflow definition file #@stdout Writes debug messages to stdout -#@return Step definition as array -workflow_load_workflow_definition() { - local item_id="${1:-}" +#@return Action definition as an array +workflow_load_action_definition() { + local action_id="${1:-}" local workflow_definition_path="${2:-}" - local step_definition + local action_definition # shellcheck disable=SC2207 - step_definition=($("$JQ" <"${WILD_CWD}/${workflow_definition_path}" -rc ".actions[] | select(.id == \"${item_id}\")")) + action_definition=($("$JQ" <"${WILD_CWD}/${workflow_definition_path}" -rc ".actions[] | select(.id == \"${action_id}\")")) # shellcheck disable=SC2145 - log_debug "Step definition is: ${step_definition[@]}" + log_debug "Action definition is: ${action_definition[@]}" - echo "${step_definition[@]}" + echo "${action_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'\"]\" -#@const JQ (read-only) -#@arg step_definition: step definition to load -#@stdout Writes debug messages to stdout -#@return The step values -workflow_load_step_values() { - local step_definition="${1}" - local initializer - # shellcheck disable=SC2128 disable=SC2086 - initializer=$("$JQ" -r <<<$step_definition 'to_entries[] | "\(.key)=\(.value)"' | tr -d \") - - log_debug "Step values are: $initializer" - - eval "$initializer" -} - -#@desc Iterate over workflow. -#@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 -workflow_iterate_over_workflow() { - local workflow_definition_path="${1}" - shift - local workflows_id=("$@") - - for item in "${workflows_id[@]}"; do - log_info "Loop over step $item" - - local step_definition - # shellcheck disable=SC2207 - step_definition=($(workflow_load_workflow_definition "$item" "$workflow_definition_path")) - - # shellcheck disable=SC2128 disable=SC2145 - log_debug "Step definition is ${step_definition[@]}" - - workflow_load_step_values "${step_definition[@]}" - done -} - -#@desc Load workflow definition from a file. -#@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() { -# local workflow_definition_path="${1:-}" -# -# 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")) -# -# # shellcheck disable=SC2145 -# 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[@]}" -#} - # Call the load function with the specified workflow definition path # workflow_load "config/workflow-default.json" diff --git a/src/wild.sh b/src/wild.sh index 88aa314..b0c047a 100755 --- a/src/wild.sh +++ b/src/wild.sh @@ -51,4 +51,5 @@ source "${WILD_CWD}/src/lib/workflow.sh" workflow_configuration_path=$(project::get_configuration_path) +# shellcheck disable=SC2034 used_containers_names=$(workflow::_get_workflows_containers_names "$workflow_configuration_path") diff --git a/config/workflow-action.json b/test/config/test-workflow-default.json similarity index 55% rename from config/workflow-action.json rename to test/config/test-workflow-default.json index 116fa5a..c08352b 100644 --- a/config/workflow-action.json +++ b/test/config/test-workflow-default.json @@ -6,8 +6,14 @@ { "id": "action1", "name": "Action 1", - "container": "bash", + "container": "wild", "script": "test/action/bash-version.sh" - } + }, + { + "id": "action2", + "name": "Action 2", + "container": "maven", + "script": "test/action/maven-version.sh" + } ] } diff --git a/test/jenkins/config/casc.yaml b/test/jenkins/config/casc.yaml index 9de4889..66a8719 100644 --- a/test/jenkins/config/casc.yaml +++ b/test/jenkins/config/casc.yaml @@ -65,7 +65,7 @@ jobs: url('https://github.com/scalastic/wild.git') credentials('wild-github-token') } - branch('*/15-test-wild-on-jenkins') + branch('*/17-add-more-configurations-on-workflow-pipeline') } } lightweight() @@ -77,3 +77,6 @@ unclassified: url: http://${LOCAL_IP_ADDRESS}:8080/ ansiColorBuildWrapper: globalColorMapName: "xterm" + themeManager: + disableUserThemes: true + theme: "darkSystem" diff --git a/test/jenkins/config/plugins.txt b/test/jenkins/config/plugins.txt index b8c49a7..820e6a3 100644 --- a/test/jenkins/config/plugins.txt +++ b/test/jenkins/config/plugins.txt @@ -8,3 +8,4 @@ kubernetes:latest job-dsl:latest ansicolor:latest pipeline-utility-steps:latest +dark-theme:latest diff --git a/vars/wildPipeline.groovy b/vars/wildPipeline.groovy index 301a4d0..62e38af 100644 --- a/vars/wildPipeline.groovy +++ b/vars/wildPipeline.groovy @@ -28,14 +28,6 @@ def call() { logger.bannerStage('init') - //logger.info("This is an informational message.") - //logger.warn("This is a warning message.") - //logger.err("This is an error message.") - //logger.success("This is a success message.") - //logger.debug("This is a debug message.") - //logger.bannerLogo("Banner Logo") - //logger.bannerStage("My Stage") - sh(script: "git config --global http.sslverify false") checkout scm @@ -64,24 +56,20 @@ def call() { export LOG_PATH=${log_path} bash --version source ${wild_path}/src/lib/workflow.sh - workflow_get_workflows_containers_names ${wild_path}/test/config/workflow-default.json + workflow_get_workflows_containers_names ${wild_path}/config/workflow-default.json ''', returnStdout: true) } - logger.info("workflow executed!") + logger.info("Workflow pipeline is initialized!") def config_containers_run = containerConfig.getContainerConfig(config_containers, names_containers_run) k8s_containers_run = containerConfig.generateContainerTemplate(config_containers_run) - logger.info("${k8s_containers_run}") - stash name: "init", useDefaultExcludes: false } } } } - - podTemplate( label: pod_run_label, yaml: k8s_containers_run, @@ -94,14 +82,25 @@ def call() { unstash "init" def workflow = readJSON(file: "${wild_path}/config/workflow-default.json") - logger.info("Processing workflow '${workflow.name}' version '${workflow.version}'...") + logger.info("Processing workflow '${workflow.name}', version '${workflow.version}'...") workflow.actions.each { action -> stage(action.name) { logger.bannerStage(action.name) container(action.container) { + if (action.pre_script?.trim()) { + logger.info("Processing PRE action script ${action.pre_script}...") + sh "chmod +x ${action.pre_script}" + sh "./${action.pre_script}" + } + logger.info("Processing MAIN action script ${action.script}...") sh "chmod +x ${action.script}" sh "./${action.script}" + if (action.post_script?.trim()) { + logger.info("Processing POST action script ${action.post_script}...") + sh "chmod +x ${action.post_script}" + sh "./${action.post_script}" + } } } }