-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcr.sh
executable file
·189 lines (163 loc) · 4.8 KB
/
cr.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env bash
# Based on work from https://github.com/helm/chart-releaser-action
# As the chart is already packaged, just uploading it
set -o errexit
set -o nounset
set -o pipefail
DEFAULT_CHART_RELEASER_VERSION=v1.4.1
main() {
local version="$DEFAULT_CHART_RELEASER_VERSION"
local config=
local chart_tar=
local owner=
local repo=
local charts_repo_url=
local install_dir=
local install_only=
parse_command_line "$@"
local repo_root
repo_root=$(git rev-parse --show-toplevel)
pushd "$repo_root" > /dev/null
install_chart_releaser
rm -rf .cr-release-packages
mkdir -p .cr-release-packages
cp $chart_tar .cr-release-packages/
echo "Release dir : `ls -la .cr-release-packages/`"
rm -rf .cr-index
mkdir -p .cr-index
update_index
popd > /dev/null
}
install_chart_releaser() {
if [[ ! -d "$RUNNER_TOOL_CACHE" ]]; then
echo "Cache directory '$RUNNER_TOOL_CACHE' does not exist" >&2
exit 1
fi
if [[ ! -d "$install_dir" ]]; then
mkdir -p "$install_dir"
echo "Installing chart-releaser on $install_dir..."
curl -sSLo cr.tar.gz "https://github.com/helm/chart-releaser/releases/download/$version/chart-releaser_${version#v}_linux_amd64.tar.gz"
tar -xzf cr.tar.gz -C "$install_dir"
rm -f cr.tar.gz
fi
echo 'Adding cr directory to PATH...'
export PATH="$install_dir:$PATH"
}
parse_command_line() {
while :; do
case "${1:-}" in
-h|--help)
show_help
exit
;;
--config)
if [[ -n "${2:-}" ]]; then
config="$2"
shift
else
echo "ERROR: '--config' cannot be empty." >&2
show_help
exit 1
fi
;;
-v|--version)
if [[ -n "${2:-}" ]]; then
version="$2"
shift
else
echo "ERROR: '-v|--version' cannot be empty." >&2
show_help
exit 1
fi
;;
-d|--chart-tar)
if [[ -n "${2:-}" ]]; then
chart_tar="$2"
shift
else
echo "ERROR: '-d|--chart-tar' cannot be empty." >&2
show_help
exit 1
fi
;;
-u|--charts-repo-url)
if [[ -n "${2:-}" ]]; then
charts_repo_url="$2"
shift
else
echo "ERROR: '-u|--charts-repo-url' cannot be empty." >&2
show_help
exit 1
fi
;;
-o|--owner)
if [[ -n "${2:-}" ]]; then
owner="$2"
shift
else
echo "ERROR: '--owner' cannot be empty." >&2
show_help
exit 1
fi
;;
-r|--repo)
if [[ -n "${2:-}" ]]; then
repo="$2"
shift
else
echo "ERROR: '--repo' cannot be empty." >&2
show_help
exit 1
fi
;;
-n|--install-dir)
if [[ -n "${2:-}" ]]; then
install_dir="$2"
shift
fi
;;
-i|--install-only)
if [[ -n "${2:-}" ]]; then
install_only="$2"
shift
fi
;;
*)
break
;;
esac
shift
done
if [[ -z "$owner" ]]; then
echo "ERROR: '-o|--owner' is required." >&2
show_help
exit 1
fi
if [[ -z "$repo" ]]; then
echo "ERROR: '-r|--repo' is required." >&2
show_help
exit 1
fi
if [[ -z "$charts_repo_url" ]]; then
charts_repo_url="https://$owner.github.io/$repo"
fi
if [[ -z "$install_dir" ]]; then
local arch
arch=$(uname -m)
install_dir="$RUNNER_TOOL_CACHE/cr/$version/$arch"
fi
if [[ -n "$install_only" ]]; then
echo "Will install cr tool and not run it..."
install_chart_releaser
exit 0
fi
}
update_index() {
local args=(-o "$owner" -r "$repo" -p ".cr-release-packages/" --release-name-template "{{ .Version }}" --push --pages-index-path "." --pages-branch "main" -i ".")
if [[ -n "$config" ]]; then
args+=(--config "$config")
fi
echo 'Updating charts repo index...'
cr index "${args[@]}"
}
main "$@"