-
Notifications
You must be signed in to change notification settings - Fork 14
/
chart_version_check
executable file
·128 lines (108 loc) · 3.57 KB
/
chart_version_check
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2018-present Open Networking Foundation <info@opennetworking.org>
#
# SPDX-License-Identifier: Apache-2.0
# chart_version_check (taken from https://gerrit.opencord.org/plugins/gitiles/helm-repo-tools)
# checks that changes to a chart include a change to the chart version
set -u
echo "# chart_version_check, using git: $(git --version) #"
# Collect success/failure, and list/types of failures
fail_version=0
failed_charts=""
# when not running under Jenkins, use current dir as workspace
WORKSPACE=${WORKSPACE:-.}
# branch to compare against, defaults to master
COMPARISON_BRANCH="${COMPARISON_BRANCH:-opencord/master}"
echo "# Comparing with branch: $COMPARISON_BRANCH"
# Create list of changed files compared to branch
changed_files=$(git diff --name-only "${COMPARISON_BRANCH}")
# Create list of untracked by git files
untracked_files=$(git ls-files -o --exclude-standard)
# Print lists of files that are changed/untracked
if [ -z "$changed_files" ] && [ -z "$untracked_files" ]
then
echo "# chart_version_check.sh - No changes, Success! #"
exit 0
else
if [ -n "$changed_files" ]
then
echo "Changed files compared with $COMPARISON_BRANCH:"
# Search and replace per SC2001 doesn't recognize ^ (beginning of line)
# shellcheck disable=SC2001
echo "${changed_files}" | sed 's/^/ /'
fi
if [ -n "$untracked_files" ]
then
echo "Untracked files:"
# shellcheck disable=SC2001
echo "${untracked_files}" | sed 's/^/ /'
fi
fi
# combine lists
if [ -n "$changed_files" ]
then
if [ -n "$untracked_files" ]
then
changed_files+=$'\n'
changed_files+="${untracked_files}"
fi
else
changed_files="${untracked_files}"
fi
# For all the charts, fail on changes within a chart without a version change
# loop on result of 'find -name Chart.yaml'
while IFS= read -r -d '' chart
do
chartdir=$(dirname "${chart#${WORKSPACE}/}")
chart_changed_files=""
version_updated=0
# create a list of files that were changed in the chart
for file in $changed_files; do
if [[ $file =~ /tests/ ]]
then
# test files don't count for version checking
continue
fi
if [[ $file =~ ^$chartdir/ ]]
then
chart_changed_files+=$'\n'
chart_changed_files+=" ${file}"
fi
done
# See if chart version changed using 'git diff', and is SemVer
chart_yaml_diff=$(git diff -p "$COMPARISON_BRANCH" -- "${chartdir}/Chart.yaml")
if [ -n "$chart_yaml_diff" ]
then
echo "Changes to Chart.yaml in '$chartdir'"
old_version_string=$(echo "$chart_yaml_diff" | awk '/^\-version:/ { print $2 }')
new_version_string=$(echo "$chart_yaml_diff" | awk '/^\+version:/ { print $2 }')
if [ -n "$new_version_string" ]
then
version_updated=1
echo " Old version string:${old_version_string//-version:/}"
echo " New version string:${new_version_string//+version:/}"
fi
fi
# if there are any changed files
if [ -n "$chart_changed_files" ]
then
# and version updated, print changed files
if [ $version_updated -eq 1 ]
then
echo " Files changed:${chart_changed_files}"
else
# otherwise fail this chart
echo "Changes to chart but no version update in '$chartdir':${chart_changed_files}"
fail_version=1
failed_charts+=$'\n'
failed_charts+=" $chartdir"
fi
fi
done < <(find "${WORKSPACE}" -name Chart.yaml -print0)
if [[ $fail_version != 0 ]]; then
echo "# chart_version_check.sh Failure! #"
echo "Charts that need to be fixed:$failed_charts"
exit 1
fi
echo "# chart_version_check.sh Success! - all charts have updated versions #"
exit 0