Skip to content

Commit

Permalink
Automatically generate protobuf documentation.
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Littley <[email protected]>
  • Loading branch information
cody-littley committed Dec 2, 2024
1 parent e8ffa50 commit 1b936df
Show file tree
Hide file tree
Showing 13 changed files with 5,599 additions and 1,566 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ clean:
# Builds the protobuf files inside a docker container.
protoc: clean
./api/builder/protoc-docker.sh
./api/builder/generate-docs.sh

# Builds the protobuf files locally (i.e. without docker).
protoc-local: clean
Expand Down
48 changes: 48 additions & 0 deletions api/builder/generate-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

# This script generates protobuf documentation.

# The location where this script can be found.
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

API_DIR="${SCRIPT_DIR}/.."
PROTO_DIR="${API_DIR}/proto"
DOCS_DIR="${API_DIR}/docs"

# Function to get the relative path of file in argument 1 with respect directory in argument 2.
# Doesn't use the convenient 'realpath --relative-to' because it's not available on macOS.
relativePath() {
python3 -c 'import os.path, sys; print(os.path.relpath(sys.argv[1],sys.argv[2]))' "${1}" "${2}"
}

# Find all .proto files.
PROTO_FILES=( $(find "${PROTO_DIR}" -name '*.proto') )

# Make the proto files relative to the proto directory.
for i in "${!PROTO_FILES[@]}"; do
PROTO_FILES[$i]=$(relativePath "${PROTO_FILES[$i]}" "${PROTO_DIR}")
done

# Generate HTML doc
docker run --rm \
-v "${DOCS_DIR}":/out \
-v "${PROTO_DIR}":/protos \
pseudomuto/protoc-gen-doc \
"${PROTO_FILES[@]}" \
--doc_opt=html,eigenda-protos.html

if [ $? -ne 0 ]; then
exit 1
fi

# Generate markdown doc
docker run --rm \
-v "${DOCS_DIR}":/out \
-v "${PROTO_DIR}":/protos \
pseudomuto/protoc-gen-doc \
"${PROTO_FILES[@]}" \
--doc_opt=markdown,eigenda-protos.md

if [ $? -ne 0 ]; then
exit 1
fi
6 changes: 0 additions & 6 deletions api/docs/README.md

This file was deleted.

144 changes: 0 additions & 144 deletions api/docs/churner.md

This file was deleted.

Loading

0 comments on commit 1b936df

Please sign in to comment.