forked from komodorio/helm-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.sh
executable file
·66 lines (58 loc) · 2.14 KB
/
publish.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
#!/bin/sh
set -ex
WORKING_DIRECTORY="$PWD"
[ "$GITHUB_PAGES_REPO" ] || {
echo "ERROR: Environment variable GITHUB_PAGES_REPO is required"
exit 1
}
[ -z "$GITHUB_PAGES_BRANCH" ] && GITHUB_PAGES_BRANCH=gh-pages
[ -z "$HELM_CHARTS_SOURCE" ] && HELM_CHARTS_SOURCE="$WORKING_DIRECTORY/charts"
[ -d "$HELM_CHARTS_SOURCE" ] || {
echo "ERROR: Could not find Helm charts in $HELM_CHARTS_SOURCE"
exit 1
}
[ "$BUILDKITE_BRANCH" ] || {
echo "ERROR: Environment variable CURRENT_BRANCH is required"
exit 1
}
echo "GITHUB_PAGES_REPO=$GITHUB_PAGES_REPO"
echo "GITHUB_PAGES_BRANCH=$GITHUB_PAGES_BRANCH"
echo "HELM_CHARTS_SOURCE=$HELM_CHARTS_SOURCE"
echo "BUILDKITE_BRANCH=$BUILDKITE_BRANCH"
echo ">> Checking out $GITHUB_PAGES_BRANCH branch from $GITHUB_PAGES_REPO"
rm -rf /tmp/helm/publish
mkdir -p /tmp/helm/publish && cd /tmp/helm/publish
mkdir -p "$HOME/.ssh"
ssh-keyscan -H github.com >> "$HOME/.ssh/known_hosts"
git clone -b "$GITHUB_PAGES_BRANCH" "[email protected]:$GITHUB_PAGES_REPO.git" .
echo '>> Building charts...'
find "$HELM_CHARTS_SOURCE" -mindepth 1 -maxdepth 1 -type d | while read chart; do
chart_name="`basename "$chart"`"
echo ">>> fetching chart $chart_name version"
chart_version=$(cat $chart/Chart.yaml | grep -oE "version:\s[0-9]+\.[0-9]+\.[0-9]+" | grep -oE "[0-9]+\.[0-9]+\.[0-9]+")
echo ">>> checking if version is already published"
if [ -f "$chart_name/$chart_name-$chart_version.tgz" ]; then
echo ">>> VERSION $chart_version ALREADY EXISTS! Skipping..."
continue
else
echo ">>> chart version is valid, continuing..."
fi
echo ">>> helm lint $chart"
helm lint "$chart"
echo ">>> helm package -d $chart_name $chart"
mkdir -p "$chart_name"
helm package -d "$chart_name" "$chart"
done
echo '>>> helm repo index'
helm repo index .
if [ "$BUILDKITE_BRANCH" != "master" ]; then
echo "Current branch is not master and do not publish"
exit 0
fi
echo ">> Publishing to $GITHUB_PAGES_BRANCH branch of $GITHUB_PAGES_REPO"
git config user.email "[email protected]"
git config user.name Buildkite
git add .
git status
git commit -m "Published by Buildkite $BUILDKITE_BUILD_URL"
git push origin "$GITHUB_PAGES_BRANCH"