diff --git a/.github/workflows/helm-charts.yaml b/.github/workflows/helm-charts.yaml index e1885fb5..8b66bafc 100644 --- a/.github/workflows/helm-charts.yaml +++ b/.github/workflows/helm-charts.yaml @@ -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 @@ -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 @@ -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) }} @@ -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 diff --git a/bin/list-charts b/bin/list-charts new file mode 100755 index 00000000..0eb7271d --- /dev/null +++ b/bin/list-charts @@ -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/'