Skip to content

Commit

Permalink
feat: Add checker to ensure that env variable doc is up to date (#5091)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Behar <simbeh7@gmail.com>
  • Loading branch information
simster7 authored Feb 13, 2021
1 parent 210080a commit 19b22f2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ codegen: \
go generate ./persist/sqldb ./pkg/apiclient/workflow ./server/auth ./server/auth/sso ./workflow/executor
rm -Rf vendor
go mod tidy
./hack/check-env-doc.sh

$(GOPATH)/bin/mockery:
./hack/recurl.sh dist/mockery.tar.gz https://github.com/vektra/mockery/releases/download/v1.1.1/mockery_1.1.1_$(shell uname -s)_$(shell uname -m).tar.gz
Expand Down
2 changes: 2 additions & 0 deletions docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Note that these environment variables may be removed at any time.
| `TRANSIENT_ERROR_PATTERN` | `string` | The regular expression that represents additional patterns for transient errors. |
| `WF_DEL_PROPAGATION_POLICY` | `string` | The deletion propogation policy for workflows. |
| `WORKFLOW_GC_PERIOD` | `time.Duration` | The periodicity for GC of workflows. |
| `BUBBLE_ENTRY_TEMPLATE_ERR` | `bool` | Whether to bubble up template errors to workflow. Default true |
| `INFORMER_WRITE_BACK` | `bool` | Whether to write back to informer instead of catching up. Deafult true |

## Executor

Expand Down
33 changes: 33 additions & 0 deletions hack/check-env-doc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

echo "Checking docs/environment-variables.md for completeness..."

function check-used {
grep "| \`" < ./docs/environment-variables.md \
| awk '{gsub(/\`/, "", $2); print $2; }' \
| while read -r x; do
var="${x%\`}";
var="${var#\`}";
if ! grep -qR --exclude="*_test.go" "$var" ./workflow ./persist ./util; then
echo "Documented variable $var in docs/environment-variables.md is not used anywhere";
exit 1;
fi;
done
}

function check-documented {
grep -REh --exclude="*_test.go" "Getenv.*?\(|LookupEnv.*?\(" ./workflow ./persist ./util \
| grep -Eo "\"[A-Z_]+?\"" \
| sort \
| uniq \
| while read -r x; do
var="${x%\"}";
var="${var#\"}";
if ! grep -q "$var" docs/environment-variables.md; then
echo "Variable $var not documented in docs/environment-variables.md";
exit 1;
fi;
done
}

check-used && check-documented && echo "Success!"

0 comments on commit 19b22f2

Please sign in to comment.