Skip to content

Commit 41f1422

Browse files
authored
Feature/update release scripts (#150)
* Add get_workspace_root function Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Move to workspace root before running release scripts Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Add delete_old_rc_branches.sh Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Cleanup Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
1 parent 3f731ed commit 41f1422

10 files changed

+105
-40
lines changed

scripts/release/common/helper_functions.sh

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/usr/bin/env bash
22

3+
function get_workspace_root() {
4+
git rev-parse --show-toplevel
5+
}
6+
37
function get_repos_file_path() {
4-
echo "$(git rev-parse --show-toplevel)/autoware.proj.repos"
8+
echo "$(get_workspace_root)/autoware.proj.repos"
59
}
610

711
function install_yq_if_not_installed() {
@@ -147,13 +151,13 @@ function update_workspace() {
147151
function update_version_in_repos() {
148152
repository="$1"
149153
if [ "$repository" = "" ]; then
150-
echo -e "Please input a repository name as the 1st argument"
154+
echo -e "Please input a repository name as the 1st argument."
151155
return 1
152156
fi
153157

154158
version="$2"
155159
if [ "$version" = "" ]; then
156-
echo -e "Please input a version as the 2nd argument"
160+
echo -e "Please input a version as the 2nd argument."
157161
return 1
158162
fi
159163

@@ -197,17 +201,17 @@ function create_branch() {
197201
git_command="git --work-tree=$repository --git-dir=$repository/.git"
198202

199203
if [ "$flag_delete" ]; then
200-
echo -e "Delete branch \"$branch_name\" in \"$repository\""
204+
echo -e "Delete branch \"$branch_name\" in \"$repository\"."
201205
$git_command checkout --detach --quiet HEAD
202206
$git_command branch -D --quiet "$branch_name"
203207
return 0
204208
fi
205209

206-
echo -e "Create branch \"$branch_name\" in \"$repository\""
210+
echo -e "Create branch \"$branch_name\" in \"$repository\"."
207211
$git_command checkout --quiet -b "$branch_name" || exit 1
208212

209213
if [ "$flag_push" ]; then
210-
echo -e "Push branch \"$branch_name\" to \"$repository\""
214+
echo -e "Push branch \"$branch_name\" to \"$repository\"."
211215
$git_command push origin "$branch_name"
212216
fi
213217

@@ -223,17 +227,17 @@ function create_tag() {
223227
git_command="git --work-tree=$repository --git-dir=$repository/.git"
224228

225229
if [ "$flag_delete" ]; then
226-
echo -e "Delete tag \"$version\" in \"$repository\""
230+
echo -e "Delete tag \"$version\" in \"$repository\"."
227231
$git_command tag -d "$version" > /dev/null
228232
return 0
229233
fi
230234

231-
echo -e "Create tag \"$version\" in \"$repository\""
235+
echo -e "Create tag \"$version\" in \"$repository\"."
232236
$git_command checkout --detach --quiet HEAD
233237
$git_command tag -a "$version" -m "$version" || exit 1
234238

235239
if [ "$flag_push" ]; then
236-
echo -e "Push tag \"$version\" to \"$repository\""
240+
echo -e "Push tag \"$version\" to \"$repository\"."
237241
$git_command push origin "$version"
238242
fi
239243

@@ -246,7 +250,7 @@ function checkout_branch_or_tag() {
246250

247251
git_command="git --work-tree=$repository --git-dir=$repository/.git"
248252

249-
echo -e "Checkout \"$branch_or_tag_name\" in \"$repository\""
253+
echo -e "Checkout \"$branch_or_tag_name\" in \"$repository\"."
250254
$git_command checkout --quiet "$branch_or_tag_name" || exit 1
251255

252256
return 0

scripts/release/common/parse_common_args.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,39 +40,39 @@ fi
4040

4141
if [ "$flag_yes" = "" ]; then
4242
if [ "$flag_change_reference_repositories" ]; then
43-
read -rp "You are going to change reference repositories. Do you really want to continue? [y/N] " answer
43+
read -rp "You are going to change reference repositories. Are you sure to continue? [y/N] " answer
4444

4545
case "$answer" in
4646
[yY]* )
4747
;;
4848
* )
49-
echo -e "\e[33mCanceled \e[0m"
49+
echo -e "\e[33mCanceled.\e[m"
5050
exit 1
5151
;;
5252
esac
5353
fi
5454

5555
if [ "$flag_push" ]; then
56-
read -rp "You are going to push branches or tags. Do you really want to continue? [y/N] " answer
56+
read -rp "You are going to push branches or tags. Are you sure to continue? [y/N] " answer
5757

5858
case "$answer" in
5959
[yY]* )
6060
;;
6161
* )
62-
echo -e "\e[33mCanceled \e[0m"
62+
echo -e "\e[33mCanceled.\e[m"
6363
exit 1
6464
;;
6565
esac
6666
fi
6767

6868
if [ "$flag_delete" ]; then
69-
read -rp "You are going to delete branches or tags. Do you really want to continue? [y/N] " answer
69+
read -rp "You are going to delete branches or tags. Are you sure to continue? [y/N] " answer
7070

7171
case "$answer" in
7272
[yY]* )
7373
;;
7474
* )
75-
echo -e "\e[33mCanceled \e[0m"
75+
echo -e "\e[33mCanceled.\e[m"
7676
exit 1
7777
;;
7878
esac

scripts/release/common/pre_common_tasks.sh

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# Install prerequisites
66
install_yq_if_not_installed
77

8+
# Move to workspace root
9+
cd "$(get_workspace_root)" || exit 1
10+
811
# Create src directory if not exist
912
if ! [ -d src ]; then
1013
mkdir -p src

scripts/release/create_experiment_branches.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ experiment_name="${args[0]}"
3636

3737
# Check args
3838
if ! is_valid_experiment_name "$experiment_name"; then
39-
echo -e "\e[31mPlease input a valid experiment branch name as the 1st argument\e[m"
39+
echo -e "\e[31mPlease input a valid experiment branch name as the 1st argument.\e[m"
4040
show_usage
4141
exit 1
4242
fi

scripts/release/create_product_rc_branches.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ function show_usage() {
2525
Whether to delete branches/tags. Please use this option when you mistook something.
2626
2727
reference_version:
28-
The version to be used for refecenfe rc branches.
28+
The version to be used for reference RC branches.
2929
The valid pattern is '^v([0-9]+)\.([0-9]+)\.([0-9]+)$'.
3030
3131
product_version:
32-
The version to be used for product rc branches.
32+
The version to be used for product RC branches.
3333
The valid pattern is '^v([0-9]+)\.([0-9]+)\.([0-9]+)$'.
3434
3535
Note: Using --push and --delete at the same time may cause unexpected behaviors."
@@ -42,13 +42,13 @@ product_version="${args[1]}"
4242

4343
# Check args
4444
if (! is_valid_reference_release_version "$reference_version") && (! is_rc_branch_name "$reference_version"); then
45-
echo -e "\e[31mPlease input a valid reference rc version as the 1st argument\e[m"
45+
echo -e "\e[31mPlease input a valid reference RC version as the 1st argument.\e[m"
4646
show_usage
4747
exit 1
4848
fi
4949

5050
if ! is_valid_product_rc_version "$product_version"; then
51-
echo -e "\e[31mPlease input a valid product rc version as the 2nd argument\e[m"
51+
echo -e "\e[31mPlease input a valid product RC version as the 2nd argument.\e[m"
5252
show_usage
5353
exit 1
5454
fi

scripts/release/create_product_release_tags.sh

+8-9
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,25 @@ source "$SCRIPT_DIR/common/parse_common_args.sh"
3939
reference_version="${args[0]}"
4040
product_version="${args[1]}"
4141

42-
# Check if using rc branches
43-
echo -e "\e[36mCheck if using rc branch\e[m"
44-
if ! is_on_corresponding_rc_branch "$product_version"; then
45-
echo -e "\e[31mPlease checkout corresponding rc branch for $product_version\e[m"
46-
exit 1
47-
fi
48-
4942
# Check args
5043
if ! is_valid_reference_release_version "$reference_version"; then
51-
echo -e "\e[31mPlease input a valid reference release version as the 1st argument\e[m"
44+
echo -e "\e[31mPlease input a valid reference release version as the 1st argument.\e[m"
5245
show_usage
5346
exit 1
5447
fi
5548

5649
if ! is_valid_product_release_version "$product_version"; then
57-
echo -e "\e[31mPlease input a valid product release version as the 2nd argument\e[m"
50+
echo -e "\e[31mPlease input a valid product release version as the 2nd argument.\e[m"
5851
show_usage
5952
exit 1
6053
fi
6154

55+
# Check if using RC branch
56+
if ! is_on_corresponding_rc_branch "$product_version"; then
57+
echo -e "\e[31mPlease checkout corresponding RC branch for $product_version.\e[m"
58+
exit 1
59+
fi
60+
6261
# Run pre common tasks
6362
source "$SCRIPT_DIR/common/pre_common_tasks.sh"
6463

scripts/release/create_reference_rc_branches.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function show_usage() {
2424
Whether to delete branches/tags. Please use this option when you mistook something.
2525
2626
reference_version:
27-
The version to be used for refecenfe rc branches.
27+
The version to be used for reference RC branches.
2828
The valid pattern is '^v([0-9]+)\.([0-9]+)\.([0-9]+)$'.
2929
3030
Note: Using --push and --delete at the same time may cause unexpected behaviors."
@@ -42,7 +42,7 @@ fi
4242

4343
# Check args
4444
if ! is_valid_reference_rc_version "$reference_version"; then
45-
echo -e "\e[31mPlease input a valid reference rc version as the 1st argument\e[m"
45+
echo -e "\e[31mPlease input a valid reference RC version as the 1st argument.\e[m"
4646
show_usage
4747
exit 1
4848
fi

scripts/release/create_reference_release_tags.sh

+7-8
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,24 @@ source "$SCRIPT_DIR/common/parse_common_args.sh"
3535
reference_version="${args[0]}"
3636
product_version="$reference_version" # Use reference version to product repositories as well
3737

38-
# Check if using rc branches
39-
echo -e "\e[36mCheck if using rc branch\e[m"
40-
if ! is_on_corresponding_rc_branch "$product_version"; then
41-
echo -e "\e[31mPlease checkout corresponding rc branch for $product_version\e[m"
42-
exit 1
43-
fi
44-
4538
# Set default values
4639
if [ "$flag_change_reference_repositories" = "" ]; then
4740
flag_change_reference_repositories=true
4841
fi
4942

5043
# Check args
5144
if ! is_valid_reference_release_version "$reference_version"; then
52-
echo -e "\e[31mPlease input a valid reference release version as the 1st argument\e[m"
45+
echo -e "\e[31mPlease input a valid reference release version as the 1st argument.\e[m"
5346
show_usage
5447
exit 1
5548
fi
5649

50+
# Check if using RC branch
51+
if ! is_on_corresponding_rc_branch "$product_version"; then
52+
echo -e "\e[31mPlease checkout corresponding RC branch for $product_version.\e[m"
53+
exit 1
54+
fi
55+
5756
# Run pre common tasks
5857
source "$SCRIPT_DIR/common/pre_common_tasks.sh"
5958

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR=$(readlink -f "$(dirname "$0")")
4+
source "$SCRIPT_DIR/common/helper_functions.sh"
5+
6+
# Define functions
7+
function delete_old_rc_branches() {
8+
repository="$1"
9+
git_command="git --work-tree=$repository --git-dir=$repository/.git"
10+
11+
# Show message
12+
echo -e "\e[32mDelete old RC branches in '$($git_command rev-parse --show-toplevel)'.\e[m"
13+
14+
# Iterate all branches
15+
for remote_branch_name in $($git_command branch -r); do
16+
branch_name=$(echo "$remote_branch_name" | sed "s/origin\///g")
17+
tag_name=$(echo "$branch_name" | sed "s/rc\///g")
18+
19+
# Ignore non-RC branches
20+
if ! is_rc_branch_name "$branch_name"; then
21+
continue
22+
fi
23+
24+
# Find the corresponding tag
25+
if ! $git_command rev-parse "$tag_name" >/dev/null 2>&1; then
26+
echo -e "\e[33mNo corresponding tag for $remote_branch_name was not found, skipping.\e[m"
27+
continue
28+
fi
29+
30+
# Show confirmation
31+
$git_command show --no-patch --no-notes --pretty=format:'%h %s%n%ad %aN%d' "origin/$branch_name"
32+
printf "\e[31m"
33+
read -rp "Are you sure to delete origin/$branch_name? [y/N] " answer
34+
printf "\e[m"
35+
36+
# Delete if the answer is "yes"
37+
case $answer in
38+
[yY]* )
39+
echo -e "\e[32mRun 'git push --delete origin $branch_name'.\e[m"
40+
$git_command push --delete origin "$branch_name"
41+
;;
42+
* )
43+
echo -e "\e[32mSkipped.\e[m"
44+
continue
45+
;;
46+
esac
47+
done
48+
}
49+
50+
# Move to workspace root
51+
cd "$(get_workspace_root)" || exit 1
52+
53+
# Delete old RC branches
54+
for repository in $(get_meta_repository) $(get_reference_repositories) $(get_product_repositories); do
55+
delete_old_rc_branches "$repository"
56+
done

scripts/release/update_vcs_versions.sh

+4
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
SCRIPT_DIR=$(readlink -f "$(dirname "$0")")
44
source "$SCRIPT_DIR/common/helper_functions.sh"
55

6+
# Move to workspace root
7+
cd "$(get_workspace_root)" || exit 1
8+
9+
# Update repos file
610
update_vcs_versions

0 commit comments

Comments
 (0)