forked from jfrog/charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint-charts.sh
executable file
·107 lines (100 loc) · 5.24 KB
/
lint-charts.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
readonly IMAGE_TAG=${CHART_TESTING_TAG}
readonly IMAGE_REPOSITORY="releases-docker.jfrog.io/charts-ci"
readonly REPO_ROOT="${REPO_ROOT:-$(git rev-parse --show-toplevel)}"
# shellcheck disable=SC2034 # This variable is used by the script get_helm.sh
readonly DESIRED_VERSION=${HELM_VERSION}
# shellcheck source=test/common.sh
source "${REPO_ROOT}/test/common.sh"
check_changelog_version() {
local changed_charts=("")
while IFS='' read -r line; do changed_charts+=("$line"); done < <(get_changed_charts)
echo "------------------------------------------------------------------------------------------------------------------------"
echo " Checking CHANGELOG!"
echo " Charts to be processed: ${changed_charts[*]}"
echo "------------------------------------------------------------------------------------------------------------------------"
for chart_name in ${changed_charts[*]} ; do
echo "==> Checking CHANGELOG for chart ${chart_name}"
echo "------------------------------------------------------------------------------------------------------------------------"
local chart_version
chart_version=$(grep "version:" "${REPO_ROOT}/${chart_name}/Chart.yaml" | cut -d" " -f 2)
## Check that the version has an entry in the changelog
if ! grep -q "\[${chart_version}\]" "${REPO_ROOT}/${chart_name}/CHANGELOG.md"; then
echo "No CHANGELOG entry for chart ${chart_name} version ${chart_version}"
exit 1
else
echo "Found CHANGELOG entry for chart ${chart_name} version ${chart_version}"
fi
done
echo "------------------------------------------------------------------------------------------------------------------------"
echo "Done CHANGELOG Check!"
echo "------------------------------------------------------------------------------------------------------------------------"
echo
}
validate_manifests() {
local changed_charts=("")
while IFS='' read -r line; do changed_charts+=("$line"); done < <(get_changed_charts)
echo "------------------------------------------------------------------------------------------------------------------------"
echo " Validating Manifests!"
echo " Charts to be processed: ${changed_charts[*]}"
echo "------------------------------------------------------------------------------------------------------------------------"
cd tmp
for chart_name in ${changed_charts[*]} ; do
echo "Validating chart ${chart_name}"
rm -rf stable
mkdir stable
pwd
helm template "${REPO_ROOT}/${chart_name}" --output-dir stable --set distribution.jfrogUrl=http://artifactory-artifactory.rt:8082,missionControl.jfrogUrl=http://artifactory-artifactory.rt:8082,pipelines.jfrogUrl=http://artifactory-artifactory.rt:8082,pipelines.jfrogUrlUI=http://artifactory-artifactory.rt:8082,xray.jfrogUrl=http://artifactory-artifactory.rt:8082,postgresql.postgresqlPassword=password > /dev/null 2>&1
TEMPLATE_FILES="${chart_name}/templates"
if [ -d "${TEMPLATE_FILES}" ]
then
echo "------------------------------------------------------------------------------------------------------------------------"
echo "==> Processing with default values..."
echo "------------------------------------------------------------------------------------------------------------------------"
# shellcheck disable=SC2086
kubeval -d ${TEMPLATE_FILES}
if [ -d "${REPO_ROOT}/${chart_name}/ci" ]
then
FILES="${REPO_ROOT}/${chart_name}/ci/*"
for file in $FILES
do
echo "------------------------------------------------------------------------------------------------------------------------"
echo "==> Processing with $file..."
echo "------------------------------------------------------------------------------------------------------------------------"
rm -rf stable
mkdir stable
helm template "${REPO_ROOT}/${chart_name}" -f "$file" --output-dir stable > /dev/null 2>&1
TEMPLATE_FILES="${chart_name}/templates/*"
# shellcheck disable=SC2086
kubeval ${TEMPLATE_FILES}
done
fi
fi
done
echo "------------------------------------------------------------------------------------------------------------------------"
echo "Done Manifests validating!"
echo
}
main() {
mkdir -p tmp
install_kubeval
install_helm
## git_fetch
# Lint helm charts
docker rm -f ct || true
# shellcheck disable=SC2086
docker run --rm -v "$(pwd):/workdir" --workdir /workdir "$IMAGE_REPOSITORY:$IMAGE_TAG" ct lint ${CHART_TESTING_ARGS} --config /workdir/test/ct.yaml --validate-maintainers=false | tee tmp/lint.log
echo "Done Charts Linting!"
echo
if [[ -z "${CHART_TESTING_ARGS}" ]]
then
# Check for changelog version
check_changelog_version | tee -a tmp/lint.log
# Validate Kubernetes manifests
validate_manifests | tee -a tmp/lint.log
fi
}
main