Skip to content

Commit

Permalink
Feature/remove push option in release scripts (#155)
Browse files Browse the repository at this point in the history
* Remove push option

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* Add push_banches.sh

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* Add push_tags.sh

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
  • Loading branch information
kenji-miyake authored Jun 23, 2021
1 parent 41f1422 commit d29628e
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 75 deletions.
16 changes: 2 additions & 14 deletions scripts/release/common/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ function update_vcs_versions() {
function create_branch() {
repository="$1"
branch_name="$2"
flag_push="$3"
flag_delete="$4"
flag_delete="$3"

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

Expand All @@ -210,19 +209,13 @@ function create_branch() {
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\"."
$git_command push origin "$branch_name"
fi

return 0
}

function create_tag() {
repository="$1"
version="$2"
flag_push="$3"
flag_delete="$4"
flag_delete="$3"

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

Expand All @@ -236,11 +229,6 @@ function create_tag() {
$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\"."
$git_command push origin "$version"
fi

return 0
}

Expand Down
16 changes: 0 additions & 16 deletions scripts/release/common/parse_common_args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ function parse_common_args(){
"--change-reference-repositories")
flag_change_reference_repositories=true
;;
"--push")
flag_push=true
;;
"--delete")
flag_delete=true
;;
Expand Down Expand Up @@ -52,19 +49,6 @@ if [ "$flag_yes" = "" ]; then
esac
fi

if [ "$flag_push" ]; then
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[m"
exit 1
;;
esac
fi

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

Expand Down
14 changes: 5 additions & 9 deletions scripts/release/create_experiment_branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source "$SCRIPT_DIR/common/helper_functions.sh"
# Define functions
function show_usage() {
echo -e "Usage: create_experiment_branches.sh experiment_name
[-h/--help] [-y/--yes] [--change-reference-repositories] [--push|--delete]
[-h/--help] [-y/--yes] [--change-reference-repositories] [--delete]
-h/--help:
Show usage and exit.
Expand All @@ -17,17 +17,13 @@ function show_usage() {
--change-reference-repositories:
Whether to create branches/tags in reference repositories.
--push:
Whether to push branches/tags. Please use this option when you can be sure.
--delete:
Whether to delete branches/tags. Please use this option when you mistook something.
experiment_name:
The version to be used for experiment 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."
"
}

# Parse arguments
Expand All @@ -50,13 +46,13 @@ branch_prefix="experiment/"
# Create branches in reference repositories
echo -e "\e[36mCreate branches in autoware repositories\e[m"
for reference_repository in $(get_reference_repositories); do
create_branch "$reference_repository" "$branch_prefix$experiment_name" "$flag_push" "$flag_delete"
create_branch "$reference_repository" "$branch_prefix$experiment_name" "$flag_delete"
done

# Create branches in product repositories
echo -e "\e[36mCreate branches in product repositories\e[m"
for product_repository in $(get_product_repositories); do
create_branch "$product_repository" "$branch_prefix$experiment_name" "$flag_push" "$flag_delete"
create_branch "$product_repository" "$branch_prefix$experiment_name" "$flag_delete"
done

# Run post common tasks
Expand All @@ -65,4 +61,4 @@ if [ "$flag_delete" = "" ]; then
fi

# Create branch in meta repository
create_branch "$(get_meta_repository)" "$branch_prefix$experiment_name" "$flag_push" "$flag_delete"
create_branch "$(get_meta_repository)" "$branch_prefix$experiment_name" "$flag_delete"
14 changes: 5 additions & 9 deletions scripts/release/create_product_rc_branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source "$SCRIPT_DIR/common/helper_functions.sh"
function show_usage() {
echo -e
"Usage: create_reference_rc_branches.sh reference_version product_version
[-h/--help] [-y/--yes] [--change-reference-repositories] [--push|--delete]
[-h/--help] [-y/--yes] [--change-reference-repositories] [--delete]
-h/--help:
Show usage and exit.
Expand All @@ -18,9 +18,6 @@ function show_usage() {
--change-reference-repositories:
Whether to create branches/tags in reference repositories.
--push:
Whether to push branches/tags. Please use this option when you can be sure.
--delete:
Whether to delete branches/tags. Please use this option when you mistook something.
Expand All @@ -31,8 +28,7 @@ function show_usage() {
product_version:
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."
"
}

# Parse arguments
Expand Down Expand Up @@ -64,7 +60,7 @@ echo -e "\e[36mCreate branches in autoware repositories\e[m"
for reference_repository in $(get_reference_repositories); do
if [ "$flag_change_reference_repositories" ]; then
# Don't use branch prefix for reference version, so you need to specify the exact branch name or tag.
create_branch "$reference_repository" "$reference_version" "$flag_push" "$flag_delete"
create_branch "$reference_repository" "$reference_version" "$flag_delete"
else
checkout_branch_or_tag "$reference_repository" "$reference_version"
fi
Expand All @@ -73,7 +69,7 @@ done
# Create branches in product repositories
echo -e "\e[36mCreate branches in product repositories\e[m"
for product_repository in $(get_product_repositories); do
create_branch "$product_repository" "$branch_prefix$product_version" "$flag_push" "$flag_delete"
create_branch "$product_repository" "$branch_prefix$product_version" "$flag_delete"
done

# Run post common tasks
Expand All @@ -82,4 +78,4 @@ if [ "$flag_delete" = "" ]; then
fi

# Create branch in meta repository
create_branch "$(get_meta_repository)" "$branch_prefix$product_version" "$flag_push" "$flag_delete"
create_branch "$(get_meta_repository)" "$branch_prefix$product_version" "$flag_delete"
14 changes: 5 additions & 9 deletions scripts/release/create_product_release_tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source "$SCRIPT_DIR/common/helper_functions.sh"
# Define functions
function show_usage() {
echo -e "Usage: create_product_release_tags.sh reference_version product_version
[-h/--help] [-y/--yes] [--change-reference-repositories] [--push|--delete]
[-h/--help] [-y/--yes] [--change-reference-repositories] [--delete]
-h/--help:
Show usage and exit.
Expand All @@ -17,9 +17,6 @@ function show_usage() {
--change-reference-repositories:
Whether to create branches/tags in reference repositories.
--push:
Whether to push branches/tags. Please use this option when you can be sure.
--delete:
Whether to delete branches/tags. Please use this option when you mistook something.
Expand All @@ -30,8 +27,7 @@ function show_usage() {
product_version:
The version to be used for product release tags.
The valid pattern is '^v([0-9]+)\.([0-9]+)\.([0-9]+)$'.
Note: Using --push and --delete at the same time may cause unexpected behaviors."
"
}

# Parse arguments
Expand Down Expand Up @@ -65,7 +61,7 @@ source "$SCRIPT_DIR/common/pre_common_tasks.sh"
echo -e "\e[36mCreate tags in reference repositories\e[m"
for reference_repository in $(get_reference_repositories); do
if [ "$flag_change_reference_repositories" ]; then
create_tag "$reference_repository" "$reference_version" "$flag_push" "$flag_delete"
create_tag "$reference_repository" "$reference_version" "$flag_delete"
else
checkout_branch_or_tag "$reference_repository" "$reference_version"
fi
Expand All @@ -74,7 +70,7 @@ done
# Create tags in product repositories
echo -e "\e[36mCreate tags in product repositories\e[m"
for product_repository in $(get_product_repositories); do
create_tag "$product_repository" "$product_version" "$flag_push" "$flag_delete"
create_tag "$product_repository" "$product_version" "$flag_delete"
done

# Run post common tasks
Expand All @@ -83,4 +79,4 @@ if [ "$flag_delete" = "" ]; then
fi

# Create tag in meta repository
create_tag "$(get_meta_repository)" "$product_version" "$flag_push" "$flag_delete"
create_tag "$(get_meta_repository)" "$product_version" "$flag_delete"
14 changes: 5 additions & 9 deletions scripts/release/create_reference_rc_branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source "$SCRIPT_DIR/common/helper_functions.sh"
# Define functions
function show_usage() {
echo -e "Usage: create_reference_rc_branches.sh reference_version
[-h/--help] [-y/--yes] [--change-reference-repositories] [--push|--delete]
[-h/--help] [-y/--yes] [--change-reference-repositories] [--delete]
-h/--help:
Show usage and exit.
Expand All @@ -17,17 +17,13 @@ function show_usage() {
--change-reference-repositories:
Whether to create branches/tags in reference repositories.
--push:
Whether to push branches/tags. Please use this option when you can be sure.
--delete:
Whether to delete branches/tags. Please use this option when you mistook something.
reference_version:
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."
"
}

# Parse arguments
Expand Down Expand Up @@ -57,7 +53,7 @@ branch_prefix="rc/"
echo -e "\e[36mCreate branches in autoware repositories\e[m"
for reference_repository in $(get_reference_repositories); do
if [ "$flag_change_reference_repositories" ]; then
create_branch "$reference_repository" "$branch_prefix$reference_version" "$flag_push" "$flag_delete"
create_branch "$reference_repository" "$branch_prefix$reference_version" "$flag_delete"
else
checkout_branch_or_tag "$reference_repository" "$branch_prefix$reference_version"
fi
Expand All @@ -66,7 +62,7 @@ done
# Create branches in product repositories
echo -e "\e[36mCreate branches in product repositories\e[m"
for product_repository in $(get_product_repositories); do
create_branch "$product_repository" "$branch_prefix$product_version" "$flag_push" "$flag_delete"
create_branch "$product_repository" "$branch_prefix$product_version" "$flag_delete"
done

# Run post common tasks
Expand All @@ -75,4 +71,4 @@ if [ "$flag_delete" = "" ]; then
fi

# Create branch in meta repository
create_branch "$(get_meta_repository)" "$branch_prefix$product_version" "$flag_push" "$flag_delete"
create_branch "$(get_meta_repository)" "$branch_prefix$product_version" "$flag_delete"
14 changes: 5 additions & 9 deletions scripts/release/create_reference_release_tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source "$SCRIPT_DIR/common/helper_functions.sh"
# Define functions
function show_usage() {
echo -e "Usage: create_reference_release_tags.sh reference_version
[-h/--help] [-y/--yes] [--change-reference-repositories] [--push|--delete]
[-h/--help] [-y/--yes] [--change-reference-repositories] [--delete]
-h/--help:
Show usage and exit.
Expand All @@ -17,17 +17,13 @@ function show_usage() {
--change-reference-repositories:
Whether to create branches/tags in reference repositories.
--push:
Whether to push branches/tags. Please use this option when you can be sure.
--delete:
Whether to delete branches/tags. Please use this option when you mistook something.
reference_version:
The version to be used for reference release tags.
The valid pattern is '^v([0-9]+)\.([0-9]+)\.([0-9]+)$'.
Note: Using --push and --delete at the same time may cause unexpected behaviors."
"
}

# Parse arguments
Expand Down Expand Up @@ -60,7 +56,7 @@ source "$SCRIPT_DIR/common/pre_common_tasks.sh"
echo -e "\e[36mCreate tags in reference repositories\e[m"
for reference_repository in $(get_reference_repositories); do
if [ "$flag_change_reference_repositories" ]; then
create_tag "$reference_repository" "$reference_version" "$flag_push" "$flag_delete"
create_tag "$reference_repository" "$reference_version" "$flag_delete"
else
checkout_branch_or_tag "$reference_repository" "$reference_version"
fi
Expand All @@ -69,7 +65,7 @@ done
# Create tags in product repositories
echo -e "\e[36mCreate tags in product repositories\e[m"
for product_repository in $(get_product_repositories); do
create_tag "$product_repository" "$product_version" "$flag_push" "$flag_delete"
create_tag "$product_repository" "$product_version" "$flag_delete"
done

# Run post common tasks
Expand All @@ -78,4 +74,4 @@ if [ "$flag_delete" = "" ]; then
fi

# Create tag in meta repository
create_tag "$(get_meta_repository)" "$product_version" "$flag_push" "$flag_delete"
create_tag "$(get_meta_repository)" "$product_version" "$flag_delete"
46 changes: 46 additions & 0 deletions scripts/release/push_branches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

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

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

# Get branch name
branch_name=$($git_command rev-parse --abbrev-ref HEAD)

# Verify branch name
if (! is_rc_branch_name "$branch_name") && (! is_experiment_branch_name "$branch_name"); then
echo -e "\e[32mNot a valid branch name, skipping.\e[m"
return
fi

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

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

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

# Push branches
for repository in $(get_meta_repository) $(get_reference_repositories) $(get_product_repositories); do
echo -e "\e[36mProcessing '$(readlink -f "$repository")'.\e[m"
push_branch "$repository"
done
Loading

0 comments on commit d29628e

Please sign in to comment.