blob: c068c28de7426fbfb9db8e127616cd8e618338d8 [file] [log] [blame]
Luca Prete1b823d62018-12-13 17:33:47 -08001#!/usr/bin/env bash
2
3# Copyright 2018-present Open Networking Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# helmlint.sh
18# run `helm lint` on all helm charts that are found
19
20set +e -o pipefail
21
22# verify that we have helm installed
23command -v helm >/dev/null 2>&1 || { echo "helm not found, please install it" >&2; exit 1; }
24
Zack Williams48542de2018-12-19 17:26:41 -070025echo "# helmlint.sh, using helm version: $(helm version -c --short) #"
Luca Prete1b823d62018-12-13 17:33:47 -080026
Zack Williams48542de2018-12-19 17:26:41 -070027# Collect success/failure, and list/types of failures
Luca Prete1b823d62018-12-13 17:33:47 -080028fail_lint=0
Zack Williams48542de2018-12-19 17:26:41 -070029failed_lint=""
30failed_req=""
Luca Prete1b823d62018-12-13 17:33:47 -080031
32# when not running under Jenkins, use current dir as workspace
33WORKSPACE=${WORKSPACE:-.}
34
35# cleanup repos if `clean` option passed as parameter
36if [ "$1" = "clean" ]
37then
Zack Williams48542de2018-12-19 17:26:41 -070038 echo "Removing any downloaded charts"
39 find "${WORKSPACE}" -type d -name 'charts' -exec rm -rf {} \;
Luca Prete1b823d62018-12-13 17:33:47 -080040fi
41
Zack Williams48542de2018-12-19 17:26:41 -070042# now that $1 is checked, error on undefined vars
43set -u
44
45# loop on result of 'find -name Chart.yaml'
Luca Prete1b823d62018-12-13 17:33:47 -080046while IFS= read -r -d '' chart
47do
48 chartdir=$(dirname "${chart}")
49
Zack Williams48542de2018-12-19 17:26:41 -070050 echo "Checking chart: $chartdir"
51
52 # update dependencies for profiles/workflows, as they include TOSCA from required charts
Luca Prete1b823d62018-12-13 17:33:47 -080053 if [[ $chartdir =~ xos-profiles || $chartdir =~ workflows ]] && [ -f "${chartdir}/requirements.yaml" ]
54 then
55 helm dependency update "${chartdir}"
56 fi
57
Zack Williams48542de2018-12-19 17:26:41 -070058 # lint the chart (with values.yaml if it exists)
Luca Prete1b823d62018-12-13 17:33:47 -080059 if [ -f "${chartdir}/values.yaml" ]; then
60 helm lint --strict --values "${chartdir}/values.yaml" "${chartdir}"
61 else
62 helm lint --strict "${chartdir}"
63 fi
64
65 rc=$?
66 if [[ $rc != 0 ]]; then
67 fail_lint=1
Zack Williams48542de2018-12-19 17:26:41 -070068 failed_lint+="${chartdir} "
Luca Prete1b823d62018-12-13 17:33:47 -080069 fi
Zack Williams48542de2018-12-19 17:26:41 -070070
71 # check that requirements are available if they're specified
72 if [ -f "${chartdir}/requirements.yaml" ]
73 then
74 echo "Chart has requirements.yaml, checking availability"
75 helm dependency update "${chartdir}"
76 rc=$?
77 if [[ $rc != 0 ]]; then
78 fail_lint=1
79 failed_req+="${chartdir} "
80 fi
81
82 # remove charts dir after checking for availability, as this chart might be
83 # required by other charts in the next loop
84 rm -rf "${chartdir}/charts"
85 fi
86
Luca Prete1b823d62018-12-13 17:33:47 -080087done < <(find "${WORKSPACE}" -name Chart.yaml -print0)
88
89if [[ $fail_lint != 0 ]]; then
Zack Williams48542de2018-12-19 17:26:41 -070090 echo "# helmlint.sh Failure! #"
91 echo "Charts that failed to lint: $failed_lint"
92 echo "Charts with failures in requirements.yaml: $failed_req"
Luca Prete1b823d62018-12-13 17:33:47 -080093 exit 1
94fi
95
Zack Williams48542de2018-12-19 17:26:41 -070096echo "# helmlint.sh Success! - all charts linted and have valid requirements.yaml #"
97
Luca Prete1b823d62018-12-13 17:33:47 -080098exit 0