diff --git a/Scripts/my-script.sh b/Scripts/my-script.sh index ca030f2..bbee2fc 100755 --- a/Scripts/my-script.sh +++ b/Scripts/my-script.sh @@ -2,22 +2,26 @@ set -u +function error_handler() { + echo "error=$(cat /tmp/Error)" >> "$GITHUB_OUTPUT" + exit 1 +} + git config user.name 'Kazumasa Shimomura' git config user.email s2mr@users.noreply.github.com -TARGET_BRANCH=$(echo "$COMMENT_BODY" | sed -e 's/\/ota --into \(.*\).*/\1/g') +# 正規表現にマッチしない場合(e.g. --intoがない場合)はERRステータスになるので、 +# ERRのtrap はこれ以降で行う +TARGET_BRANCH=$(expr "$COMMENT_BODY" : '.*--into \([^ ]*\)') -if [ "$TARGET_BRANCH" != "" ]; then - git pull - git checkout "$TARGET_BRANCH" - git mmmmerge origin/"$PR_BRANCH" --no-rebase -m "[ota] Merge branch '$PR_BRANCH' into $TARGET_BRANCH" 2> /tmp/Error +trap error_handler ERR - if [ "$(cat /tmp/Error)" != "" ]; then - echo "error=$(cat /tmp/Error)" >> "$GITHUB_OUTPUT" - exit 1 - fi +if [ "$TARGET_BRANCH" != "" ]; then + git pull 2> /tmp/Error + git checkout "$TARGET_BRANCH" 2> /tmp/Error + git merge origin/"$PR_BRANCH" --no-ff -m "[ota] Merge remote-tracking branch 'origin/$PR_BRANCH' into $TARGET_BRANCH" 2> /tmp/Error else - git commit --allow-empty -m "[ota]${COMMENT_BODY##/ota}" + git commit --allow-empty -m "[ota]${COMMENT_BODY##/ota}" 2> /tmp/Error fi -git push \ No newline at end of file +git push