forked from kata-containers/packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag_repos.sh
executable file
·242 lines (207 loc) · 5.55 KB
/
tag_repos.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/bin/bash
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
set -o errexit
set -o nounset
set -o pipefail
tmp_dir=$(mktemp -d -t tag-repos-tmp.XXXXXXXXXX)
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
script_name="$(basename "${BASH_SOURCE[0]}")"
OWNER=${OWNER:-"kata-containers"}
PROJECT="Kata Containers"
PUSH="${PUSH:-"false"}"
branch="master"
readonly URL_RAW_FILE="https://raw.githubusercontent.com/${OWNER}"
#The runtime version is used as reference of latest release
# This is set to the right value later.
kata_version=""
# Set if a new stable branch is created
stable_branch=""
source "${script_dir}/../scripts/lib.sh"
function usage() {
cat <<EOT
Usage: ${script_name} [options] <args>
This script creates a new release for ${PROJECT}.
It tags and create release for:
EOT
for r in "${repos[@]}"; do
echo " - ${r}"
done
cat <<EOT
Args:
status : Get Current ${PROJECT} tags status
pre-release <target-version>: Takes a version to check all the components match with it (but not the runtime)
tag : Create tags for ${PROJECT}
Options:
-b <branch>: branch were will check the version.
-h : Show this help
-p : push tags
EOT
}
finish() {
rm -rf "$tmp_dir"
}
trap finish EXIT
die() {
echo >&2 "ERROR: $*"
exit 1
}
info() {
echo "INFO: $*"
}
repos=(
"agent"
"kata-containers"
"ksm-throttler"
"osbuilder"
"packaging"
"proxy"
"runtime"
"shim"
"tests"
)
# The pre-release option at the check_versions function receives
# the runtime VERSION in order to check all the components match with it,
# this has the purpose that all the components have the same version before
# merging the runtime version
check_versions() {
version_to_check=${1:-}
if [ -z "${version_to_check}" ];then
info "Query the version from latest runtime in branch ${branch}"
else
kata_version="${version_to_check}"
fi
info "Tagging ${PROJECT} with version ${kata_version}"
info "Check all repos has version ${kata_version} in VERSION file"
for repo in "${repos[@]}"; do
if [ ! -z "${version_to_check}" ] && [ "${repo}" == "runtime" ]; then
info "Not checking runtime because we want the rest of repos are in ${version_to_check}"
continue
fi
repo_version=$(curl -Ls "${URL_RAW_FILE}/${repo}/${branch}/VERSION" | grep -v -P "^#")
info "${repo} is in $repo_version"
[ "${repo_version}" == "${kata_version}" ] || die "${repo} is not in version ${kata_version}"
done
}
do_tag(){
local tag=${1:-}
[ -n "${tag}" ] || die "No tag not provided"
if git rev-parse -q --verify "refs/tags/${tag}"; then
info "$repo already has tag"
else
info "Creating tag ${tag} for ${repo}"
git tag -a "${tag}" -s -m "${PROJECT} release ${tag}"
fi
}
tag_repos() {
info "Creating tag ${kata_version} in all repos"
for repo in "${repos[@]}"; do
git clone --quiet "https://github.com/${OWNER}/${repo}.git"
pushd "${repo}" >>/dev/null
git remote set-url --push origin "[email protected]:${OWNER}/${repo}.git"
git fetch origin
git checkout "${branch}"
version_from_file=$(cat ./VERSION)
info "Check VERSION file has ${kata_version}"
if [ "${version_from_file}" != "${kata_version}" ];then
die "mismatch: VERSION file (${version_from_file}) and runtime version ${kata_version}"
else
echo "OK"
fi
git fetch origin --tags
tag="$kata_version"
if [[ "packaging" == "${repo}" ]];then
do_tag "${tag}-kernel-config"
fi
do_tag "${tag}"
if [ "${branch}" == "master" ]; then
if echo "${tag}" | grep -oP '.*-rc0$'; then
info "This is a rc0 for master - creating stable branch"
stable_branch=$(echo ${tag} | awk 'BEGIN{FS=OFS="."}{print $1 "." $2}')
stable_branch="stable-${stable_branch}"
info "creating branch ${stable_branch} for ${repo}"
git checkout -b "${stable_branch}" "${branch}"
fi
fi
popd >>/dev/null
done
}
push_tags() {
info "Pushing tags to repos"
build_hub
for repo in "${repos[@]}"; do
pushd "${repo}" >>/dev/null
tag="$kata_version"
if [[ "packaging" == "${repo}" ]];then
ktag="${tag}-kernel-config"
info "Push tag ${ktag} for ${repo}"
git push origin "${ktag}"
fi
info "Push tag ${tag} for ${repo}"
git push origin "${tag}"
create_github_release "${PWD}" "${tag}"
if [ "${stable_branch}" != "" ]; then
info "Pushing stable ${stable_branch} branch for ${repo}"
git push origin ${stable_branch}
fi
popd >>/dev/null
done
}
create_github_release() {
repo_dir=${1:-}
tag=${2:-}
[ -d "${repo_dir}" ] || die "No repository directory"
[ -n "${tag}" ] || die "No tag specified"
if ! "${hub_bin}" release show "${tag}"; then
info "Creating Github release"
if [[ "$tag" =~ "-rc" ]]; then
rc_args="-p"
fi
rc_args=${rc_args:-}
"${hub_bin}" -C "${repo_dir}" release create ${rc_args} -m "${PROJECT} ${tag}" "${tag}"
else
info "Github release already created"
fi
}
main () {
while getopts "b:hp" opt; do
case $opt in
b) branch="${OPTARG}" ;;
h) usage && exit 0 ;;
p) PUSH="true" ;;
esac
done
shift $((OPTIND - 1))
subcmd=${1:-""}
shift || true
kata_version=$(curl -Ls "${URL_RAW_FILE}/runtime/${branch}/VERSION" | grep -v -P "^#")
[ -z "${subcmd}" ] && usage && exit 0
pushd "${tmp_dir}" >>/dev/null
case "${subcmd}" in
status)
check_versions
;;
pre-release)
local target_version=${1:-}
[ -n "${target_version}" ] || die "No version provided"
check_versions "${target_version}"
;;
tag)
check_versions
tag_repos
if [ "${PUSH}" == "true" ]; then
push_tags
else
info "tags not pushed, use -p option to push the tags"
fi
;;
*)
usage && die "Invalid argument ${subcmd}"
;;
esac
popd >>/dev/null
}
main "$@"