Skip to content

build: set up workflow to automatically manage/mirror the v0.16.1 branch #7577

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Roasbeef
Copy link
Member

@Roasbeef Roasbeef commented Apr 5, 2023

In this PR, we set up an automated Github Actions workflow to merge any PR that has a milestone of v0.16.1 into the v0.16.1 branch once it has been merged into the master branch.

For this to work, we'll need to create a new scoped PAT that gives our normal code review bot the ability to merge PRs into the master branch. Note that with the way this is set up, we only want to merge things in when they have all the checks passed. We might want to also consider peter-evans/enable-pull-request-automerge for this task.

NOTE: The contents of this PR were generated entirely by ChatGPT 🤖.

In this PR, we set up an automated Github Actions workflow to merge any
PR that has a milestone of v0.16.1 into the v0.16.1 branch once it has
been merged into the master branch.

For this to work, we'll need to create a new scoped PAT that gives our
normal code review bot the ability to merge PRs into the master branch.
Note that with the way this is set up, we only want to merge things in
when they have all the checks passed. We might want to also consider
`peter-evans/enable-pull-request-automerge` for this task.

**NOTE**: The contents of this PR were generated entirely by ChatGPT 🤖.
@Roasbeef
Copy link
Member Author

Roasbeef commented Apr 5, 2023

We can use this to handle the merge vs that script fragment: https://github.com/peter-evans/enable-pull-request-automerge

A solution that uses that instead (asked it to use the action and modify the solution):

name: Merge pull request into v0.16.1

on:
  pull_request:
    types: [closed]
    branches:
      - master
    milestone:
      types: [created, edited]
      names:
        - 'v0.16.1'

jobs:
  create-pr:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Create pull request to merge into v0.16.1
        uses: peter-evans/[email protected]
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          branch: v0.16.1
          commit-message: Merge pull request #${{ github.event.pull_request.number }}
          title: Merge pull request #${{ github.event.pull_request.number }} into v0.16.1
          body: |
            This pull request was automatically created to merge pull request #${{ github.event.pull_request.number }}
            into the v0.16.1 branch because it was merged into the master branch and had the v0.16.1 milestone.
          base: v0.16.1
          draft: false

  enable-automerge:
    needs: create-pr
    runs-on: ubuntu-latest
    steps:
      - name: Enable pull request automerge
        uses: peter-evans/enable-pull-request-automerge@v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          pull-request-number: ${{ steps.create-pr.outputs.pull_request_number }}
          merge-method: merge
          delete-branch: true

Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool shall we give a shot?

we only want to merge things in when they have all the checks passed.

You mean all the builds need to be green?

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice automation feature 💯
I have a couple of suggestions though.


jobs:
create-pr:
runs-on: ubuntu-latest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need if: github.event.pull_request.merged == true here to make sure this isn't triggered when someone closes the PR without merging (see https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-your-pull_request-workflow-when-a-pull-request-merges).

uses: peter-evans/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: v0.16.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The branch is called 0-16-1-staging.

body: |
This pull request was automatically created to merge pull request #${{ github.event.pull_request.number }}
into the v0.16.1 branch because it was merged into the master branch and had the v0.16.1 milestone.
base: v0.16.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, re branch name.

runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check out the code here and below? Since all we do is invoke some GitHub APIs.

const { context } = github;
const prNumber = context.payload.pull_request.number;
const headRef = context.payload.pull_request.head.ref;
const baseRef = 'v0.16.1';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Branch name is wrong here too. Also, not sure what the github.context.payload refers to exactly, wasn't able to find any documentation on it...
Should we perhaps use the action outputs of the previous step instead? https://github.com/peter-evans/create-pull-request#action-outputs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could just use the following additional step in the create-pr flow:

    - name: Enable Pull Request Automerge
      run: gh pr merge --merge --auto "1"
      env:
        GH_TOKEN: ${{ secrets.PAT }}

See https://github.com/peter-evans/enable-pull-request-automerge#enable-pull-request-auto-merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants