Skip to content

Commit

Permalink
chore: remediate canary
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-FFFFFF committed Jan 25, 2024
1 parent f0ae58a commit d6f96cc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
31 changes: 29 additions & 2 deletions avm_scripts_canary/docs-check.sh
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
27 changes: 16 additions & 11 deletions avm_scripts_canary/docs-gen.sh
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 ..
6 changes: 3 additions & 3 deletions avm_scripts_canary/terrafmt.sh
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

0 comments on commit d6f96cc

Please sign in to comment.