Skip to content

Commit

Permalink
adjust CRD docs generator script to account for metrics API
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Wiesinger <[email protected]>
  • Loading branch information
mowies committed Apr 18, 2023
1 parent cfa4486 commit d2dd417
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions .github/scripts/generate-crd-docs/generate-crd-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
# renovate: datasource=github-releases depName=elastic/crd-ref-docs
GENERATOR_VERSION=master
API_DOMAIN="keptn.sh"
API_ROOT='operator/apis/'
OPERATOR_API_ROOT='operator/apis/'
METRICS_API_ROOT='metrics-operator/api/'
TEMPLATE_DIR='.github/scripts/generate-crd-docs/templates'
RENDERER='markdown'
RENDERER_CONFIG_FILE='.github/scripts/generate-crd-docs/crd-docs-generator-config.yaml'
Expand All @@ -25,8 +26,8 @@ fi

echo "Running CRD docs auto-generator..."

for api_group in "$API_ROOT"*; do
sanitized_api_group="${api_group#$API_ROOT}"
for api_group in "$OPERATOR_API_ROOT"*; do
sanitized_api_group="${api_group#$OPERATOR_API_ROOT}"
INDEX_PATH="./docs/content/en/docs/crd-ref/$sanitized_api_group/_index.md"

if [ ! -f "$INDEX_PATH" ]; then
Expand All @@ -39,13 +40,13 @@ for api_group in "$API_ROOT"*; do
fi

for api_version in "$api_group"/*; do
sanitized_api_version="${api_version#$API_ROOT$sanitized_api_group/}"
sanitized_api_version="${api_version#$OPERATOR_API_ROOT$sanitized_api_group/}"

OUTPUT_PATH="./docs/content/en/docs/crd-ref/$sanitized_api_group/$sanitized_api_version"

echo "Arguments:"
echo "TEMPLATE_DIR: $TEMPLATE_DIR"
echo "API_ROOT: $API_ROOT"
echo "OPERATOR_API_ROOT: $OPERATOR_API_ROOT"
echo "API_GROUP: $sanitized_api_group"
echo "API_VERSION: $sanitized_api_version"
echo "RENDERER: $RENDERER"
Expand All @@ -65,3 +66,43 @@ for api_group in "$API_ROOT"*; do
echo "---------------------"
done
done

# Metrics API
sanitized_api_group="metrics"
INDEX_PATH="./docs/content/en/docs/crd-ref/$sanitized_api_group/_index.md"

if [ ! -f "$INDEX_PATH" ]; then
echo "API group index file doesn't exist for group $sanitized_api_group. Creating it now..."
# Use sanitized_api_group and make first char uppercase
API_GROUP="$(tr '[:lower:]' '[:upper:]' <<< "${sanitized_api_group:0:1}")${sanitized_api_group:1}"
export API_GROUP
envsubst < './.github/scripts/generate-crd-docs/templates/index-template.md' > "$INDEX_PATH"
unset API_GROUP
fi

for api_version in "$METRICS_API_ROOT"*; do
sanitized_api_version="${api_version#$METRICS_API_ROOT}"

OUTPUT_PATH="./docs/content/en/docs/crd-ref/$sanitized_api_group/$sanitized_api_version"

echo "Arguments:"
echo "TEMPLATE_DIR: $TEMPLATE_DIR"
echo "METRICS_API_ROOT: $METRICS_API_ROOT"
echo "API_GROUP: $sanitized_api_group"
echo "API_VERSION: $sanitized_api_version"
echo "RENDERER: $RENDERER"
echo "RENDERER_CONFIG_FILE: $RENDERER_CONFIG_FILE"
echo "OUTPUT_PATH: $OUTPUT_PATH/_index.md"

echo "Creating docs folder $OUTPUT_PATH..."
mkdir -p "$OUTPUT_PATH"

echo "Generating CRD docs for $sanitized_api_group.$API_DOMAIN/$sanitized_api_version..."
crd-ref-docs \
--templates-dir "$TEMPLATE_DIR" \
--source-path="./$api_version" \
--renderer="$RENDERER" \
--config "$RENDERER_CONFIG_FILE" \
--output-path "$OUTPUT_PATH/_index.md"
echo "---------------------"
done

0 comments on commit d2dd417

Please sign in to comment.