Skip to content
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

refactor automerge to support merge for protected branch #668

Merged
merged 6 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ on:

jobs:
auto-merge:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: auto-merge job
if: github.event.pull_request.merged == true
uses: ./.github/workflows/auto-merge
env:
OWNER: NVIDIA
REPO_NAME: spark-rapids
HEAD: branch-0.2
BASE: branch-0.3
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AUTOMERGE_TOKEN: ${{ secrets.AUTOMERGE_TOKEN }} # use to merge PR
33 changes: 12 additions & 21 deletions .github/workflows/auto-merge/automerge
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"""A auto-merge tool

Create a PR to merge HEAD to BASE branch.
The PR will be automatically merged if no conflict. Otherwise, manual operation will be required.
NOTE:
The generated PR should be automatically merged if no conflict. Otherwise, manual operation will be required.
"""

import os
Expand All @@ -35,12 +36,12 @@ HEAD = os.environ.get('HEAD')
assert HEAD, 'env HEAD should not be empty'
BASE = os.environ.get('BASE')
assert BASE, 'env BASE should not be empty'
GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN')
assert GITHUB_TOKEN, 'env GITHUB_TOKEN should not be empty'
AUTOMERGE_TOKEN = os.environ.get('AUTOMERGE_TOKEN')
assert AUTOMERGE_TOKEN, 'env AUTOMERGE_TOKEN should not be empty'
# static
API_URL = 'https://api.github.com'
AUTH_HEADERS = {
'Authorization': 'token ' + GITHUB_TOKEN
'Authorization': 'token ' + AUTOMERGE_TOKEN
}


Expand All @@ -61,7 +62,7 @@ def create():
number = str(pull['number'])
sha = str(pull['head']['sha'])
return number, sha, False
if r.status_code == 422:
if r.status_code == 422: # early-terminate if no commits between HEAD and BASE
print('SUCCESS - No commits')
print(r.json())
return '', '', True
Expand All @@ -84,22 +85,12 @@ def auto_merge(number, sha):
print('SUCCESS - auto-merge')
sys.exit(0)
else:
comment(number, """**FAILURE** - Unable to auto-merge due to conflicts. Manual operation is required.

To maintainers, please use the following steps to fix the merge conflicts manually:
This is a example to fix conflict from `branch-0.2` to `branch-0.3`
```bash
git fetch <spark-rapids_remote>
git checkout -b branch-0.3-merge-branch-0.2 <spark-rapids_remote>/branch-0.3
git merge <spark-rapids_remote>/branch-0.2
# fix the merge conflict, then
git commit -am "merge branch-0.2 to branch-0.3"
git push <your forked remote> branch-0.3-merge-branch-0.2
print('FAILURE - auto-merge')
comment(number=number, content=f"""**FAILURE** - Unable to auto-merge. Manual operation is required.
jlowe marked this conversation as resolved.
Show resolved Hide resolved
```
{r.json()}
```
When this is done, create a PR targets the base branch (`branch-0.3` in this example).
Once the PR get merged, close the auto-merge PR.
""")
print('FAILURE - auto-merge')
print(f'status code: {r.status_code}')
print(r.json())
sys.exit(1)
Expand All @@ -124,9 +115,9 @@ def main():
if term:
sys.exit(0)

time.sleep(10) # sleep, then comment
time.sleep(10) # sleep 10s, then try auto-merge
auto_merge(number, sha)


if __name__ == "__main__":
jlowe marked this conversation as resolved.
Show resolved Hide resolved
if __name__ == '__main__':
main()