forked from acryldata/datahub-helm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-charts.sh
executable file
·81 lines (68 loc) · 2.03 KB
/
package-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
#!/bin/bash
set -e
help ()
{
echo "package-charts - a script that packages a chart and updates the repository's chart index"
echo "USAGE"
echo -e "\t -o|--output REQUIRED <the relative path to where chart packages are stored>"
echo -e "\t -b|--branch REQUIRED <the branch to check changes against>"
echo -e "\t --dry-run OPTIONAL <checks if chart version has been packaged BUT does not package the chart if a version does not already exist>"
echo -e "\nExample:\n\t package-charts -c=./charts/fc-helm-dependencies -o=./releases"
}
for arg in "$@"
do
case $arg in
--dry-run)
DRY_RUN="true"
shift
;;
-o=*|--output=*)
RELEASE_LOCATION="${arg#*=}"
shift
;;
-b=*|--branch=*)
BRANCH="${arg#*=}"
shift
;;
-h|--help)
help
exit 0
shift
;;
esac
done
if [ -z $RELEASE_LOCATION ] || [ -z $BRANCH ] ; then
echo "please provide the correct number of arguments to this application."
help
exit 1
fi
CHARTS=()
for DIR in ./charts/*/; do
if ! git diff-index --quiet $BRANCH -- $DIR || [ -n "$(git ls-files -o -- $DIR)" ]; then
CHARTS+=($DIR)
fi
done
if [ ${#CHARTS[@]} -eq 0 ]; then
echo "no changes have been found - no need to check/package charts, exiting gracefully."
exit 0
fi
for CHART in "${CHARTS[@]}"; do
echo "detected changes in $CHART..."
VERSION=$(yq eval .version "$CHART/Chart.yaml")
NAME=$(yq eval .name "$CHART/Chart.yaml")
echo "found chart in $CHART - $NAME $VERSION."
echo "scanning for packaged releases with the version '$VERSION'..."
if find ./releases/$NAME-$VERSION.tgz 2>/dev/null; then
echo "ERROR: a release for $NAME under version $VERSION has already been packaged."
echo "please bump the version number of the chart within $CHART/Chart.yaml."
exit 1
fi
if [ ! -z $DRY_RUN ]; then
echo "DRY_RUN: would have packaged helm chart $NAME with version $VERSION"
continue
fi
helm package $CHART -d $RELEASE_LOCATION --version $VERSION
done
if [ -z $DRY_RUN ]; then
helm repo index ./
fi