From 1eabd1f3f231bfd9fe03d034c140398a4264ca04 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Wed, 7 Aug 2019 11:34:44 +0200 Subject: [PATCH] MON-494 make path argument optional and normalize it --- .gitlab-ci.yml | 2 +- README.md | 10 ++++++---- scripts/01_update_output.sh | 2 +- scripts/02_update_readme.sh | 2 +- scripts/03_update_module.sh | 4 +++- scripts/90_best_practices.sh | 2 +- scripts/99_terraform.sh | 2 +- scripts/auto_update.sh | 2 +- scripts/utils.sh | 7 +++++-- 9 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5c7ac09..1f462b6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,7 @@ auto_update: image: claranet/datadog-terraform:latest stage: test script: - - ./scripts/auto_update.sh ./ + - ./scripts/auto_update.sh - git status - git diff --exit-code tags: diff --git a/README.md b/README.md index 65884d7..1657491 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,15 @@ To contribute you will need to [report an issue](https://confluence.fr.clara.net If you would like to resolve an issue or implement new monitors you must follow our [best practices](https://confluence.fr.clara.net/display/DAT/Templates+monitors). -After any change on this repo, you need to run the `./scripts/auto_update.sh ./` command to make sure all is up to date otherwise the CI pipeline will fail: -- the parameter will limit the scripts execution on a specific path on the repository +After any change on this repo, you need to run the `./scripts/auto_update.sh [PATH_TO_MODULE]` command to make sure all is up to date otherwise the CI pipeline will fail: +- the parameter is optional and it will limit the scripts execution on a specific path on the repository - on linux system it is possible to run the script directly while `terraform` and `terraform-docs` commands are available in your PATH -- else you can use [the same docker image as the CI](https://hub.docker.com/r/claranet/datadog-terraform) with docker which is available on every platforms +- else you can use [the same docker image as the CI](https://hub.docker.com/r/claranet/datadog-terraform) on every platforms + +With this command run from the root of the repository you will get exactly the same execution as the pipeline (and so the same result also): ``` - docker run --rm -v "$PWD:/work" claranet/datadog-terraform /work/scripts/auto_update.sh ./ + docker run --rm -v "$PWD:/work" claranet/datadog-terraform /work/scripts/auto_update.sh ``` ## Important notes ## diff --git a/scripts/01_update_output.sh b/scripts/01_update_output.sh index eb0167f..593e7a1 100755 --- a/scripts/01_update_output.sh +++ b/scripts/01_update_output.sh @@ -5,7 +5,7 @@ source "$(dirname $0)/utils.sh" goto_root # loop over every monitors set -for path in $(find "$(get_scope $1)" -name 'monitors-*.tf' -print | sort -fdbi); do +for path in $(find "$(get_scope ${1-})" -name 'monitors-*.tf' -print | sort -fdbi); do cd $(dirname $path) # empty outputs > outputs.tf diff --git a/scripts/02_update_readme.sh b/scripts/02_update_readme.sh index d4ae053..dff0358 100755 --- a/scripts/02_update_readme.sh +++ b/scripts/02_update_readme.sh @@ -36,7 +36,7 @@ done PATTERN_DOC="Related documentation" # loop over every monitors set readme -for path in $(find "$(get_scope $1)" -name 'monitors-*.tf' -print | sort -fdbi); do +for path in $(find "$(get_scope ${1-})" -name 'monitors-*.tf' -print | sort -fdbi); do cd $(dirname $path) EXIST=0 if [ -f README.md ]; then diff --git a/scripts/03_update_module.sh b/scripts/03_update_module.sh index 6941230..0c8e05b 100755 --- a/scripts/03_update_module.sh +++ b/scripts/03_update_module.sh @@ -6,8 +6,10 @@ goto_root root=$(basename ${PWD}) +echo "$(get_scope ${1-})" +exit # loop over every monitors set -for path in $(find "$(get_scope $1)" -name 'monitors-*.tf' -print | sort -fdbi); do +for path in $(find "$(get_scope ${1-})" -name 'monitors-*.tf' -print | sort -fdbi); do cd $(dirname $path) # get name of the monitors set directory resource="$(basename $(dirname $path))" diff --git a/scripts/90_best_practices.sh b/scripts/90_best_practices.sh index a44afb5..4f41514 100755 --- a/scripts/90_best_practices.sh +++ b/scripts/90_best_practices.sh @@ -5,7 +5,7 @@ source "$(dirname $0)/utils.sh" goto_root # loop over every monitors set -for path in $(find "$(get_scope $1)" -name 'monitors-*.tf' -print | sort -fdbi); do +for path in $(find "$(get_scope ${1-})" -name 'monitors-*.tf' -print | sort -fdbi); do # check if there is more than 1 notify_no_data parameter set to true per set of monitors if [[ $(grep -c notify_no_data.*true $path) -gt 1 ]]; then echo "More than one notify_no_data set to true on $path" diff --git a/scripts/99_terraform.sh b/scripts/99_terraform.sh index c9a746e..16e5d37 100755 --- a/scripts/99_terraform.sh +++ b/scripts/99_terraform.sh @@ -6,7 +6,7 @@ goto_root provider_version=$(grep ^[[:space:]]*version[[:space:]]= README.md | awk '{print $3}') -for path in $(find "$(get_scope $1)" -name 'inputs.tf' -print); do +for path in $(find "$(get_scope ${1-})" -name 'inputs.tf' -print); do dir=$(dirname ${path}) cat < ${dir}/tmp.tf provider "datadog" { diff --git a/scripts/auto_update.sh b/scripts/auto_update.sh index 901e1eb..572bb6b 100755 --- a/scripts/auto_update.sh +++ b/scripts/auto_update.sh @@ -9,5 +9,5 @@ source "$(dirname $0)/utils.sh" cd $(dirname $0) for script in [0-9][0-9]_*.sh; do - ./${script} "$(get_scope $1)" + ./${script} "$(get_scope ${1-})" done diff --git a/scripts/utils.sh b/scripts/utils.sh index fae414a..084e8f3 100755 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -10,10 +10,13 @@ function goto_root { } function get_scope { - TO_PARSE="." - if [ ! -z ${1+x} ]; then + TO_PARSE="./" + if [ ! -z ${1+x} ] && [ $1 != "." ]; then TO_PARSE="$1" fi + if [[ $TO_PARSE != ./* ]]; then + TO_PARSE="./${TO_PARSE}" + fi echo $TO_PARSE }