Skip to content

Commit

Permalink
Merge branch 'develop/fetch' into PR/fix_update_ws
Browse files Browse the repository at this point in the history
  • Loading branch information
mqcmd196 authored Jun 22, 2023
2 parents 084e34c + 73f85ca commit 1235749
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions jsk_robot_common/jsk_robot_startup/scripts/update_workspace_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function usage()
{
echo "Usage: $0 [-w workspace_directory] [-r rosinstall_path] [-t robot_type] [-s skip keys] [-h] [-u] [-l]
echo "Usage: $0 [-w workspace_directory] [-r rosinstall_path] [-t robot_type] [-s skip keys] [-h] [-u] [-l] [-n]
optional arguments:
-h show this help
Expand All @@ -12,6 +12,7 @@ optional arguments:
-s SKIP_KEYS rosdep install skip keys
-u do not run apt-get upgrade and rosdep install
-l do not send a mail
-n do not update workspace, only show wstool status
"
}

Expand All @@ -22,9 +23,10 @@ function get_full_path()

ROSDEP_INSTALL=true
SEND_MAIL=true
UPDATE_WORKSPACE=true
WORKSPACE=$(get_full_path $HOME/ros/$ROS_DISTRO)

while getopts w:r:t:s:ulh OPT
while getopts w:r:t:s:ulnh OPT
do
case $OPT in
w)
Expand All @@ -45,6 +47,9 @@ do
l)
SEND_MAIL=false
;;
n)
UPDATE_WORKSPACE=false
;;
h)
usage
exit 1
Expand All @@ -57,15 +62,15 @@ do
done

if [ "$WORKSPACE" = "" ]; then
echo "Please set valid workspace -w $WORKSPACE"
echo "Please set valid workspace -w $WORKSPACE<br>"
exit 1
fi
if [ "$ROSINSTALL" = "" ]; then
echo "Please set valid rosinstall -r $ROSINSTALL"
echo "Please set valid rosinstall -r $ROSINSTALL<br>"
exit 1
fi
if [ "$ROBOT_TYPE" = "" ]; then
echo "Please set valid robot type -t $ROBOT_TYPE"
echo "Please set valid robot type -t $ROBOT_TYPE<br>"
exit 1
fi

