From 4b4db9efc69ddfd2b5df41b63f60f0531eb3eb90 Mon Sep 17 00:00:00 2001 From: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com> Date: Sun, 12 Sep 2021 23:50:38 +0900 Subject: [PATCH 1/2] Fix sync-rc.yml (#402) Signed-off-by: Kenji Miyake --- .github/workflows/sync-rc.yml | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sync-rc.yml b/.github/workflows/sync-rc.yml index 26645d10d8d10..f3a6a35084e69 100644 --- a/.github/workflows/sync-rc.yml +++ b/.github/workflows/sync-rc.yml @@ -7,10 +7,13 @@ on: types: - closed workflow_dispatch: + inputs: + rc_branch: + description: "Target RC branch(e.g. rc/v1.0.0)" + required: true env: BASE_BRANCH: main - SYNC_BRANCH: sync-rc jobs: sync-rc: @@ -30,15 +33,37 @@ jobs: app_id: ${{ secrets.APP_ID }} private_key: ${{ secrets.APP_PRIVATE_KEY }} - - name: Set SYNC_TARGET_BRANCH + - name: Set SYNC_TARGET_BRANCH for pull_request event + if: github.event_name == 'pull_request' run: | - echo "SYNC_TARGET_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV + echo "SYNC_TARGET_BRANCH=${{ github.base_ref }}" >> $GITHUB_ENV + + - name: Set SYNC_TARGET_BRANCH for workflow_dispatch event + if: github.event_name == 'workflow_dispatch' + run: | + echo "SYNC_TARGET_BRANCH=${{ github.event.inputs.rc_branch }}" >> $GITHUB_ENV + + - name: Set SYNC_BRANCH + run: | + echo ${SYNC_TARGET_BRANCH} | grep -e "^rc/v.*" + echo "SYNC_BRANCH=sync-rc/${SYNC_TARGET_BRANCH#refs/heads/}" >> $GITHUB_ENV # 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: | git reset --hard origin/${{ env.SYNC_TARGET_BRANCH }} + - name: Set git config + run: | + git config --local user.email "actions@example.com" + git config --local user.name "Github Actions" + + - 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 + done + - name: Create PR id: create_pr uses: peter-evans/create-pull-request@v3 @@ -69,4 +94,4 @@ jobs: with: token: ${{ steps.generate-token.outputs.token }} pull-request-number: ${{ steps.create_pr.outputs.pull-request-number }} - merge-method: merge + merge-method: squash From 406d7e8a909330080b7a5ca4e965b2ceb80cb4a0 Mon Sep 17 00:00:00 2001 From: Daisuke Nishimatsu <42202095+wep21@users.noreply.github.com> Date: Sun, 12 Sep 2021 23:52:02 +0900 Subject: [PATCH 2/2] Add sync rc develop action (#401) Signed-off-by: wep21 --- .github/workflows/sync-rc-develop.yml | 90 +++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 .github/workflows/sync-rc-develop.yml diff --git a/.github/workflows/sync-rc-develop.yml b/.github/workflows/sync-rc-develop.yml new file mode 100644 index 0000000000000..7d63b51760e29 --- /dev/null +++ b/.github/workflows/sync-rc-develop.yml @@ -0,0 +1,90 @@ +name: sync rc develop + +on: + pull_request: + branches: + - "rc/*" + types: + - closed + workflow_dispatch: + inputs: + rc_branch: + description: "Target RC branch(e.g. rc/v1.0.0)" + required: true + +env: + BASE_BRANCH: develop + +jobs: + sync-rc: + runs-on: ubuntu-20.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + ref: ${{ env.BASE_BRANCH }} + fetch-depth: 0 + + - name: Generate token + uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + + - name: Set SYNC_TARGET_BRANCH for pull_request event + if: github.event_name == 'pull_request' + run: | + echo "SYNC_TARGET_BRANCH=${{ github.base_ref }}" >> $GITHUB_ENV + - name: Set SYNC_TARGET_BRANCH for workflow_dispatch event + if: github.event_name == 'workflow_dispatch' + run: | + echo "SYNC_TARGET_BRANCH=${{ github.event.inputs.rc_branch }}" >> $GITHUB_ENV + - name: Set SYNC_BRANCH + run: | + echo ${SYNC_TARGET_BRANCH} | grep -e "^rc/v.*" + echo "SYNC_BRANCH=sync-rc/${SYNC_TARGET_BRANCH#refs/heads/}" >> $GITHUB_ENV + # 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: | + git reset --hard origin/${{ env.SYNC_TARGET_BRANCH }} + - name: Set git config + run: | + git config --local user.email "actions@example.com" + git config --local user.name "Github Actions" + - 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 + done + - name: Create PR + id: create_pr + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ steps.generate-token.outputs.token }} + commit-message: sync rc develop + committer: GitHub + author: GitHub + signoff: false + base: ${{ env.BASE_BRANCH }} + branch: ${{ env.SYNC_BRANCH }} + delete-branch: true + title: sync rc develop + body: | + sync rc develop + labels: | + sync-rc-develop + draft: false + + - name: Check outputs + run: | + echo "Pull Request Number - ${{ steps.create_pr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.create_pr.outputs.pull-request-url }}" + - name: Enable Auto-merge + if: steps.create_pr.outputs.pull-request-operation == 'created' + uses: peter-evans/enable-pull-request-automerge@v1 + with: + token: ${{ steps.generate-token.outputs.token }} + pull-request-number: ${{ steps.create_pr.outputs.pull-request-number }} + merge-method: squash