[helm-docs] update script and create task (#608)

This commit is contained in:
ᗪєνιη ᗷυнʟ 2021-02-22 07:41:46 -05:00 committed by GitHub
parent 207c6de178
commit aa0786fcc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 11 deletions

View File

@ -18,30 +18,40 @@ tasks:
silent: true silent: true
dependency: dependency:
dir: "{{.GIT_ROOT}}/charts/{{.CHART}}"
cmds: cmds:
- test -d {{.GIT_ROOT}}/charts/{{.CHART}}/Chart.lock && rm {{.GIT_ROOT}}/charts/{{.CHART}}/Chart.lock || exit 0 - test -d Chart.lock && rm Chart.lock || exit 0
- test -d {{.GIT_ROOT}}/charts/{{.CHART}}/tmpcharts && rm -rf {{.GIT_ROOT}}/charts/{{.CHART}}/tmpcharts || exit 0 - test -d tmpcharts && rm -rf tmpcharts || exit 0
- cd {{.GIT_ROOT}}/charts/{{.CHART}} && helm dependency update - helm dependency update
silent: true silent: true
lint: lint:
desc: lint your chart code desc: lint your chart code
dir: "{{.GIT_ROOT}}/charts/{{.CHART}}"
cmds: cmds:
- cd {{.GIT_ROOT}}/charts/{{.CHART}} && helm lint - helm lint
deps: deps:
- dependency - dependency
- check-chart - check-chart
ct-lint: ct-lint:
desc: Run `ct lint` on your chart code desc: run `ct lint` on your chart code
cmds: cmds:
- docker run --rm -it --user $(id -u):$(id -g) -e "HELM_CONFIG_HOME=/tmp/helm" -e "HELM_CACHE_HOME=/tmp/helm" -v {{.GIT_ROOT}}:/ci -w /ci quay.io/helmpack/chart-testing:latest ct lint --charts charts/{{.CHART}} --config /ci/.github/ct.yaml - docker run --rm -it --user $(id -u):$(id -g) -e "HELM_CONFIG_HOME=/tmp/helm" -e "HELM_CACHE_HOME=/tmp/helm" -v {{.GIT_ROOT}}:/ci -w /ci quay.io/helmpack/chart-testing:latest ct lint --charts charts/{{.CHART}} --config /ci/.github/ct.yaml
deps: deps:
- check-chart - check-chart
- lint - lint
helm-docs:
desc: generate helm-docs
dir: "{{.GIT_ROOT}}/hack"
cmds:
- ./gen-helm-docs.sh "{{.CHART}}"
deps:
- check-chart
# Checks Parameters # Checks Parameters
check-chart: check-chart:
cmds: cmds:
- cmd: test ! -z "{{.CHART}}" || (echo "Please define CHART parameter"; exit 1) - test ! -z "{{.CHART}}" || (echo "Please define CHART parameter"; exit 1)
silent: true silent: true

View File

@ -1,9 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eu set -eu
# # Generate helm-docs for Helm charts
# Generate helm-docs for Helm charts using the common library # Usage ./gen-helm-docs.sh [chart]
#
# require helm-docs
command -v helm-docs >/dev/null 2>&1 || {
echo >&2 "helm-docs is not installed. Aborting."
exit 1
}
# Absolute path of repository # Absolute path of repository
repository=$(git rev-parse --show-toplevel) repository=$(git rev-parse --show-toplevel)
@ -16,11 +21,24 @@ readme_changelog_template="${repository}/hack/templates/README_CHANGELOG.md.gotm
# Gather all charts using the common library, excluding common-test # Gather all charts using the common library, excluding common-test
charts=$(find "${repository}" -name "Chart.yaml" -exec grep --exclude="*common-test*" -l "\- name\: common" {} \;) charts=$(find "${repository}" -name "Chart.yaml" -exec grep --exclude="*common-test*" -l "\- name\: common" {} \;)
# Allow for a specific chart to be passed in as a argument
if [ $# -ge 1 ] && [ -n "$1" ]; then
charts="${repository}/charts/$1/Chart.yaml"
root="$(dirname "${charts}")"
if [ ! -f "$charts" ]; then
echo "File ${charts} does not exist."
exit 1
fi
else
root="${repository}"
fi
for chart in ${charts}; do for chart in ${charts}; do
chart_directory="$(dirname "${chart}")" chart_directory="$(dirname "${chart}")"
echo "-] Copying templates to ${chart_directory}"
# Copy README template into each Chart directory, overwrite if exists # Copy README template into each Chart directory, overwrite if exists
cp "${readme_template}" "${chart_directory}" cp "${readme_template}" "${chart_directory}"
# Copy CUSTOM_CONFIG template to each Chart directory, do not overwrite if exists # Copy CONFIG template to each Chart directory, do not overwrite if exists
cp -n "${readme_config_template}" "${chart_directory}" || true cp -n "${readme_config_template}" "${chart_directory}" || true
# Copy CHANGELOG template to each Chart directory, do not overwrite if exists # Copy CHANGELOG template to each Chart directory, do not overwrite if exists
cp -n "${readme_changelog_template}" "${chart_directory}" || true cp -n "${readme_changelog_template}" "${chart_directory}" || true
@ -32,4 +50,4 @@ helm-docs \
--template-files="$(basename "${readme_template}")" \ --template-files="$(basename "${readme_template}")" \
--template-files="$(basename "${readme_config_template}")" \ --template-files="$(basename "${readme_config_template}")" \
--template-files="$(basename "${readme_changelog_template}")" \ --template-files="$(basename "${readme_changelog_template}")" \
--chart-search-root="${repository}" --chart-search-root="${root}"