mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
Run terraform_docs only if README.md is present
This commit is contained in:
parent
97a668640d
commit
8e03aec3d5
1 changed files with 7 additions and 2 deletions
|
|
@ -19,19 +19,24 @@ for file_with_path in "$@"; do
|
||||||
done
|
done
|
||||||
|
|
||||||
readonly tmp_file="tmp_$(date | md5).txt"
|
readonly tmp_file="tmp_$(date | md5).txt"
|
||||||
|
readonly text_file="README.md"
|
||||||
|
|
||||||
for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
|
for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
|
||||||
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"
|
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"
|
||||||
|
|
||||||
pushd "$path_uniq" > /dev/null
|
pushd "$path_uniq" > /dev/null
|
||||||
|
|
||||||
|
if [[ ! -f "$text_file" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
terraform-docs md ./ > "$tmp_file"
|
terraform-docs md ./ > "$tmp_file"
|
||||||
|
|
||||||
# Replace content between markers with the placeholder - http://fahdshariff.blogspot.no/2012/12/sed-mutli-line-replacement-between-two.html
|
# Replace content between markers with the placeholder - http://fahdshariff.blogspot.no/2012/12/sed-mutli-line-replacement-between-two.html
|
||||||
sed -i -n '/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/{p;:a;N;/END OF PRE-COMMIT-TERRAFORM DOCS HOOK/!ba;s/.*\n/I_WANT_TO_BE_REPLACED\n/};p' README.md
|
sed -i -n '/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/{p;:a;N;/END OF PRE-COMMIT-TERRAFORM DOCS HOOK/!ba;s/.*\n/I_WANT_TO_BE_REPLACED\n/};p' "$text_file"
|
||||||
|
|
||||||
# Replace placeholder with the content of the file - https://stackoverflow.com/a/31057013/550451
|
# Replace placeholder with the content of the file - https://stackoverflow.com/a/31057013/550451
|
||||||
sed -i -e "/I_WANT_TO_BE_REPLACED/r $tmp_file" -e "//d" README.md
|
sed -i -e "/I_WANT_TO_BE_REPLACED/r $tmp_file" -e "//d" "$text_file"
|
||||||
|
|
||||||
rm -f "$tmp_file"
|
rm -f "$tmp_file"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue