Skip to content

Commit

Permalink
Feature/update release scripts (#57) (#63)
Browse files Browse the repository at this point in the history
* Feature/update release scripts (#57)

* Allow product release version(e.g. rc v0.1.2 or release v0.1.2.3)

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

* Write `show_usage` in each scripts

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

* Support experiment branch creation

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

* Split parse_args.sh from pre_common_tasks.sh

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

* Rename function

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

* Update yq to v4

See https://mikefarah.gitbook.io/yq/v/v4.x/upgrading-from-v3 for more details.

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

* fix directory name and add basename command

Co-authored-by: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com>
  • Loading branch information
UMiho and kenji-miyake authored Mar 30, 2021
1 parent 4d587c3 commit a753378
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 84 deletions.
68 changes: 68 additions & 0 deletions scripts/release/create_experiment_branches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

SCRIPT_DIR=$(cd $(dirname $0); pwd)
source $SCRIPT_DIR/helper_functions.sh

# Define functions
function show_usage() {
echo -e "Usage: create_experiment_branches.sh [--push|--delete] experiment_branch_name
--push:
Push branches or tags of autoware repositories. Please use this option when you can be sure.
--delete:
Delete branches or tags of autoware repositories. Please use this option when you mistook something.
experiment_branch_name:
The version to be used for experiment branches.
The valid pattern is '^[0-9a-zA-Z][0-9a-zA-Z-]+$'.
Note: Using --push and --delete at the same time may cause unexpected behaviors."
}

function create_experiment_branch() {
repository="$1"
if [ "$repository" = "" ]; then
echo -e "Please input a repository name as the 1st argument"
return 1
fi

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

experiment_branch=experiment/$autoware_version
$git_command checkout --quiet -b $experiment_branch

if [ "$push" ]; then
$git_command push origin $experiment_branch
fi

if [ "$delete" ]; then
$git_command checkout --detach --quiet HEAD
$git_command branch -D --quiet $experiment_branch
fi
}

# Parse arguments
source $SCRIPT_DIR/parse_args.sh

# Check version
if ! is_valid_autoware_experiment_version $autoware_version; then
echo -e "\e[31mPlease input a valid autoware experiment version as the 1st argument\e[m"
show_usage
exit 1
fi

# Pre common tasks
source $SCRIPT_DIR/pre_common_tasks.sh

# Create experiment branches in autoware repositories
echo -e "\e[36mCreate experiment branches in autoware repositories\e[m"
for autoware_repository in $(get_autoware_repositories); do
create_experiment_branch $autoware_repository
done

# Pre common tasks
source $SCRIPT_DIR/post_common_tasks.sh

# Create experiment branch in autoware.proj
echo -e "\e[36mCreate experiment branch in autoware.proj\e[m"
create_experiment_branch .
22 changes: 15 additions & 7 deletions scripts/release/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function install_yq_if_not_installed() {
}

function is_release_branch_name() {
if ! [[ "$1" =~ ^(rc|release)\/.*$ ]]; then
if ! [[ "$1" =~ ^(experiment|rc|release)\/.*$ ]]; then
return 1
fi

Expand All @@ -26,16 +26,24 @@ function is_sem_ver() {
return 0
}

function is_valid_autoware_experiment_version() {
if ! [[ "$1" =~ ^[0-9a-zA-Z][0-9a-zA-Z-]+$ ]]; then
return 1
fi

return 0
}

function is_valid_autoware_rc_version() {
if ! [[ "$1" =~ ^v([0-9]+)\.([0-9]+)$ ]]; then
if ! [[ "$1" =~ ^v([0-9]+)\.([0-9]+)(\.([0-9]+))?$ ]]; then
return 1
fi

return 0
}

function is_valid_autoware_version() {
if ! [[ "$1" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
function is_valid_autoware_release_version() {
if ! [[ "$1" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)(\.([0-9]+))?$ ]]; then
return 1
fi

Expand Down Expand Up @@ -63,11 +71,11 @@ function show_workspace_diff() {
}

function get_autoware_repositories() {
echo "src/autoware/pilot.auto" "src/autoware/launcher"
echo "src/autoware/autoware.iv" "src/autoware/launcher"
}

function get_vcs_repositories() {
echo "$(yq r $(get_repos_file_path) repositories | grep -E "^[a-zA-Z]+" | sed "s/://g")"
echo "$(yq e '.repositories' $(get_repos_file_path) | grep -E "^[a-zA-Z]+" | sed "s/://g")"
}

function is_on_rc_branch() {
Expand Down Expand Up @@ -105,7 +113,7 @@ function update_version_in_repos() {
return 1
fi

yq w --inplace $(get_repos_file_path) "repositories.[$repository].version" "$version"
yq eval --inplace ".repositories.\"$repository\".version = \"$version\"" $(get_repos_file_path)

return 0
}
58 changes: 58 additions & 0 deletions scripts/release/parse_args.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

SCRIPT_DIR=$(cd $(dirname $0); pwd)
source $SCRIPT_DIR/helper_functions.sh

# Define functions
function parse_args(){
while [ "${1:-}" != "" ]; do
case "$1" in
"-h" | "--help")
help=true
;;
"--push")
push=true
;;
"--delete")
delete=true
;;
*)
autoware_version="$1"
esac
shift
done
}

# Parse arguments
parse_args $@

if [ "$help" ]; then
show_usage
exit 0
fi

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

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

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

case $answer in
[yY]* )
;;
* )
echo -e "\e[33mCanceled \e[0m"
exit 1
;;
esac
fi
2 changes: 1 addition & 1 deletion scripts/release/post_common_tasks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ source $SCRIPT_DIR/update_vcs_versions.sh
# Commit autoware.proj
git checkout --detach --quiet HEAD
git add $(get_repos_file_path)
git commit -m "Update $(get_repos_file_path)"
git commit -m "Update $(basename $(get_repos_file_path))"
70 changes: 0 additions & 70 deletions scripts/release/pre_common_tasks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,9 @@
SCRIPT_DIR=$(cd $(dirname $0); pwd)
source $SCRIPT_DIR/helper_functions.sh

# Define functions
function show_usage() {
echo -e "Usage: release_candidate.sh [--push|--delete] autoware_version
--push:
Push branches or tags of autoware repositories. Please use this option when you can be sure.
--delete:
Delete branches or tags of autoware repositories. Please use this option when you mistook something.
autoware_version:
The version to be used for branches or tags.
The valid pattern for release_candidate.sh is '^v([0-9]+)\.([0-9]+)$'.
The valid pattern for release.sh is '^v([0-9]+)\.([0-9]+)\.([0-9]+)$'.
Note: Using --push and --delete at the same time may cause unexpected behaviors."
}

function parse_args(){
while [ "${1:-}" != "" ]; do
case "$1" in
"-h" | "--help")
help=true
;;
"--push")
push=true
;;
"--delete")
delete=true
;;
*)
autoware_version="$1"
esac
shift
done
}

