From 028e687fbc471740bc404245df5c9850baccd2cf Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw-openim)" <3293172751nss@gmail.com> Date: Fri, 21 Jul 2023 20:55:46 +0800 Subject: [PATCH] feat: add comment remark Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- .github/workflows/auto-release.yml | 26 +++++++++++ .github/workflows/bot-auto-cherry-pick.yml | 53 ++++++++++++++++++++++ .github/workflows/bot-cherry-pick.yml | 19 ++++++++ 3 files changed, 98 insertions(+) create mode 100644 .github/workflows/auto-release.yml create mode 100644 .github/workflows/bot-auto-cherry-pick.yml create mode 100644 .github/workflows/bot-cherry-pick.yml diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml new file mode 100644 index 000000000..15a77da9f --- /dev/null +++ b/.github/workflows/auto-release.yml @@ -0,0 +1,26 @@ +name: Automatic Rebase +on: + issue_comment: + types: [created] +jobs: + rebase: + name: Rebase + runs-on: ubuntu-latest + if: >- + github.event.issue.pull_request != '' && + ( + contains(github.event.comment.body, '/rebase') || + contains(github.event.comment.body, '/autosquash') + ) + steps: + - name: Checkout the latest code + uses: actions/checkout@v3 + with: + token: ${{ secrets.BOT_GITHUB_TOKEN }} + fetch-depth: 0 # otherwise, you will fail to push refs to dest repo + - name: Automatic Rebase + uses: cirrus-actions/rebase@1.8 + with: + autosquash: ${{ contains(github.event.comment.body, '/autosquash') || contains(github.event.comment.body, '/rebase-autosquash') }} + env: + GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/bot-auto-cherry-pick.yml b/.github/workflows/bot-auto-cherry-pick.yml new file mode 100644 index 000000000..4cb2cf0ec --- /dev/null +++ b/.github/workflows/bot-auto-cherry-pick.yml @@ -0,0 +1,53 @@ +name: 'Github Rebot for Cherry Pick when PR is merged' +on: + pull_request_target: + types: + - closed + +jobs: + comment: + runs-on: ubuntu-latest + steps: + - name: Comment cherry-pick command + uses: actions/github-script@v5 + with: + script: | + const pr = context.payload.pull_request; + if (!pr.merged) { + console.log("PR is not merged. Skipping..."); + return; + } + if (!pr.milestone || !pr.milestone.title) { + console.log("Milestone is not set. Skipping..."); + return; + } + const milestone = pr.milestone.title; + const ref = `heads/release-${milestone}`; + let branchExists; + try { + await github.rest.git.getRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: ref + }); + branchExists = true; + } catch (error) { + if (error.status === 404) { + console.log(`Branch ${ref} does not exist. Skipping...`); + branchExists = false; + } else { + throw error; // Rethrow if it's another error + } + } + if (!branchExists) { + return; + } + const cherryPickCmd = `/cherry-pick release-${milestone}`; + console.log(`Adding comment: ${cherryPickCmd}`); + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + body: cherryPickCmd + }); + github-token: ${{ secrets.BOT_GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/bot-cherry-pick.yml b/.github/workflows/bot-cherry-pick.yml new file mode 100644 index 000000000..9b5ff49bb --- /dev/null +++ b/.github/workflows/bot-cherry-pick.yml @@ -0,0 +1,19 @@ +name: Github Rebot for Cherry Pick On Comment +on: + issue_comment: + types: [created] +jobs: + cherry-pick: + name: Cherry Pick + if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/cherry-pick') && github.event.comment.user.login=='kubbot' + runs-on: ubuntu-latest + steps: + - name: Checkout the latest code + uses: actions/checkout@v2 + with: + token: ${{ secrets.BOT_GITHUB_TOKEN }} + fetch-depth: 0 # otherwise, you will fail to push refs to dest repo + - name: Automatic Cherry Pick + uses: vendoo/gha-cherry-pick@v1 + env: + GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} \ No newline at end of file