From 41f14221d08f8cd7ff7c4261624d3e4c699aab95 Mon Sep 17 00:00:00 2001 From: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com> Date: Tue, 22 Jun 2021 17:27:32 +0900 Subject: [PATCH] Feature/update release scripts (#150) * Add get_workspace_root function Signed-off-by: Kenji Miyake * Move to workspace root before running release scripts Signed-off-by: Kenji Miyake * Add delete_old_rc_branches.sh Signed-off-by: Kenji Miyake * Cleanup Signed-off-by: Kenji Miyake --- scripts/release/common/helper_functions.sh | 24 ++++---- scripts/release/common/parse_common_args.sh | 12 ++-- scripts/release/common/pre_common_tasks.sh | 3 + scripts/release/create_experiment_branches.sh | 2 +- scripts/release/create_product_rc_branches.sh | 8 +-- .../release/create_product_release_tags.sh | 17 +++--- .../release/create_reference_rc_branches.sh | 4 +- .../release/create_reference_release_tags.sh | 15 +++-- scripts/release/delete_old_rc_branches.sh | 56 +++++++++++++++++++ scripts/release/update_vcs_versions.sh | 4 ++ 10 files changed, 105 insertions(+), 40 deletions(-) create mode 100755 scripts/release/delete_old_rc_branches.sh diff --git a/scripts/release/common/helper_functions.sh b/scripts/release/common/helper_functions.sh index 8277b26156234..85e53678e54a9 100755 --- a/scripts/release/common/helper_functions.sh +++ b/scripts/release/common/helper_functions.sh @@ -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() { @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/scripts/release/common/parse_common_args.sh b/scripts/release/common/parse_common_args.sh index 4bfe1fbf69083..c752dbadd100d 100755 --- a/scripts/release/common/parse_common_args.sh +++ b/scripts/release/common/parse_common_args.sh @@ -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 diff --git a/scripts/release/common/pre_common_tasks.sh b/scripts/release/common/pre_common_tasks.sh index 7bdb53abda1e9..c3eaffdc2168c 100755 --- a/scripts/release/common/pre_common_tasks.sh +++ b/scripts/release/common/pre_common_tasks.sh @@ -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 diff --git a/scripts/release/create_experiment_branches.sh b/scripts/release/create_experiment_branches.sh index 9686bb66d5e9a..107533a4f1f8e 100755 --- a/scripts/release/create_experiment_branches.sh +++ b/scripts/release/create_experiment_branches.sh @@ -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 diff --git a/scripts/release/create_product_rc_branches.sh b/scripts/release/create_product_rc_branches.sh index e1dba5eaeef7e..854d8ffd8a09a 100755 --- a/scripts/release/create_product_rc_branches.sh +++ b/scripts/release/create_product_rc_branches.sh @@ -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." @@ -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 diff --git a/scripts/release/create_product_release_tags.sh b/scripts/release/create_product_release_tags.sh index 887e4ea91f3a7..b3cc2640037d8 100755 --- a/scripts/release/create_product_release_tags.sh +++ b/scripts/release/create_product_release_tags.sh @@ -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" diff --git a/scripts/release/create_reference_rc_branches.sh b/scripts/release/create_reference_rc_branches.sh index 57e4d121f67b9..8125da74e24a5 100755 --- a/scripts/release/create_reference_rc_branches.sh +++ b/scripts/release/create_reference_rc_branches.sh @@ -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." @@ -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 diff --git a/scripts/release/create_reference_release_tags.sh b/scripts/release/create_reference_release_tags.sh index f721b568e3fb7..5472cc425a970 100755 --- a/scripts/release/create_reference_release_tags.sh +++ b/scripts/release/create_reference_release_tags.sh @@ -35,13 +35,6 @@ 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 @@ -49,11 +42,17 @@ 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" diff --git a/scripts/release/delete_old_rc_branches.sh b/scripts/release/delete_old_rc_branches.sh new file mode 100755 index 0000000000000..7140e627ac734 --- /dev/null +++ b/scripts/release/delete_old_rc_branches.sh @@ -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 diff --git a/scripts/release/update_vcs_versions.sh b/scripts/release/update_vcs_versions.sh index 23adce70898ad..add3391a479fd 100755 --- a/scripts/release/update_vcs_versions.sh +++ b/scripts/release/update_vcs_versions.sh @@ -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