Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add checker to ensure that env variable doc is up to date #5091

Merged
merged 12 commits into from
Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
simster7 marked this conversation as resolved.
Show resolved Hide resolved

## 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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add -o

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!"