Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty #4

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
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