forked from apache/pulsar-helm-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·115 lines (96 loc) · 3.48 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
BINDIR=`dirname "$0"`
CHARTS_HOME=`cd ${BINDIR}/..;pwd`
CHARTS_PKGS=${CHARTS_HOME}/.chart-packages
CHARTS_INDEX=${CHARTS_HOME}/.chart-index
CHARTS_REPO=${CHARTS_REPO:-"https://pulsar.apache.org/charts/"}
OWNER=${OWNER:-apache}
REPO=${REPO:-pulsar-helm-chart}
PUBLISH_CHARTS=${PUBLISH_CHARTS:-"false"}
# hack/common.sh need this variable to be set
PULSAR_CHART_HOME=${CHARTS_HOME}
source ${CHARTS_HOME}/hack/common.sh
source ${CHARTS_HOME}/.ci/git.sh
# allow overwriting cr binary
CR="docker run -v ${CHARTS_HOME}:/cr quay.io/helmpack/chart-releaser:v${CR_VERSION} cr"
function release::ensure_dir() {
local dir=$1
if [[ -d ${dir} ]]; then
rm -rf ${dir}
fi
mkdir -p ${dir}
}
function release::find_changed_charts() {
local charts_dir=$1
echo $(git diff --find-renames --name-only "$latest_tag_rev" -- ${charts_dir} | cut -d '/' -f 2 | uniq)
}
function release::package_chart() {
local chart=$1
echo "Packaging chart '$chart'..."
helm package ${CHARTS_HOME}/charts/$chart --destination ${CHARTS_PKGS}
}
function release::upload_packages() {
${CR} upload --owner ${OWNER} --git-repo ${REPO} -t ${GITHUB_TOKEN} --package-path /cr/.chart-packages
}
function release::update_chart_index() {
${CR} index -o ${OWNER} -r ${REPO} -t "${GITHUB_TOKEN}" -c ${CHARTS_REPO} --index-path /cr/.chart-index --package-path /cr/.chart-packages
}
function release::git_setup() {
git config --global user.email "[email protected]"
git config --global user.name "Apache Pulsar Team"
}
function release::publish_charts() {
release::git_setup
git clone https://${GITHUB_TOKEN}@github.com/apache/pulsar
cd pulsar
git checkout asf-site
mkdir -p content/charts
cp --force ${CHARTS_INDEX}/index.yaml content/charts/index.yaml
git add content/charts/index.yaml
ls content/charts
git commit --message="Publish new charts to ${CHARTS_REPO}" --signoff
if [[ "x${PUBLISH_CHARTS}" == "xtrue" ]]; then
git push --set-upstream origin asf-site
else
git push --dry-run --set-upstream origin asf-site
fi
}
# install cr
# hack::ensure_cr
docker pull quay.io/helmpack/chart-releaser:v${CR_VERSION}
latest_tag=$(git::find_latest_tag)
echo "Latest tag: $latest_tag"
latest_tag_rev=$(git::get_revision "$latest_tag")
echo "$latest_tag_rev $latest_tag (latest tag)"
head_rev=$(git::get_revision HEAD)
echo "$head_rev HEAD"
if [[ "$latest_tag_rev" == "$head_rev" ]]; then
echo "Do nothing. Exiting ..."
exit
fi
release::ensure_dir ${CHARTS_PKGS}
release::ensure_dir ${CHARTS_INDEX}
for chart in $(release::find_changed_charts charts); do
release::package_chart ${chart}
done
release::upload_packages
release::update_chart_index
release::publish_charts