# Install prerequisites
install_yq_if_not_installed

# Parse arguments
parse_args $@

if [ "$help" ]; then
show_usage
exit 0
fi

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

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

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

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

# Create src directory if not exist
if ! [ -d src ]; then
mkdir -p src
Expand Down
26 changes: 22 additions & 4 deletions scripts/release/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ SCRIPT_DIR=$(cd $(dirname $0); pwd)
source $SCRIPT_DIR/helper_functions.sh

# Define functions
function show_usage() {
echo -e "Usage: release.sh [--push|--delete] autoware_version
--push:
Push branches or tags of autoware repositories. Please use this option when you can be sure.
--delete:
Delete branches or tags of autoware repositories. Please use this option when you mistook something.
autoware_version:
The version to be used for release tags.
The valid pattern is '^v([0-9]+)\.([0-9]+)\.([0-9]+)(\.([0-9]+))?$'.
Note: Using --push and --delete at the same time may cause unexpected behaviors."
}

function add_tag() {
repository="$1"
if [ "$repository" = "" ]; then
Expand All @@ -24,16 +39,19 @@ function add_tag() {
fi
}

# Pre common tasks
source $SCRIPT_DIR/pre_common_tasks.sh
# Parse arguments
source $SCRIPT_DIR/parse_args.sh

# Check version
if ! is_valid_autoware_version $autoware_version; then
echo -e "\e[31mPlease input a valid autoware version as the 1st argument\e[m"
if ! is_valid_autoware_release_version $autoware_version; then
echo -e "\e[31mPlease input a valid autoware release version as the 1st argument\e[m"
show_usage
exit 1
fi

# Pre common tasks
source $SCRIPT_DIR/pre_common_tasks.sh

# Check if using rc branches
echo -e "\e[36mCheck if using rc branch\e[m"
if ! is_on_rc_branch; then
Expand Down
22 changes: 20 additions & 2 deletions scripts/release/release_candidate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ SCRIPT_DIR=$(cd $(dirname $0); pwd)
source $SCRIPT_DIR/helper_functions.sh

# Define functions
function show_usage() {
echo -e "Usage: release_candidate.sh [--push|--delete] autoware_rc_version
--push:
Push branches or tags of autoware repositories. Please use this option when you can be sure.
--delete:
Delete branches or tags of autoware repositories. Please use this option when you mistook something.
autoware_rc_version:
The version to be used for 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."
}

function create_rc_branch() {
repository="$1"
if [ "$repository" = "" ]; then
Expand All @@ -26,8 +41,8 @@ function create_rc_branch() {
fi
}

# Pre common tasks
source $SCRIPT_DIR/pre_common_tasks.sh
# Parse arguments
source $SCRIPT_DIR/parse_args.sh

# Check version
if ! is_valid_autoware_rc_version $autoware_version; then
Expand All @@ -36,6 +51,9 @@ if ! is_valid_autoware_rc_version $autoware_version; then
exit 1
fi

# Pre common tasks
source $SCRIPT_DIR/pre_common_tasks.sh

# Create rc branches in autoware repositories
echo -e "\e[36mCreate rc branches in autoware repositories\e[m"
for autoware_repository in $(get_autoware_repositories); do
Expand Down

0 comments on commit a753378

Please sign in to comment.