-
-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added terraform-docs integration (#13)
* Add hook to create readme * Updated README
- Loading branch information
1 parent
41d4951
commit 97a6686
Showing
4 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
declare -a paths | ||
declare -a tfvars_files | ||
|
||
index=0 | ||
|
||
for file_with_path in "$@"; do | ||
file_with_path="${file_with_path// /__REPLACED__SPACE__}" | ||
|
||
paths[index]=$(dirname "$file_with_path") | ||
|
||
if [[ "$file_with_path" == *".tfvars" ]]; then | ||
tfvars_files+=("$file_with_path") | ||
fi | ||
|
||
let "index+=1" | ||
done | ||
|
||
readonly tmp_file="tmp_$(date | md5).txt" | ||
|
||
for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do | ||
path_uniq="${path_uniq//__REPLACED__SPACE__/ }" | ||
|
||
pushd "$path_uniq" > /dev/null | ||
|
||
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 | ||
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 | ||
|
||
# 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 | ||
|
||
rm -f "$tmp_file" | ||
|
||
popd > /dev/null | ||
done |