forked from falcosecurity/charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·91 lines (69 loc) · 2.45 KB
/
release.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
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
: "${GITHUB_TOKEN:?Environment variable GITHUB_TOKEN must be set}"
: "${CR_REPO_URL:?Environment variable CR_REPO_URL must be set}"
: "${GIT_USERNAME:?Environment variable GIT_USERNAME must be set}"
: "${GIT_REPOSITORY_NAME:?Environment variable GIT_REPOSITORY_NAME must be set}"
readonly REPO_ROOT="${REPO_ROOT:-$(git rev-parse --show-toplevel)}"
export CR_TOKEN="$GITHUB_TOKEN"
main() {
pushd "$REPO_ROOT" > /dev/null
echo "Fetching tags..."
git fetch --tags
echo "Fetching charts..."
local changed_charts=()
# iterate over all charts and skip those that already have a tag matching the current version
for chart_config in */Chart.yaml; do
local chart_name
local chart_ver
local tag
chart_name=$(awk '/^name: /{print $NF}' < "$chart_config" )
chart_ver=$(awk '/^version: /{print $NF}' < "$chart_config")
tag="${chart_name}-${chart_ver}"
if git rev-parse "$tag" >/dev/null 2>&1; then
echo "Chart '$chart_name': tag '$tag' already exists, skipping."
else
echo "Chart '$chart_name': new version '$chart_ver' detected."
changed_charts+=("$chart_name")
fi
done
# preparing dirs
rm -rf .cr-release-packages
mkdir -p .cr-release-packages
rm -rf .cr-index
mkdir -p .cr-index
# only release those charts for which a new version has been detected
if [[ -n "${changed_charts[*]}" ]]; then
for chart in "${changed_charts[@]}"; do
echo "Packaging chart '$chart'..."
package_chart "$chart"
done
release_charts
# the newly created GitHub releases may not be available yet; let's wait a bit to be sure.
sleep 5
update_index
else
echo "Nothing to do. No chart changes detected."
fi
popd > /dev/null
}
package_chart() {
local chart="$1"
helm package "$chart" --destination .cr-release-packages --dependency-update
}
release_charts() {
cr upload -o "$GIT_USERNAME" -r "$GIT_REPOSITORY_NAME"
}
update_index() {
cr index -o "$GIT_USERNAME" -r "$GIT_REPOSITORY_NAME" -c "$CR_REPO_URL"
git config user.email "[email protected]"
git config user.name "poiana"
git checkout gh-pages
cp --force .cr-index/index.yaml index.yaml
git add index.yaml
git commit --message="Update index.yaml" --signoff
git push origin gh-pages
}
main