diff --git a/.github/workflows/go-application.yml b/.github/workflows/go-application.yml index 01253469..11cf1279 100644 --- a/.github/workflows/go-application.yml +++ b/.github/workflows/go-application.yml @@ -49,7 +49,6 @@ jobs: uses: ludeeus/action-shellcheck@2.0.0 with: ignore_names: >- - add_descriptions_to_readme.sh add_metrics_to_readme.sh create_release_notes.sh verify_metrics.sh diff --git a/README.md b/README.md index 34c9ac64..67cd9249 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ See more in the [Migration](#migration) section. - `make build-linux`: Builds a binary executable for Linux. - `make build-darwin`: Builds a binary executable for Darwin. - `make build-windows`: Builds a binary executable for Windows. +- `make build-linux-arm`: Builds a binary executable for Linux ARM. - `make build-docker`: Builds a Docker image for the Go Exporter application. - `make build-docker-multi`: Builds a multi-arch Docker image (`amd64` and `arm64`). - `make clean`: Deletes all binary executables in the out directory. @@ -168,6 +169,9 @@ See more in the [Migration](#migration) section. - `make install-helm-readme`: Installs readme-generator-for-helm tool. - `make helm-readme`: Generates Helm chart README.md file. - `make clean-elasticsearch`: Cleans Elasticsearch data, works only with default ES port. The command may take a very long time to complete. +- `make upgrade-dependencies`: Upgrades all dependencies. +- `make migrate-v1-to-v2`: Migrates configuration from v1 to v2. +- `make update-readme-descriptions`: Update Makefile descriptions in main README.md. - `make help`: Shows info about available commands. @@ -177,96 +181,6 @@ See more in the [Migration](#migration) section. The main Go Exporter application is located in the cmd/exporter/main.go file. The binary executables are saved in the out directory. -#### Example Usage - - - -Builds binary executables for all OS (Win, Darwin, Linux): - - make all - -Runs the Go Exporter application: - - make run - -Builds a binary executable for Linux: - - make build-linux - -Builds a binary executable for Darwin: - - make build-darwin - -Builds a binary executable for Windows: - - make build-windows - -Builds a Docker image for the Go Exporter application: - - make build-docker - -Builds a multi-arch Docker image (`amd64` and `arm64`): - - make build-docker-multi - -Deletes all binary executables in the out directory: - - make clean - -Runs all tests: - - make test - -Displays test coverage report: - - make test-coverage - -Starts a Docker-compose configuration: - - make compose - -Starts a Docker-compose configuration until it's ready: - - make wait-for-compose - -Stops a Docker-compose configuration: - - make compose-down - -Verifies the metrics from the Go Exporter application: - - make verify-metrics - -Pulls the Docker image from the registry: - - make pull - -Shows logs from the Docker-compose configuration: - - make logs - -Minifies the binary executables: - - make minify - -Installs readme-generator-for-helm tool: - - make install-helm-readme - -Generates Helm chart README.md file: - - make helm-readme - -Cleans Elasticsearch data, works only with default ES port. The command may take a very long time to complete: - - make clean-elasticsearch - -Shows info about available commands: - - make help - - - ## Helper Scripts Application repository contains some helper scripts, which can be used to improve process diff --git a/scripts/add_descriptions_to_readme.sh b/scripts/add_descriptions_to_readme.sh index 7a1335f1..62187bf0 100755 --- a/scripts/add_descriptions_to_readme.sh +++ b/scripts/add_descriptions_to_readme.sh @@ -2,128 +2,100 @@ # execute: ./scripts/add_descriptions_to_readme.sh +# define new line character to be used in `sed` +nl=' +' + +# enable regex (see: https://stackoverflow.com/a/42740385) +shopt -s extglob + scriptName="$(dirname "$0")/$(basename "$0")" function getHelp() { # get descriptions and commands from Makefile - i=0 - commands=() - descriptions=() - - while read -r line; do - if (( i % 2 == 0 )); - then - descriptions+=( "$(echo $line | sed 's/#:[ ]*//')" ) - else - commands+=( $(echo "$line" | cut -d : -f 1) ) - fi - - ((i++)) - done < <( - # https://stackoverflow.com/a/59087509 - grep -B1 -E "^[a-zA-Z0-9_-]+:([^\=]|$)" ./Makefile \ - | grep -v -- -- - ) + i=0 + commands=() + descriptions=() + + while read -r line; do + if (( i % 2 == 0 )); + then + descriptions+=( "${line//#:*( )}" ) + else + commands+=( "$(echo "$line" | cut -d : -f 1)" ) + fi + ((i++)) + done < <( + # https://stackoverflow.com/a/59087509 + grep -B1 -E "^[a-zA-Z0-9_-]+:([^\=]|$)" ./Makefile \ + | grep -v -- -- + ) } FILE=README.md +# returns `commands` and `descriptions` arrays getHelp -let startLine=$(grep -n "^#### Available Commands" $FILE | cut -d : -f 1)+2 -let endLine=$(grep -n "^#### File Structure" $FILE | cut -d : -f 1)-2 - -# Updates "Available Commands" section: +startLine=$(( $( grep -n "^#### Available Commands" $FILE | cut -d : -f 1 ) + 2 )) +endLine=$(( $( grep -n "^#### File Structure" $FILE | cut -d : -f 1 ) - 2 )) +# Updates "Available Commands" section if (( startLine <= endLine)); then - $(sed -i "$startLine,${endLine}d" $FILE) # deletion of previous descriptions + # Deletes previous descriptions + sed -i "$startLine,${endLine}d" "$FILE" fi -function printAvailableCommands() { - curLine=$startLine - stringToWrite="" - let commentLen=${#stringToWrite}-11 - i=0 - - $(sed -i "${curLine}i\\${stringToWrite}" $FILE) - let curLine++ - - $(sed -i "${curLine}i\\ " $FILE) # empty line - let curLine++ - - while (( $i < ${#commands[@]} )) - do - - stringToWrite="- \`make ${commands[$i]}\`: ${descriptions[$i]}." - $(sed -i "${curLine}i\\${stringToWrite}" $FILE) - let curLine++ - - let i++ - done - - $(sed -i "${curLine}i\\ " $FILE) # empty line - let curLine++ - - stringToWrite="" # multiple '*' - $(sed -i "${curLine}i\\${stringToWrite}" $FILE) - let curLine++ - +function createMultipleAsterisks() { + numOfAsterisks=$1 + asterisks=$( eval printf "\*%.0s" "{1..${numOfAsterisks}}" ) + echo "$asterisks" } -echo 'Updating "Available Commands" section...' - -printAvailableCommands - -# Updates "Example Usage" section: - -let startLine=$(grep -n "^#### Example Usage" $FILE | cut -d : -f 1)+2 -let endLine=$(grep -n "^## Helper Scripts" $FILE | cut -d : -f 1)-2 - -if (( startLine <= endLine)); -then - $(sed -i "$startLine,${endLine}d" $FILE) # deletion of previous descriptions -fi +function printAvailableCommands() { + curLine=$startLine + stringToWrite="" + commentLen=$(( ${#stringToWrite} - 11 )) + i=0 -function printExampleUsage() { - curLine=$startLine - stringToWrite="" - let commentLen=${#stringToWrite}-11 - i=0 + sed -i "${curLine}i\\${stringToWrite}" "$FILE" - $(sed -i "${curLine}i\\${stringToWrite}" $FILE) - let curLine++ + # https://www.shellcheck.net/wiki/SC2219 + (( curLine++ )) || true - $(sed -i "${curLine}i\\ " $FILE) # empty line - let curLine++ + # empty line + sed -i "${curLine}i${nl}" "$FILE" - while (( $i < ${#commands[@]} )) - do - stringToWrite="${descriptions[$i]}:" - $(sed -i "${curLine}i\\${stringToWrite}" $FILE) - let curLine++ + (( curLine++ )) || true - $(sed -i "${curLine}i\\ " $FILE) - let curLine++ + echo 'Writing the following commands with their descriptions:' + while (( i < ${#commands[@]} )) + do + stringToWrite="- \`make ${commands[$i]}\`: ${descriptions[$i]}." + stringToWrite=${stringToWrite//\'/\\\'} + echo "$stringToWrite" - stringToWrite=" make ${commands[$i]}" # 4 spaces for tab (DON'T CHANGE IT) - $(sed -i "${curLine}i\\${stringToWrite}" $FILE) - let curLine++ + sed -i "${curLine}i\\${stringToWrite}" "$FILE" + (( curLine++ )) || true - $(sed -i "${curLine}i\\ " $FILE) - let curLine++ + (( i++ )) || true + done - let i++ - done + # empty line + sed -i "${curLine}i${nl}" "$FILE" + (( curLine++ )) || true - stringToWrite="" # multiple '*' - $(sed -i "${curLine}i\\${stringToWrite}" $FILE) - let curLine++ + # multiple '*' + asterisks=$(createMultipleAsterisks $commentLen) + stringToWrite="" + sed -i "${curLine}i\\${stringToWrite}" "$FILE" + (( curLine++ )) || true } -echo 'Updating "Example Usage" section...' +echo 'Updating "Available Commands" section...' -printExampleUsage +printAvailableCommands echo 'Done.'