Skip to content

Commit

Permalink
move trailing space checks to helm template based
Browse files Browse the repository at this point in the history
I don't know why I went with so very complex implementation before and hadn't thought of this :)

The prev impl didn't catch the cases were helm rendering was causing issues. This should catch all
  • Loading branch information
Kishan Sairam Adapa authored Jul 29, 2024
1 parent 3282781 commit 3c28bf2
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions validate-charts/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,19 @@ inputs:
runs:
using: "composite"
steps:
- name: validate helm chart
- name: Validate Helm Chart
shell: bash
run: |
helm version
helm dependency update ${{ inputs.chart-path }}
helm lint ${{ inputs.chart-path }} ${{ inputs.extra-args }}
helm template ${{ inputs.chart-path }} ${{ inputs.extra-args }}
- name: ensure no trailing spaces in config maps
- name: Ensure no Trailing Spaces
shell: bash
run: |
configmaps=($(find ${{ inputs.chart-path }} -type f -regex '.*\.ya*ml' -exec grep -l "kind: ConfigMap" {} \;))
COUNTER=0
echo "Checking these config maps for trailing spaces..."
for yaml in "${configmaps[@]}"
do
echo $yaml
# we have to use sed for performing exists check because of complications dealing with grep exit code in non match
exists=$(sed -nE '/\S\s+$/p' $yaml)
[ ! -z "$exists" ] && grep -nE '\S\s+$' $yaml && COUNTER=$((COUNTER+1))
done
test $COUNTER -gt 0 && echo "$COUNTER config map yamls contain trailing spaces, please remove them"
echo "Checking values.yaml for trailing spaces..."
# we have to use sed for performing exists check because of complications dealing with grep exit code in non match
exists=$(sed -nE '/\S\s+$/p' ${{ inputs.chart-path }}/values.yaml)
[ ! -z "$exists" ] && grep -nE '\S\s+$' ${{ inputs.chart-path }}/values.yaml && echo "^^^^^^ values.yaml has trailing spaces, please remove them" && exit 1
if (( $COUNTER > 0 )); then
exit 1
output=$(helm template ${{ inputs.chart-path }} ${{ inputs.extra-args }} | sed -nE '/\S\s+$/p')
if [ ! -z "$output" ]; then
echo "trailing spaces exist in helm chart after rending at below places, please fix:"
echo $output
fi

0 comments on commit 3c28bf2

Please sign in to comment.