-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvalidate.sh
78 lines (69 loc) · 2.52 KB
/
validate.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
#!/bin/bash
WORKING_DIRECTORY="$PWD"
GITHUB_PAGES_REPO=$1
PR_NUMBER=$2
GITHUB_BRANCH=$3
[ "$GITHUB_PAGES_REPO" ] || {
echo "ERROR: Environment variable GITHUB_PAGES_REPO is required"
exit 1
}
[ "$PR_NUMBER" ] || {
echo "ERROR: Environment variable PR_NUMBER is required"
exit 0
}
# Get labels from github-api and deserialize response using jq and sed
LABELS=$(curl -s 'https://api.github.com/repos/'"${GITHUB_PAGES_REPO}"'/issues/'"${PR_NUMBER}"'/labels' | jq -r '.[] | .name' | sed 's/do not merge/do_not_merge/g') || {
echo "ERROR: curl failed to get response from github-api / failed to serialize data"
exit 1
}
if [ -z "$LABELS" ]; then
echo "ERROR: Github-api failed to return answer / no labels found"
exit 1
fi
[ -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
}
[ -z "$HELM_VERSION" ] && HELM_VERSION=2.16.7
[ "$GITHUB_BRANCH" ] || {
echo "ERROR: Environment variable GITHUB_BRANCH is required"
exit 1
}
echo "LABELS=$LABELS"
echo "PR_NUMBER=$PR_NUMBER"
echo "GITHUB_PAGES_REPO=$GITHUB_PAGES_REPO"
echo "GITHUB_PAGES_BRANCH=$GITHUB_PAGES_BRANCH"
echo "HELM_CHARTS_SOURCE=$HELM_CHARTS_SOURCE"
echo "HELM_VERSION=$HELM_VERSION"
echo "GITHUB_BRANCH=$GITHUB_BRANCH"
echo ">> Checking out $GITHUB_PAGES_BRANCH branch from $GITHUB_PAGES_REPO"
cd /tmp/helm/publish
mkdir -p "$HOME/.ssh"
git clone -b "${GITHUB_PAGES_BRANCH}" "https://github.com/${GITHUB_PAGES_REPO}.git"
cd helm-charts/
echo '>> Building charts and comparing with labels...'
sudo find "$HELM_CHARTS_SOURCE" -mindepth 1 -maxdepth 1 -type d | while read chart; do
chart_name="`basename "$chart"`"
for label in $LABELS; do
if [ $label = $chart_name ]; then
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 ">>> Error: CHART $chart_name VERSION $chart_version ALREADY EXISTS! Update chart version."
exit 1
else
echo ">>> chart version is valid, continuing..."
fi
else
echo ">>> skipped version check on $chart_name"
fi
done
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