Skip to content

Commit

Permalink
fix: docs scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-FFFFFF committed Jan 25, 2024
1 parent 57cc51a commit 046a1e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
29 changes: 27 additions & 2 deletions avm_scripts/docs-check.sh
Original file line number Diff line number Diff line change
@@ -1,13 +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."; rm -f README-generated.md; 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
10 changes: 3 additions & 7 deletions avm_scripts/docs-gen.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#!/usr/bin/env bash

generate_docs () {
generate_example_docs () {
local dir=$1
echo "===> Generating examples documentation in $dir"
rm -f "$dir/.terraform.lock.hcl"
if [ -f ".terraform-docs.yml" ]; then
terraform-docs -c ".terraform-docs.yml" "$dir"
else
terraform-docs markdown table --output-file "README.md" --output-mode inject "$dir"
fi
terraform-docs -c ".terraform-docs.yml" "$dir"
}

echo "==> Generating module documentation..."
Expand All @@ -22,6 +18,6 @@ fi
cd examples
subexamples=$(find ./ -maxdepth 1 -mindepth 1 -type d)
for d in $subexamples; do
generate_docs $d
generate_example_docs $d
done
cd ..

0 comments on commit 046a1e2

Please sign in to comment.