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
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/0-16-1-auto-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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
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).

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.


- name: Create pull request to merge into v0.16.1
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.

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
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.

draft: false

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

- name: Merge pull request into v0.16.1
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
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.


// Merge the pull request into the target branch
await github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/heads/${baseRef}`,
sha: context.payload.pull_request.head.sha,
});

const mergeResponse = await github.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
sha: headRef,
merge_method: 'merge',
});

console.log(`Merged PR ${prNumber} into ${baseRef}: ${mergeResponse.status}`);