From 8f34a19d26c4ab297c898cc056ae599137912381 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Mon, 12 Aug 2019 20:46:23 +0200 Subject: [PATCH] MON-494 rework scripts organization and splitting --- scripts/00_requirements.sh | 2 ++ ...1_update_output.sh => 10_update_output.sh} | 0 scripts/20_update_global_readme.sh | 27 +++++++++++++++++++ ...readme.sh => 20_update_modules_readmes.sh} | 25 ----------------- ...3_update_module.sh => 30_update_module.sh} | 0 5 files changed, 29 insertions(+), 25 deletions(-) rename scripts/{01_update_output.sh => 10_update_output.sh} (100%) create mode 100755 scripts/20_update_global_readme.sh rename scripts/{02_update_readme.sh => 20_update_modules_readmes.sh} (78%) rename scripts/{03_update_module.sh => 30_update_module.sh} (100%) diff --git a/scripts/00_requirements.sh b/scripts/00_requirements.sh index f65fa22..3d5c3d8 100755 --- a/scripts/00_requirements.sh +++ b/scripts/00_requirements.sh @@ -23,7 +23,9 @@ function check_version() { if [[ "$1" == "terraform" ]]; then tmp_dir=$(mktemp -d) cd ${tmp_dir} + set +o pipefail # terraform fails on command piping when not last version cur_ver=$(terraform version | head -n 1 | cut -d' ' -f2) + set -o pipefail cur_ver=${cur_ver#"v"} cd - > /dev/null rm -fr ${tmp_dir} diff --git a/scripts/01_update_output.sh b/scripts/10_update_output.sh similarity index 100% rename from scripts/01_update_output.sh rename to scripts/10_update_output.sh diff --git a/scripts/20_update_global_readme.sh b/scripts/20_update_global_readme.sh new file mode 100755 index 0000000..9135c60 --- /dev/null +++ b/scripts/20_update_global_readme.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +source "$(dirname $0)/utils.sh" +init + +# only keep current README from begining to "Monitors summary" section (delete monitors list) +sed -i '/### Monitors summary ###/q' README.md +# add a newline after listing section +echo >> README.md +# loop over all ready monitors sets on the repo +for path in $(find -mindepth 1 -type d ! -path '*/.*' ! -path './scripts*' -print | sort -fdbi); do + # split path in directories + directories=($(list_dirs $path)) + # loop over directories in path + for i in $(seq 1 $((${#directories[@]}-1))); do + ## add tabulation for every subdirectory + echo -en "\t" >> README.md + done + # add link to list of monitors sets + echo -en "- [$(basename ${path})](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/" >> README.md + # add path to link + for directory in "${directories[@]}"; do + echo -en "${directory}/" >> README.md + done + # end of markdown link + echo ")" >> README.md +done diff --git a/scripts/02_update_readme.sh b/scripts/20_update_modules_readmes.sh similarity index 78% rename from scripts/02_update_readme.sh rename to scripts/20_update_modules_readmes.sh index fab7f9e..1d0643d 100755 --- a/scripts/02_update_readme.sh +++ b/scripts/20_update_modules_readmes.sh @@ -6,31 +6,6 @@ init # download awk script to hack terraform-docs TERRAFORM_AWK="/tmp/terraform-docs.awk" curl -Lso ${TERRAFORM_AWK} "https://raw.githubusercontent.com/cloudposse/build-harness/master/bin/terraform-docs.awk" - -## root README generator -# only keep current README from begining to "Monitors summary" section (delete monitors list) -sed -i '/### Monitors summary ###/q' README.md -# add a newline after listing section -echo >> README.md -# loop over all ready monitors sets on the repo -for path in $(find -mindepth 1 -type d ! -path '*/.*' ! -path './scripts*' -print | sort -fdbi); do - # split path in directories - directories=($(list_dirs $path)) - # loop over directories in path - for i in $(seq 1 $((${#directories[@]}-1))); do - ## add tabulation for every subdirectory - echo -en "\t" >> README.md - done - # add link to list of monitors sets - echo -en "- [$(basename ${path})](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/" >> README.md - # add path to link - for directory in "${directories[@]}"; do - echo -en "${directory}/" >> README.md - done - # end of markdown link - echo ")" >> README.md -done - # this is the pattern from where custom information is saved to be restored PATTERN_DOC="Related documentation" diff --git a/scripts/03_update_module.sh b/scripts/30_update_module.sh similarity index 100% rename from scripts/03_update_module.sh rename to scripts/30_update_module.sh