diff --git a/.taskfiles/Taskfile_chart.yml b/.taskfiles/Taskfile_chart.yml index ef835a6f..c7cb6b51 100644 --- a/.taskfiles/Taskfile_chart.yml +++ b/.taskfiles/Taskfile_chart.yml @@ -18,30 +18,40 @@ tasks: silent: true dependency: + dir: "{{.GIT_ROOT}}/charts/{{.CHART}}" cmds: - - test -d {{.GIT_ROOT}}/charts/{{.CHART}}/Chart.lock && rm {{.GIT_ROOT}}/charts/{{.CHART}}/Chart.lock || exit 0 - - test -d {{.GIT_ROOT}}/charts/{{.CHART}}/tmpcharts && rm -rf {{.GIT_ROOT}}/charts/{{.CHART}}/tmpcharts || exit 0 - - cd {{.GIT_ROOT}}/charts/{{.CHART}} && helm dependency update + - test -d Chart.lock && rm Chart.lock || exit 0 + - test -d tmpcharts && rm -rf tmpcharts || exit 0 + - helm dependency update silent: true lint: desc: lint your chart code + dir: "{{.GIT_ROOT}}/charts/{{.CHART}}" cmds: - - cd {{.GIT_ROOT}}/charts/{{.CHART}} && helm lint + - helm lint deps: - dependency - check-chart ct-lint: - desc: Run `ct lint` on your chart code + desc: run `ct lint` on your chart code 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 deps: - check-chart - lint + + helm-docs: + desc: generate helm-docs + dir: "{{.GIT_ROOT}}/hack" + cmds: + - ./gen-helm-docs.sh "{{.CHART}}" + deps: + - check-chart # Checks Parameters check-chart: cmds: - - cmd: test ! -z "{{.CHART}}" || (echo "Please define CHART parameter"; exit 1) + - test ! -z "{{.CHART}}" || (echo "Please define CHART parameter"; exit 1) silent: true diff --git a/hack/gen-helm-docs.sh b/hack/gen-helm-docs.sh index a6df2706..1c96d4ba 100755 --- a/hack/gen-helm-docs.sh +++ b/hack/gen-helm-docs.sh @@ -1,9 +1,14 @@ #!/usr/bin/env bash set -eu -# -# Generate helm-docs for Helm charts using the common library -# +# Generate helm-docs for Helm charts +# 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 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 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 chart_directory="$(dirname "${chart}")" + echo "-] Copying templates to ${chart_directory}" # Copy README template into each Chart directory, overwrite if exists 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 # Copy CHANGELOG template to each Chart directory, do not overwrite if exists cp -n "${readme_changelog_template}" "${chart_directory}" || true @@ -32,4 +50,4 @@ helm-docs \ --template-files="$(basename "${readme_template}")" \ --template-files="$(basename "${readme_config_template}")" \ --template-files="$(basename "${readme_changelog_template}")" \ - --chart-search-root="${repository}" + --chart-search-root="${root}"