Expand All @@ -79,16 +84,28 @@ TMP_MAIL_BODY_FILE=/tmp/update_workspace_mailbody.txt
{
set -x
# Update workspace

wstool foreach -t $WORKSPACE/src --git 'git stash -u'
echo "" > $TMP_MAIL_BODY_FILE
wstool foreach -t $WORKSPACE/src --git 'git fetch origin --prune'
wstool update -t $WORKSPACE/src $(rospack find jsk_robot_startup)/../.. --delete-changed-uris
ln -sf $ROSINSTALL $WORKSPACE/src/.rosinstall
wstool update -t $WORKSPACE/src --delete-changed-uris
# When the repository's Spec-Version branch has commits which are not pushed to remote, they are evacuated to another branch
wstool foreach -t $WORKSPACE/src --git --shell 'expected_version=$(wstool info . | grep Spec-Version: | awk '\''{print $2}'\''); current_version=$(git rev-parse --abbrev-ref HEAD); remote_diff=$(git diff --stat $current_version origin/$current_version); if [ "$expected_version" = "$current_version" ] && [ -n "$remote_diff" ]; then git checkout -b ${expected_version}-patch-$(date +%Y%m%d%H%M%S); git checkout origin/$expected_version; git branch -D $expected_version; git checkout -b $expected_version --track origin/$expected_version; fi'
wstool update -t $WORKSPACE/src
WSTOOL_UPDATE_RESULT=$?
WSTOOL_STATUS=$(wstool status -t $WORKSPACE/src)
if [ -n "$WSTOOL_STATUS" ]; then
echo -e "<b>Please commit robot internal change and send pull request.</b><br><br>" >> $TMP_MAIL_BODY_FILE
echo -e $WSTOOL_STATUS >> $TMP_MAIL_BODY_FILE
# escape " ' , -- and add change line code to end of line
wstool diff -t $WORKSPACE/src | sed -e "s/'/ /g" -e "s/^--/ /g" -e 's/"/ /g' -e "s/<br>/\\\n/" -e 's/$/<br>/g' -e "s/,/ /g" | tee -a $TMP_MAIL_BODY_FILE
fi
if [ "${UPDATE_WORKSPACE}" == "true" ]; then
wstool foreach -t $WORKSPACE/src --git 'git stash -u'
wstool foreach -t $WORKSPACE/src --git 'git fetch origin --prune'
wstool update -t $WORKSPACE/src $(rospack find jsk_robot_startup)/../.. --delete-changed-uris
ln -sf $ROSINSTALL $WORKSPACE/src/.rosinstall
wstool update -t $WORKSPACE/src --delete-changed-uris
# When the repository's Spec-Version branch has commits which are not pushed to remote, they are evacuated to another branch
wstool foreach -t $WORKSPACE/src --git --shell 'expected_version=$(wstool info . | grep Spec-Version: | awk '\''{print $2}'\''); current_version=$(git rev-parse --abbrev-ref HEAD); remote_diff=$(git diff --stat $current_version origin/$current_version); if [ "$expected_version" = "$current_version" ] && [ -n "$remote_diff" ]; then git checkout -b ${expected_version}-patch-$(date +%Y%m%d%H%M%S); git checkout origin/$expected_version; git branch -D $expected_version; git checkout -b $expected_version --track origin/$expected_version; fi'
wstool update -t $WORKSPACE/src
WSTOOL_UPDATE_RESULT=$?
else
WSTOOL_UPDATE_RESULT=0
fi
# Rosdep Install
if [ "${ROSDEP_INSTALL}" == "true" ]; then
sudo apt-get update -y;
Expand All @@ -106,15 +123,14 @@ catkin config -DCMAKE_BUILD_TYPE=Release
catkin build --continue-on-failure
CATKIN_BUILD_RESULT=$?
# Send mail
echo "" > $TMP_MAIL_BODY_FILE
if [ $WSTOOL_UPDATE_RESULT -ne 0 ]; then
echo "Please wstool update workspace manually.\n" >> $TMP_MAIL_BODY_FILE
echo "<b>Please wstool update workspace manually.</b><br>" >> $TMP_MAIL_BODY_FILE
fi
if [ $ROSDEP_INSTALL_RESULT -ne 0 ]; then
echo "Please install dependencies manually.\n" >> $TMP_MAIL_BODY_FILE
echo "<b>Please install dependencies manually.</b><br>" >> $TMP_MAIL_BODY_FILE
fi
if [ $CATKIN_BUILD_RESULT -ne 0 ]; then
echo "Please catkin build workspace manually.\n" >> $TMP_MAIL_BODY_FILE
echo "<b>Please catkin build workspace manually.</b><br>" >> $TMP_MAIL_BODY_FILE
fi
set +x
} 2>&1 | tee $LOGFILE
Expand All @@ -133,7 +149,7 @@ if [ -n "$MAIL_BODY" ] && [ "${SEND_MAIL}" == "true" ]; then
frame_id: ''
subject: 'Daily workspace update fails'
body:
- {type: 'text', message: '${MAIL_BODY}', file_path: '', img_data: '', img_size: 0}
- {type: 'html', message: '${MAIL_BODY}', file_path: '', img_data: '', img_size: 0}
sender_address: '$(hostname)@jsk.imi.i.u-tokyo.ac.jp'
receiver_address: '$ROBOT_TYPE@jsk.imi.i.u-tokyo.ac.jp'
smtp_server: ''
Expand Down

0 comments on commit 1235749

Please sign in to comment.