Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions Scripts/my-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]

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
git push