Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Judge merge base in sync rc (#422)
Browse files Browse the repository at this point in the history
Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp>
  • Loading branch information
wep21 authored Sep 27, 2021
1 parent 8cd04aa commit ff36c12
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 98 deletions.
90 changes: 0 additions & 90 deletions .github/workflows/sync-rc-develop.yml

This file was deleted.

38 changes: 30 additions & 8 deletions .github/workflows/sync-rc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ on:
description: "Target RC branch(e.g. rc/v1.0.0)"
required: true

env:
BASE_BRANCH: main

jobs:
sync-rc:
runs-on: ubuntu-20.04
Expand All @@ -23,7 +20,6 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: ${{ env.BASE_BRANCH }}
fetch-depth: 0

- name: Generate token
Expand All @@ -48,6 +44,31 @@ jobs:
echo ${SYNC_TARGET_BRANCH} | grep -e "^rc/v.*"
echo "SYNC_BRANCH=sync-rc/${SYNC_TARGET_BRANCH#refs/heads/}" >> $GITHUB_ENV
- name: Judge BASE_BRANCH
run: |
function is_main_base() {
target_branch="$1"
main_base=$(git merge-base "${target_branch}" origin/main)
develop_base=$(git merge-base "${target_branch}" origin/develop)
return $(test "${main_base}" = "${develop_base}")
}
if is_main_base "origin/${{ env.SYNC_TARGET_BRANCH }}"; then
base_branch=main
else
base_branch=develop
fi
echo "BASE_BRANCH=${base_branch}" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: ${{ env.BASE_BRANCH }}
fetch-depth: 0

# To keep the base branch in "create-pull-request", checkout with "BASE_BRANCH" and reset to "SYNC_TARGET_BRANCH"
- name: Reset to sync target branch
run: |
Expand All @@ -60,8 +81,9 @@ jobs:
- name: Rebase on the base branch
run: |
for commit in $(git rev-list --left-only origin/${{ env.BASE_BRANCH }}...HEAD | tac); do
git rebase $commit || git rebase --abort
for commit in $(git rev-list --left-only "origin/${{ env.BASE_BRANCH }}"...HEAD | tac); do
merge_base=$(git merge-base HEAD "origin/${{ env.BASE_BRANCH }}")
git rebase --onto "$commit" "$merge_base" "${{ env.BASE_BRANCH }}" || git rebase --abort
done
- name: Create PR
Expand All @@ -76,9 +98,9 @@ jobs:
base: ${{ env.BASE_BRANCH }}
branch: ${{ env.SYNC_BRANCH }}
delete-branch: true
title: sync rc
title: sync rc ${{ env.SYNC_TARGET_BRANCH }}
body: |
sync rc
sync rc ${{ env.SYNC_TARGET_BRANCH }}
labels: |
sync-rc
draft: false
Expand Down

0 comments on commit ff36c12

Please sign in to comment.