From d8f686b2df1bc81ffbb95bfe91e389fb662f51e4 Mon Sep 17 00:00:00 2001 From: Peixin Li Date: Tue, 17 Jun 2025 08:39:24 +0800 Subject: [PATCH] Use shared auto-merge workflow Signed-off-by: Peixin Li --- .../workflows/action-helper/python/auto-merge | 69 --------------- .github/workflows/auto-merge.yml | 85 +++---------------- 2 files changed, 10 insertions(+), 144 deletions(-) delete mode 100755 .github/workflows/action-helper/python/auto-merge diff --git a/.github/workflows/action-helper/python/auto-merge b/.github/workflows/action-helper/python/auto-merge deleted file mode 100755 index dcd03ecd12..0000000000 --- a/.github/workflows/action-helper/python/auto-merge +++ /dev/null @@ -1,69 +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. - -import sys -from argparse import ArgumentParser - -from utils import EnvDefault, PullRequest, strtobool - - -def main(): - parser = ArgumentParser(description="Automerge") - parser.add_argument("--owner", action=EnvDefault, env="OWNER", - help="github token, will try use env OWNER if empty") - parser.add_argument("--repo", action=EnvDefault, env="REPO", - help="repo name, will try use env REPO if empty") - parser.add_argument("--head", action=EnvDefault, env="HEAD", - help="HEAD ref, will try use env HEAD if empty") - parser.add_argument("--base", action=EnvDefault, env="BASE", - help="Base ref, will try use env BASE if empty") - parser.add_argument("--token", action=EnvDefault, env="TOKEN", - help="github token, will try use env TOKEN if empty") - parser.add_argument("--delete_head", default=False, type=lambda x: bool(strtobool(x)), - help="if delete HEAD branch after auto-merge") - args = parser.parse_args() - - pr = PullRequest(head_owner=args.owner, head=args.head, head_token=args.token, - base_owner=args.owner, repo=args.repo, base=args.base, base_token=args.token) - try: - if exist := pr.get_open(): - number = exist[0].get('number') - sha = exist[0].get('head').get('sha') - else: - params = { - # head share the same owner/repo with base in auto-merge - 'title': f"[auto-merge] {pr.head} to {pr.base} [skip ci] [bot]", - 'head': f"{pr.head_owner}:{pr.head}", - 'base': pr.base, - 'body': f"auto-merge triggered by github actions on `{pr.head}` to " - f"create a PR keeping `{pr.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 - } - number, sha, term = pr.create(params) - if term: - sys.exit(0) - pr.auto_merge(number, sha) - if args.delete_head: - pr.delete_head() - except Exception as e: - print(e) - sys.exit(1) - - -if __name__ == '__main__': - main() diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml index 87aad7f034..36da14aeb6 100755 --- a/.github/workflows/auto-merge.yml +++ b/.github/workflows/auto-merge.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024, NVIDIA CORPORATION. +# Copyright (c) 2022-2025, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,78 +22,13 @@ on: types: [closed] jobs: - auto-merge: # TODO: use spark-rapids-common shared action when available + auto-merge: if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - - steps: - - name: set HEAD ENV - run: echo "HEAD=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV - - - name: Generate target branch - run: | - current_branch="${{ env.HEAD }}" - version=${current_branch#branch-} - - IFS='.' read -r -a parts <<< "$version" - year=${parts[0]} - month=${parts[1]} - month=$((10#$month + 2)) - if [ $month -gt 12 ]; then - month=$((month - 12)) - year=$((year + 1)) - fi - - next_release=$(printf "%02d.%02d" $year $month) - echo "Next release is $next_release" - echo "BASE=branch-$next_release" >> $GITHUB_ENV - - - name: Check if target branch exists - run: | - CODE=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token ${{ secrets.AUTOMERGE_TOKEN }}" \ - https://api.github.com/repos/${{ github.repository }}/branches/${{ env.BASE }}) - echo "Response code: $CODE..." - - if [ $CODE -eq 200 ]; then - echo "branch_exists=true" >> $GITHUB_ENV - else - echo "branch_exists=false" >> $GITHUB_ENV - echo "Failed to find ${{ env.BASE }}. Skip auto-merge..." - fi - - - uses: actions/checkout@v4 - if: env.branch_exists == 'true' - with: - ref: ${{ env.HEAD }} # force to fetch from latest upstream instead of PR ref - token: ${{ secrets.AUTOMERGE_TOKEN }} # workaround auto-merge token to avoid GITHUB_TOKEN insufficient permission - - - name: push intermediate branch for auto-merge - if: env.branch_exists == 'true' - run: | - git config user.name "spark-rapids automation" - git config user.email "70000568+nvauto@users.noreply.github.com " - git fetch origin ${HEAD} ${BASE} - git checkout -b ${INTERMEDIATE_HEAD} origin/${HEAD} - # Sync the $BASE branch with the commits from the $HEAD branch, - # excluding the paths defined as $FILE_USE_BASE (located under ./thirdparty). - git checkout origin/${BASE} -- ${FILE_USE_BASE} - # If any submodule file is updated in the HEAD branch, - # always change it to the corresponding one from the BASE branch. - [ ! -z "$(git status --porcelain=v1 --untracked=no)" ] && \ - git commit -s -am "Auto-merge use ${BASE} versions" - git push origin ${INTERMEDIATE_HEAD} -f - env: - INTERMEDIATE_HEAD: bot-auto-merge-${{ env.HEAD }} - FILE_USE_BASE: thirdparty/cudf thirdparty/cudf-pins - - - name: auto-merge job - if: env.branch_exists == 'true' - uses: ./.github/workflows/action-helper - with: - operator: auto-merge - env: - OWNER: NVIDIA - REPO: spark-rapids-jni - HEAD: bot-auto-merge-${{ env.HEAD }} - BASE: ${{ env.BASE }} - TOKEN: ${{ secrets.AUTOMERGE_TOKEN }} + uses: NVIDIA/spark-rapids-common/.github/workflows/auto-merge.yml@main + with: + owner: ${{ github.repository_owner }} + repo: spark-rapids-jni + branch: ${{ github.event.pull_request.base.ref }} + file_use_base: 'thirdparty/cudf thirdparty/cudf-pins' + secrets: + token: ${{ secrets.AUTOMERGE_TOKEN }}