add: devops scripts and configs
This commit is contained in:
Executable
+98
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Canonical resources+docs generator (template format).
|
||||
# Restores instruction-style docs structure (manual/example/params_create/params_modify/outputs/ops/params landing).
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ROOT_DIR="${ROOT_DIR:-$(cd "${SCRIPT_DIR}/.." && pwd)}"
|
||||
PROVIDER_DIR="${ROOT_DIR}/universal_rebuild"
|
||||
PROFILE_DIR="${PROFILE_DIR:-}"
|
||||
|
||||
resolve_root_path() {
|
||||
local path_value="$1"
|
||||
if [[ -z "$path_value" ]]; then
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
if [[ "$path_value" = /* ]]; then
|
||||
echo "$path_value"
|
||||
return
|
||||
fi
|
||||
echo "${ROOT_DIR}/${path_value}"
|
||||
}
|
||||
|
||||
if [[ "${1:-}" == "--profile" ]]; then
|
||||
PROFILE_DIR="${2:-}"
|
||||
shift 2
|
||||
fi
|
||||
|
||||
if [[ -n "$PROFILE_DIR" ]]; then
|
||||
if [[ ! -d "$PROFILE_DIR" ]]; then
|
||||
echo "Error: profile directory not found: $PROFILE_DIR" >&2
|
||||
exit 2
|
||||
fi
|
||||
PROFILE_ENV_FILE="${PROFILE_DIR}/profile.env"
|
||||
if [[ -f "$PROFILE_ENV_FILE" ]]; then
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
source "$PROFILE_ENV_FILE"
|
||||
set +a
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$PROFILE_DIR" ]]; then
|
||||
echo "Error: --profile <path> is required. Strict mode stores generated files per stand only." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
PROFILE_DIR="$(resolve_root_path "$PROFILE_DIR")"
|
||||
|
||||
RESOURCES_YAML_DIR_DEFAULT="${PROFILE_DIR}/generated/resources_yaml"
|
||||
DOCS_DIR_DEFAULT="${PROFILE_DIR}/generated/docs"
|
||||
SERVICES_LIST_PATH_DEFAULT="${PROFILE_DIR}/services_list.txt"
|
||||
GO_OUTPUT_DIR_DEFAULT="${PROFILE_DIR}/generated/go"
|
||||
|
||||
RESOURCES_YAML_DIR="${RESOURCES_YAML_DIR:-$RESOURCES_YAML_DIR_DEFAULT}"
|
||||
DOCS_DIR="${DOCS_DIR:-$DOCS_DIR_DEFAULT}"
|
||||
SERVICES_LIST_PATH="${SERVICES_LIST_PATH:-$SERVICES_LIST_PATH_DEFAULT}"
|
||||
GO_OUTPUT_DIR="${GO_OUTPUT_DIR:-$GO_OUTPUT_DIR_DEFAULT}"
|
||||
|
||||
RESOURCES_YAML_DIR="$(resolve_root_path "$RESOURCES_YAML_DIR")"
|
||||
DOCS_DIR="$(resolve_root_path "$DOCS_DIR")"
|
||||
SERVICES_LIST_PATH="$(resolve_root_path "$SERVICES_LIST_PATH")"
|
||||
GO_OUTPUT_DIR="$(resolve_root_path "$GO_OUTPUT_DIR")"
|
||||
|
||||
if [[ ! -d "$RESOURCES_YAML_DIR" ]]; then
|
||||
echo "Error: resources yaml directory not found: $RESOURCES_YAML_DIR" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ ! -f "$SERVICES_LIST_PATH" ]]; then
|
||||
echo "Error: services list not found: $SERVICES_LIST_PATH" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
cd "$PROVIDER_DIR"
|
||||
|
||||
echo "Generating resources from unified YAML specs..."
|
||||
TMP_GEN_DIR="$(mktemp -d)"
|
||||
trap 'rm -rf "$TMP_GEN_DIR"' EXIT
|
||||
|
||||
NUBES_RESOURCES_DIR="$RESOURCES_YAML_DIR" \
|
||||
NUBES_RESOURCES_GEN_DIR="$TMP_GEN_DIR" \
|
||||
go run ./tools/gen_v2
|
||||
|
||||
mkdir -p "$GO_OUTPUT_DIR"
|
||||
rm -rf "${GO_OUTPUT_DIR}"/*
|
||||
cp -R "$TMP_GEN_DIR/." "$GO_OUTPUT_DIR/"
|
||||
|
||||
echo "Generating docs via template generator..."
|
||||
mkdir -p "$DOCS_DIR"
|
||||
go run ./tools/docs_template_gen_v2 \
|
||||
-resources "$RESOURCES_YAML_DIR" \
|
||||
-docs "$DOCS_DIR" \
|
||||
-services "$SERVICES_LIST_PATH" \
|
||||
-exclude "clickhouse"
|
||||
|
||||
echo "Resources and docs generated in template format."
|
||||
Reference in New Issue
Block a user