Skip to content

Commit

Permalink
Feature/update release scripts (#150)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
kenji-miyake authored Jun 22, 2021
1 parent 3f731ed commit 41f1422
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 40 deletions.
24 changes: 14 additions & 10 deletions scripts/release/common/helper_functions.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/usr/bin/env bash

function get_workspace_root() {
git rev-parse --show-toplevel
}

function get_repos_file_path() {
echo "$(git rev-parse --show-toplevel)/autoware.proj.repos"
echo "$(get_workspace_root)/autoware.proj.repos"
}

function install_yq_if_not_installed() {
Expand Down Expand Up @@ -147,13 +151,13 @@ function update_workspace() {
function update_version_in_repos() {
repository="$1"
if [ "$repository" = "" ]; then
echo -e "Please input a repository name as the 1st argument"
echo -e "Please input a repository name as the 1st argument."
return 1
fi

version="$2"
if [ "$version" = "" ]; then
echo -e "Please input a version as the 2nd argument"
echo -e "Please input a version as the 2nd argument."
return 1
fi

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

if [ "$flag_delete" ]; then
echo -e "Delete branch \"$branch_name\" in \"$repository\""
echo -e "Delete branch \"$branch_name\" in \"$repository\"."
$git_command checkout --detach --quiet HEAD
$git_command branch -D --quiet "$branch_name"
return 0
fi

echo -e "Create branch \"$branch_name\" in \"$repository\""
echo -e "Create branch \"$branch_name\" in \"$repository\"."
$git_command checkout --quiet -b "$branch_name" || exit 1

if [ "$flag_push" ]; then
echo -e "Push branch \"$branch_name\" to \"$repository\""
echo -e "Push branch \"$branch_name\" to \"$repository\"."
$git_command push origin "$branch_name"
fi

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

if [ "$flag_delete" ]; then
echo -e "Delete tag \"$version\" in \"$repository\""
echo -e "Delete tag \"$version\" in \"$repository\"."
$git_command tag -d "$version" > /dev/null
return 0
fi

echo -e "Create tag \"$version\" in \"$repository\""
echo -e "Create tag \"$version\" in \"$repository\"."
$git_command checkout --detach --quiet HEAD
$git_command tag -a "$version" -m "$version" || exit 1

if [ "$flag_push" ]; then
echo -e "Push tag \"$version\" to \"$repository\""
echo -e "Push tag \"$version\" to \"$repository\"."
$git_command push origin "$version"
fi

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

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

echo -e "Checkout \"$branch_or_tag_name\" in \"$repository\""
echo -e "Checkout \"$branch_or_tag_name\" in \"$repository\"."
$git_command checkout --quiet "$branch_or_tag_name" || exit 1

return 0
Expand Down
12 changes: 6 additions & 6 deletions scripts/release/common/parse_common_args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,39 @@ fi

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

case "$answer" in
[yY]* )
;;
* )
echo -e "\e[33mCanceled \e[0m"
echo -e "\e[33mCanceled.\e[m"
exit 1
;;
esac
fi

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

case "$answer" in
[yY]* )
;;
* )
echo -e "\e[33mCanceled \e[0m"
echo -e "\e[33mCanceled.\e[m"
exit 1
;;
esac
fi

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

case "$answer" in
[yY]* )
;;
* )
echo -e "\e[33mCanceled \e[0m"
echo -e "\e[33mCanceled.\e[m"
exit 1
;;
esac
Expand Down
3 changes: 3 additions & 0 deletions scripts/release/common/pre_common_tasks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# Install prerequisites
install_yq_if_not_installed

# Move to workspace root
cd "$(get_workspace_root)" || exit 1

# Create src directory if not exist
if ! [ -d src ]; then
mkdir -p src
Expand Down
2 changes: 1 addition & 1 deletion scripts/release/create_experiment_branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ experiment_name="${args[0]}"

