charts/.github/scripts/gen-helm-docs.sh

48 lines
1.5 KiB
Bash
Raw Permalink Normal View History

2021-02-17 22:43:56 +00:00
#!/usr/bin/env bash
set -eu
# Generate helm-docs for Helm charts
2021-03-18 15:48:27 +00:00
# Usage ./gen-helm-docs.sh [stable/incubator] [chart]
# require helm-docs
command -v helm-docs >/dev/null 2>&1 || {
echo >&2 "helm-docs (https://github.com/k8s-at-home/helm-docs) is not installed. Aborting."
exit 1
}
2021-02-17 22:43:56 +00:00
# Absolute path of repository
repository=$(git rev-parse --show-toplevel)
# Templates to copy into each chart directory
readme_template="${repository}/hack/templates/README.md.gotmpl"
readme_config_template="${repository}/hack/templates/README_CONFIG.md.gotmpl"
# Gather all charts using the common library, excluding common-test
2021-03-18 15:48:27 +00:00
charts=$(find "${repository}" -name "Chart.yaml")
2021-02-17 22:43:56 +00:00
# Allow for a specific chart to be passed in as a argument
2021-03-18 15:48:27 +00:00
if [ $# -ge 1 ] && [ -n "$1" ] && [ -n "$2" ]; then
charts="${repository}/charts/$1/$2/Chart.yaml"
root="$(dirname "${charts}")"
if [ ! -f "$charts" ]; then
echo "File ${charts} does not exist."
exit 1
fi
else
root="${repository}/charts/stable"
fi
2021-02-17 22:43:56 +00:00
for chart in ${charts}; do
chart_directory="$(dirname "${chart}")"
echo "-] Copying templates to ${chart_directory}"
# Copy CONFIG template to each Chart directory, do not overwrite if exists
2021-02-17 22:43:56 +00:00
cp -n "${readme_config_template}" "${chart_directory}" || true
done
# Run helm-docs for charts using the common library and the common library itself
helm-docs \
--ignore-file="${repository}/.helmdocsignore" \
--template-files="${readme_template}" \
2021-02-17 22:43:56 +00:00
--template-files="$(basename "${readme_config_template}")" \
--chart-search-root="${root}"