Skip to content

Commit

Permalink
fix: work around chart-testing not supporting lib charts
Browse files Browse the repository at this point in the history
See helm/chart-testing#237.
Add an empty values file in the CI to library charts for the linter.
Exclude library charts for the installer.
  • Loading branch information
Wielewout committed Jun 27, 2023
1 parent bf6a3b5 commit 56eb2e1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/helm-charts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
is_pull_request: ${{ github.event_name == 'pull_request' }}
target_branch: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || github.ref_name }}
charts: ${{ steps.list-charts.outputs.charts }}
app_charts: ${{ steps.list-app-charts.outputs.charts }}
lib_charts: ${{ steps.list-lib-charts.outputs.charts }}
timeout-minutes: 1
steps:
- name: Expose variables
Expand All @@ -31,7 +33,15 @@ jobs:

- name: List charts
id: list-charts
run: echo "charts=$(ls -dm charts/*/ | tr -d ' ')" >> $GITHUB_OUTPUT
run: echo "charts=$(./bin/list-charts)" >> $GITHUB_OUTPUT

- name: List application charts
id: list-app-charts
run: echo "charts=$(./bin/list-charts -a)" >> $GITHUB_OUTPUT

- name: List library charts
id: list-lib-charts
run: echo "charts=$(./bin/list-charts -l)" >> $GITHUB_OUTPUT

lint-charts:
name: Lint Charts
Expand Down Expand Up @@ -75,6 +85,16 @@ jobs:
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Prepare library charts
if: ${{ steps.list-changed.outputs.changed == 'true' }}
run: |
lib_charts="${{ needs.vars.outputs.lib_charts }}"
for lc in "${lib_charts//,/ }" ; do
# Add values.yaml file so the linter doesn't complain
echo "${lc}/values.yaml"
touch "${lc}/values.yaml"
done
- name: Lint charts
if: ${{ steps.list-changed.outputs.changed == 'true' }}
run: ct lint --config etc/ct.yaml ${{ needs.vars.outputs.is_pull_request == 'true' && format('--target-branch {0}', needs.vars.outputs.target_branch) || format('--charts {0}', needs.vars.outputs.charts) }}
Expand Down Expand Up @@ -127,7 +147,7 @@ jobs:

- name: Test charts
if: ${{ steps.list-changed.outputs.changed == 'true' }}
run: ct install --config etc/ct.yaml ${{ needs.vars.outputs.is_pull_request == 'true' && format('--target-branch {0}', needs.vars.outputs.target_branch) || format('--charts {0}', needs.vars.outputs.charts) }}
run: ct install --config etc/ct.yaml ${{ needs.vars.outputs.is_pull_request == 'true' && format('--target-branch {0} --excluded-charts {1}', needs.vars.outputs.target_branch, needs.vars.outputs.lib_charts) || format('--charts {0}', needs.vars.outputs.app_charts) }}

release-charts:
name: Release Charts
Expand Down
53 changes: 53 additions & 0 deletions bin/list-charts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

GIT_ROOT=$(cd "$(dirname "$0")/.." && pwd)

function usage() {
echo "Usage:"
echo "list-charts"
echo " -h Display usage."
echo " -a List only application charts."
echo " -l List only library charts."
exit 0
}

function error() {
echo "${1}" 1>&2
exit 1
}

list_application_charts=false
list_library_charts=false

while getopts ":hal" opt; do
case ${opt} in
h )
usage
;;
a )
list_application_charts=true
;;
l )
list_library_charts=true
;;
\? )
error "Invalid Option: -${OPTARG}"
;;
esac
done
shift $((OPTIND -1))

if [[ "${list_application_charts}" == false && "${list_library_charts}" == false ]]; then
list_application_charts=true
list_library_charts=true
fi

if [[ "${list_application_charts}" == true && "${list_library_charts}" == true ]]; then
output=$(find "${GIT_ROOT}"/charts/ -type f -name 'Chart.yaml')
elif [[ "${list_application_charts}" == true ]]; then
output=$(find "${GIT_ROOT}"/charts/ -type f -name 'Chart.yaml' -exec sh -c 'yq -e '\''.type == "application"'\'' ${0} >/dev/null 2>&1 && echo ${0}' {} \;)
elif [[ "${list_library_charts}" == true ]]; then
output=$(find "${GIT_ROOT}"/charts/ -type f -name 'Chart.yaml' -exec sh -c 'yq -e '\''.type == "library"'\'' ${0} >/dev/null 2>&1 && echo ${0}' {} \;)
fi

echo "${output}" | sed -r 's|/[^/]+$||' | sort -u | sed -z 's/\n/,/g;s/,$/\n/'

0 comments on commit 56eb2e1

Please sign in to comment.