# Check args
if ! is_valid_experiment_name "$experiment_name"; then
echo -e "\e[31mPlease input a valid experiment branch name as the 1st argument\e[m"
echo -e "\e[31mPlease input a valid experiment branch name as the 1st argument.\e[m"
show_usage
exit 1
fi
Expand Down
8 changes: 4 additions & 4 deletions scripts/release/create_product_rc_branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ function show_usage() {
Whether to delete branches/tags. Please use this option when you mistook something.
reference_version:
The version to be used for refecenfe rc branches.
The version to be used for reference RC branches.
The valid pattern is '^v([0-9]+)\.([0-9]+)\.([0-9]+)$'.
product_version:
The version to be used for product rc branches.
The version to be used for product RC branches.
The valid pattern is '^v([0-9]+)\.([0-9]+)\.([0-9]+)$'.
Note: Using --push and --delete at the same time may cause unexpected behaviors."
Expand All @@ -42,13 +42,13 @@ product_version="${args[1]}"

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

if ! is_valid_product_rc_version "$product_version"; then
echo -e "\e[31mPlease input a valid product rc version as the 2nd argument\e[m"
echo -e "\e[31mPlease input a valid product RC version as the 2nd argument.\e[m"
show_usage
exit 1
fi
Expand Down
17 changes: 8 additions & 9 deletions scripts/release/create_product_release_tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,25 @@ source "$SCRIPT_DIR/common/parse_common_args.sh"
reference_version="${args[0]}"
product_version="${args[1]}"

# Check if using rc branches
echo -e "\e[36mCheck if using rc branch\e[m"
if ! is_on_corresponding_rc_branch "$product_version"; then
echo -e "\e[31mPlease checkout corresponding rc branch for $product_version\e[m"
exit 1
fi

# Check args
if ! is_valid_reference_release_version "$reference_version"; then
echo -e "\e[31mPlease input a valid reference release version as the 1st argument\e[m"
echo -e "\e[31mPlease input a valid reference release version as the 1st argument.\e[m"
show_usage
exit 1
fi

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

# Check if using RC branch
if ! is_on_corresponding_rc_branch "$product_version"; then
echo -e "\e[31mPlease checkout corresponding RC branch for $product_version.\e[m"
exit 1
fi

# Run pre common tasks
source "$SCRIPT_DIR/common/pre_common_tasks.sh"

Expand Down
4 changes: 2 additions & 2 deletions scripts/release/create_reference_rc_branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function show_usage() {
Whether to delete branches/tags. Please use this option when you mistook something.
reference_version:
The version to be used for refecenfe rc branches.
The version to be used for reference RC branches.
The valid pattern is '^v([0-9]+)\.([0-9]+)\.([0-9]+)$'.
Note: Using --push and --delete at the same time may cause unexpected behaviors."
Expand All @@ -42,7 +42,7 @@ fi

# Check args
if ! is_valid_reference_rc_version "$reference_version"; then
echo -e "\e[31mPlease input a valid reference rc version as the 1st argument\e[m"
echo -e "\e[31mPlease input a valid reference RC version as the 1st argument.\e[m"
show_usage
exit 1
fi
Expand Down
15 changes: 7 additions & 8 deletions scripts/release/create_reference_release_tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,24 @@ source "$SCRIPT_DIR/common/parse_common_args.sh"
reference_version="${args[0]}"
product_version="$reference_version" # Use reference version to product repositories as well

# Check if using rc branches
echo -e "\e[36mCheck if using rc branch\e[m"
if ! is_on_corresponding_rc_branch "$product_version"; then
echo -e "\e[31mPlease checkout corresponding rc branch for $product_version\e[m"
exit 1
fi

# Set default values
if [ "$flag_change_reference_repositories" = "" ]; then
flag_change_reference_repositories=true
fi

# Check args
if ! is_valid_reference_release_version "$reference_version"; then
echo -e "\e[31mPlease input a valid reference release version as the 1st argument\e[m"
echo -e "\e[31mPlease input a valid reference release version as the 1st argument.\e[m"
show_usage
exit 1
fi

# Check if using RC branch
if ! is_on_corresponding_rc_branch "$product_version"; then
echo -e "\e[31mPlease checkout corresponding RC branch for $product_version.\e[m"
exit 1
fi

# Run pre common tasks
source "$SCRIPT_DIR/common/pre_common_tasks.sh"

Expand Down
56 changes: 56 additions & 0 deletions scripts/release/delete_old_rc_branches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

SCRIPT_DIR=$(readlink -f "$(dirname "$0")")
source "$SCRIPT_DIR/common/helper_functions.sh"

# Define functions
function delete_old_rc_branches() {
repository="$1"
git_command="git --work-tree=$repository --git-dir=$repository/.git"

# Show message
echo -e "\e[32mDelete old RC branches in '$($git_command rev-parse --show-toplevel)'.\e[m"

# Iterate all branches
for remote_branch_name in $($git_command branch -r); do
branch_name=$(echo "$remote_branch_name" | sed "s/origin\///g")
tag_name=$(echo "$branch_name" | sed "s/rc\///g")

# Ignore non-RC branches
if ! is_rc_branch_name "$branch_name"; then
continue
fi

# Find the corresponding tag
if ! $git_command rev-parse "$tag_name" >/dev/null 2>&1; then
echo -e "\e[33mNo corresponding tag for $remote_branch_name was not found, skipping.\e[m"
continue
fi

# Show confirmation
$git_command show --no-patch --no-notes --pretty=format:'%h %s%n%ad %aN%d' "origin/$branch_name"
printf "\e[31m"
read -rp "Are you sure to delete origin/$branch_name? [y/N] " answer
printf "\e[m"

# Delete if the answer is "yes"
case $answer in
[yY]* )
echo -e "\e[32mRun 'git push --delete origin $branch_name'.\e[m"
$git_command push --delete origin "$branch_name"
;;
* )
echo -e "\e[32mSkipped.\e[m"
continue
;;
esac
done
}

# Move to workspace root
cd "$(get_workspace_root)" || exit 1

# Delete old RC branches
for repository in $(get_meta_repository) $(get_reference_repositories) $(get_product_repositories); do
delete_old_rc_branches "$repository"
done
4 changes: 4 additions & 0 deletions scripts/release/update_vcs_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
SCRIPT_DIR=$(readlink -f "$(dirname "$0")")
source "$SCRIPT_DIR/common/helper_functions.sh"

# Move to workspace root
cd "$(get_workspace_root)" || exit 1

# Update repos file
update_vcs_versions

0 comments on commit 41f1422

Please sign in to comment.