diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml index 9473dae4e..61a06b478 100644 --- a/.github/workflows/auto-merge.yml +++ b/.github/workflows/auto-merge.yml @@ -18,25 +18,16 @@ name: auto-merge HEAD to BASE on: pull_request_target: branches: - - branch-24.08 + - branch-* types: [closed] jobs: auto-merge: if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - ref: branch-24.08 # force to fetch from latest upstream instead of PR ref - - - name: auto-merge job - uses: ./.github/workflows/auto-merge - env: - OWNER: NVIDIA - REPO_NAME: spark-rapids-examples - HEAD: branch-24.08 - BASE: branch-24.10 - AUTOMERGE_TOKEN: ${{ secrets.AUTOMERGE_TOKEN }} # use to merge PR - + uses: NVIDIA/spark-rapids-common/.github/workflows/auto-merge.yml@main + with: + owner: ${{ github.repository_owner }} + repo: spark-rapids-examples + branch: ${{ github.event.pull_request.base.ref }} + secrets: + token: ${{ secrets.AUTOMERGE_TOKEN }} diff --git a/.github/workflows/auto-merge/Dockerfile b/.github/workflows/auto-merge/Dockerfile deleted file mode 100644 index e98b1a487..000000000 --- a/.github/workflows/auto-merge/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FROM python:alpine - -WORKDIR / -COPY automerge . -RUN pip install requests && chmod +x /automerge - -# require envs: OWNER,REPO_NAME,HEAD,BASE,GITHUB_TOKEN -ENTRYPOINT ["/automerge"] diff --git a/.github/workflows/auto-merge/action.yml b/.github/workflows/auto-merge/action.yml deleted file mode 100644 index ee5577313..000000000 --- a/.github/workflows/auto-merge/action.yml +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -name: 'auto-merge action' -description: 'auto-merge HEAD to BASE' -runs: - using: 'docker' - image: 'Dockerfile' - diff --git a/.github/workflows/auto-merge/automerge b/.github/workflows/auto-merge/automerge deleted file mode 100755 index 7ea9b1bd9..000000000 --- a/.github/workflows/auto-merge/automerge +++ /dev/null @@ -1,137 +0,0 @@ -#!/usr/bin/env python - -# Copyright (c) 2022, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""A auto-merge tool - -Create a PR to merge HEAD to BASE branch. -NOTE: - The generated PR should be automatically merged if no conflict. Otherwise, manual operation will be required. -""" - -import os -import sys -import time - -import requests - -# ENV -OWNER = os.environ.get('OWNER') -assert OWNER, 'env OWNER should not be empty' -REPO_NAME = os.environ.get('REPO_NAME') -assert REPO_NAME, 'env REPO_NAME should not be empty' -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' -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 ' + AUTOMERGE_TOKEN -} - - -def create(): - url = f'{API_URL}/repos/{OWNER}/{REPO_NAME}/pulls' - params = { - 'title': f'[auto-merge] {HEAD} to {BASE} [skip ci] [bot]', - 'head': HEAD, - 'base': BASE, - 'body': f'auto-merge triggered by github actions on `{HEAD}` to create a PR keeping `{BASE}` up-to-date. If ' - 'this PR is unable to be merged due to conflicts, it will remain open until manually fix.', - 'maintainer_can_modify': True - } - r = requests.post(url, headers=AUTH_HEADERS, json=params) - if r.status_code == 201: - print('SUCCESS - create PR') - pull = r.json() - number = str(pull['number']) - sha = str(pull['head']['sha']) - return number, sha, False - if r.status_code == 422: # early-terminate if no commits between HEAD and BASE - print('SUCCESS - No commits') - print(r.json()) - return '', '', True - # FAILURE - print('FAILURE - create PR') - print(f'status code: {r.status_code}') - print(r.json()) - sys.exit(1) - - -def auto_merge(number, sha): - url = f'{API_URL}/repos/{OWNER}/{REPO_NAME}/pulls/{number}/merge' - params = { - 'sha': sha, - 'merge_method': 'merge' - } - r = requests.put(url, headers=AUTH_HEADERS, json=params) - if r.status_code == 200: - comment(number, '**SUCCESS** - auto-merge') - print('SUCCESS - auto-merge') - sys.exit(0) - else: - print('FAILURE - auto-merge') - comment(number=number, content=f"""**FAILURE** - Unable to auto-merge. Manual operation is required. -``` -{r.json()} -``` - -Please use the following steps to fix the merge conflicts manually: -``` -# Assume upstream is NVIDIA/spark-rapids-examples remote -git fetch upstream {HEAD} {BASE} -git checkout -b fix-auto-merge-conflict-{number} upstream/{BASE} -git merge upstream/{HEAD} -# Fix any merge conflicts caused by this merge -git commit -am "Merge {HEAD} into {BASE}" -git push fix-auto-merge-conflict-{number} -# Open a PR targets NVIDIA/spark-rapids-examples {BASE} -``` -**IMPORTANT:** Before merging this PR, be sure to change the merging strategy to `Create a merge commit` (repo admin only). - -Once this PR is merged, the auto-merge PR should automatically be closed since it contains the same commit hashes -""") - print(f'status code: {r.status_code}') - print(r.json()) - sys.exit(1) - - -def comment(number, content): - url = f'{API_URL}/repos/{OWNER}/{REPO_NAME}/issues/{number}/comments' - params = { - 'body': content - } - r = requests.post(url, headers=AUTH_HEADERS, json=params) - if r.status_code == 201: - print('SUCCESS - create comment') - else: - print('FAILURE - create comment') - print(f'status code: {r.status_code}') - print(r.json()) - - -def main(): - number, sha, term = create() - if term: - sys.exit(0) - - auto_merge(number, sha) - - -if __name__ == '__main__': - main()