forked from kubernetes-sigs/kwok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreleases-helm-charts.sh
executable file
·89 lines (71 loc) · 2.58 KB
/
releases-helm-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
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
# Copyright 2024 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
DIR="$(dirname "${BASH_SOURCE[0]}")"
ROOT_DIR="$(realpath "${DIR}/..")"
function blob_base() {
local tag=${1}
local repo
repo="$(gh repo view --json url --jq '.url')"
local url="${repo}/releases/download/${tag}"
echo "${url}"
}
function update_index() {
local index_dir="${1}"
local tag=${2}
local filepath="${3}"
if ! gh release view "${tag}" >/dev/null; then
echo "Please create release ${tag}"
exit 1
fi
gh release upload "${tag}" "${filepath}"
local url
url="$(blob_base "${tag}")"
helm repo index "${index_dir}" --merge "${index_dir}/index.yaml" --url "${url}"
}
function package_and_index() {
local index_dir="${1}"
local chart_dir="${2}"
local chart_alias="${3}"
local chart_name
local chart_version
local chart_app_version
chart_name="$(yq eval '.name' "${chart_dir}/Chart.yaml")"
chart_version="$(yq eval '.version' "${chart_dir}/Chart.yaml")"
chart_app_version="$(yq eval '.appVersion' "${chart_dir}/Chart.yaml")"
if yq -e eval ".entries.${chart_name}.[] | select(.version == \"${chart_version}\") | .version" "${index_dir}/index.yaml"; then
echo "Version ${chart_version} already exists"
return 0
fi
local guess_path="${index_dir}/${chart_name}-${chart_version}.tgz"
if [[ -f "${guess_path}" ]]; then
echo "File ${guess_path} already exists"
return 0
fi
helm package "${chart_dir}" --destination "${index_dir}"
if [[ "${chart_alias}" != "" ]]; then
local tmp_file="${index_dir}/${chart_alias}-${chart_version}.tgz"
mv "${guess_path}" "${tmp_file}"
guess_path="${tmp_file}"
fi
update_index "${index_dir}" "${chart_app_version}" "${guess_path}"
}
chart_dir="./charts"
index_dir="${ROOT_DIR}/site/static/charts"
package_and_index "${index_dir}" "${chart_dir}/kwok" "kwok-chart" || :
package_and_index "${index_dir}" "${chart_dir}/stage-fast" "kwok-stage-fast-chart" || :
package_and_index "${index_dir}" "${chart_dir}/metrics-usage" "kwok-metrics-usage-chart" || :