-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0ae58a
commit d6f96cc
Showing
3 changed files
with
48 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
check_example_docs () { | ||
local dir=$1 | ||
echo "===> Generating examples documentation in $dir" | ||
cp "$dir/README.md" "$dir/README-generated.md" | ||
rm -f "$dir/.terraform.lock.hcl" | ||
terraform-docs -c ".terraform-docs.yml" "$dir" | ||
echo "===> Comparing examples documentation in $dir" | ||
if [ ! -z $(diff -q "$dir/README.md" "$dir/README-generated.md") ]; then | ||
echo "==> examples/$dir/README.md is out of date. Run 'make pre-commit' to update the generated document and commit." | ||
rm -f "$dir/README-generated.md" | ||
exit 1 | ||
fi | ||
rm -f "$dir/README-generated.md" | ||
} | ||
|
||
echo "==> Generating..." | ||
cp README.md README-generated.md | ||
|
||
rm -f .terraform.lock.hcl | ||
terraform-docs -c .terraform-docs.yml . | ||
|
||
echo "==> Comparing generated code to committed code..." | ||
diff -q README.md README-generated.md || \ | ||
(echo; echo "Unexpected difference in generated document. Run 'make pre-commit' to update the generated document and commit."; exit 1) | ||
if [ ! -z $(diff -q README.md README-generated.md) ]; then | ||
echo "==> README.md is out of date. Run 'make pre-commit' to update the generated document and commit." | ||
rm -f README-generated.md | ||
exit 1 | ||
fi | ||
|
||
cd examples | ||
subexamples=$(find ./ -maxdepth 1 -mindepth 1 -type d) | ||
for d in $subexamples; do | ||
check_example_docs $d | ||
done | ||
cd .. | ||
|
||
rm -f README-generated.md |
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 |
---|---|---|
@@ -1,18 +1,23 @@ | ||
#!/usr/bin/env bash | ||
|
||
generate_example_docs () { | ||
local dir=$1 | ||
echo "===> Generating examples documentation in $dir" | ||
rm -f "$dir/.terraform.lock.hcl" | ||
terraform-docs -c ".terraform-docs.yml" "$dir" | ||
} | ||
|
||
echo "==> Generating module documentation..." | ||
rm -f .terraform.lock.hcl | ||
terraform-docs -c .terraform-docs.yml . | ||
echo "==> Generating examples documentation..." | ||
examples=$(find ./examples -maxdepth 1 -mindepth 1 -type d) | ||
for d in $examples; do | ||
echo "===> Generating examples documentation in " $d | ||
cd $d | ||
rm -f .terraform.lock.hcl | ||
if [ -f "../.terraform-docs.yml" ]; then | ||
terraform-docs -c ../.terraform-docs.yml . | ||
else | ||
terraform-docs markdown table --output-file README.md --output-mode inject . | ||
fi | ||
|
||
if [ ! -d examples ]; then | ||
echo "==> Error - no examples directory found" | ||
exit 1 | ||
fi | ||
cd examples | ||
subexamples=$(find ./ -maxdepth 1 -mindepth 1 -type d) | ||
for d in $subexamples; do | ||
generate_example_docs $d | ||
done | ||
cd .. |
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
echo "==> Fixing test and document terraform blocks code with terrafmt..." | ||
|
||
files=$(find . -type f -name "*.md" -o -name "*.go" | grep -v -e ".github" -e "-terraform" -e "vendor" -e ".terraform" -e "README.md") | ||
files=$(find . -type f -name "*.md" -o -name "*.go" | grep -v -e ".github" -e "-terraform" -e "vendor" -e ".terraform" -e "README.md" -e "README-generated.md") | ||
for f in $files; do | ||
terrafmt fmt -f "$f" | ||
retValue=$? | ||
if [ $retValue -ne 0 ] && [ $retValue -ne 2 ]; then | ||
if [ $retValue -ne 0 ]; then | ||
echo "------------------------------------------------" | ||
echo "" | ||
echo "The preceding files contain terraform blocks that are not correctly formatted or contain errors." | ||
echo "" | ||
exit $retValue | ||
fi | ||
done | ||
done |