From c5fc36f956ce6085cd37275bdcbf9d19c40e9bf3 Mon Sep 17 00:00:00 2001 From: SigureMo Date: Tue, 30 Sep 2025 22:22:33 +0800 Subject: [PATCH 1/4] split ci to multiple workflows --- .github/workflows/check-bypass.yml | 51 +++++++++++++++++++++++++ .github/workflows/codestyle-check.yml | 55 +++++++++++++++++++++++++++ ci_scripts/check_code.sh | 21 ++++------ ci_scripts/ci_start.sh | 14 ++----- 4 files changed, 118 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/check-bypass.yml create mode 100644 .github/workflows/codestyle-check.yml diff --git a/.github/workflows/check-bypass.yml b/.github/workflows/check-bypass.yml new file mode 100644 index 00000000000..cb369e3dfb0 --- /dev/null +++ b/.github/workflows/check-bypass.yml @@ -0,0 +1,51 @@ +on: + workflow_call: + inputs: + workflow-name: + required: true + type: string + secrets: + github-token: + required: true + outputs: + can-skip: + description: "Whether the workflow can be skipped." + value: ${{ jobs.check-bypass.outputs.can-skip }} + +jobs: + check-bypass: + name: Check bypass + runs-on: ubuntu-latest + permissions: + contents: read + env: + CI_TEAM_MEMBERS: '["tianshuo78520a", "swgu98", "risemeup1", "XieYunshen", "luotao1"]' + outputs: + can-skip: ${{ steps.check-bypass.outputs.can-skip }} + steps: + - name: Cleanup + run: | + rm -rf * .[^.]* + + - id: check-bypass + name: Check Bypass + uses: PFCCLab/ci-bypass@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + non-pull-request-event-strategy: "never-skipped" + type: "composite" + composite-rule: | + { + "any": [ + { + "type": "labeled", + "label": ["skip-ci: ${{ inputs.workflow-name }}", "skip-ci: all"], + "username": ${{ env.CI_TEAM_MEMBERS }} + }, + { + "type": "commented", + "comment-pattern": [".*/skip-ci ${{ inputs.workflow-name }}.*", ".*/skip-ci all.*"], + "username": ${{ env.CI_TEAM_MEMBERS }} + } + ] + } diff --git a/.github/workflows/codestyle-check.yml b/.github/workflows/codestyle-check.yml new file mode 100644 index 00000000000..743832a2c3e --- /dev/null +++ b/.github/workflows/codestyle-check.yml @@ -0,0 +1,55 @@ +name: Codestyle Check + +on: + pull_request: + branches: ["develop"] + +jobs: + check-bypass: + name: Check bypass + if: ${{ inputs.can-skip != 'true' }} + uses: ./.github/workflows/check-bypass.yml + with: + workflow-name: "codestyle" + secrets: + github-token: ${{ secrets.GITHUB_TOKEN }} + + pre-commit: + name: Pre Commit + needs: check-bypass + if: ${{ github.repository_owner == 'PaddlePaddle' && needs.check-bypass.outputs.can-skip != 'true' }} + runs-on: ubuntu-latest + env: + PR_ID: ${{ github.event.pull_request.number }} + BRANCH: develop + + steps: + - name: Cleanup + run: | + rm -rf * .[^.]* + + - name: Checkout base repo + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.base.ref }} + fetch-depth: 200 + + - name: Merge PR to test branch + run: | + git fetch origin pull/${PR_ID}/merge + git checkout -b test FETCH_HEAD + + - name: Install uv + uses: astral-sh/setup-uv@v6 + with: + python-version: "3.13" + + - name: Install prek + run: | + uv tool install prek + + - name: Run prek + run: | + set +e + bash -x ci_scripts/check_code.sh;EXCODE=$? + exit $EXCODE diff --git a/ci_scripts/check_code.sh b/ci_scripts/check_code.sh index b47ff685644..5ffea9ba338 100644 --- a/ci_scripts/check_code.sh +++ b/ci_scripts/check_code.sh @@ -22,21 +22,16 @@ set +x SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" cd $SCRIPT_DIR/.. -# use pre-commit 2.17 -if ! [[ $(pre-commit --version) == *"2.17.0"* ]]; then - pip install pre-commit==2.17.0 1>nul -fi - diff_files=$(git diff --name-only --diff-filter=ACMR ${BRANCH}) num_diff_files=$(echo "$diff_files" | wc -l) echo -e "diff files between pr and ${BRANCH}:\n${diff_files}" -echo "Checking code style by pre-commit ..." -pre-commit run --files ${diff_files};check_error=$? +echo "Checking code style by prek ..." +prek run --files ${diff_files};check_error=$? if test ! -z "$(git diff)"; then echo -e '\n************************************************************************************' - echo -e "These files have been formatted by code format hook. You should use pre-commit to \ + echo -e "These files have been formatted by code format hook. You should use prek to \ format them before git push." echo -e '************************************************************************************\n' git diff 2>&1 @@ -45,15 +40,15 @@ fi echo -e '\n************************************************************************************' if [ ${check_error} != 0 ];then echo "Your PR code style check failed." - echo "Please install pre-commit locally and set up git hook scripts:" + echo "Please install prek locally and set up git hook scripts:" echo "" - echo " pip install pre-commit==2.17.0" - echo " pre-commit install" + echo " pip install prek" + echo " prek install" echo "" if [[ $num_diff_files -le 100 ]];then - echo "Then, run pre-commit to check codestyle issues in your PR:" + echo "Then, run prek to check codestyle issues in your PR:" echo "" - echo " pre-commit run --files" $(echo ${diff_files} | tr "\n" " ") + echo " prek run --files" $(echo ${diff_files} | tr "\n" " ") echo "" fi echo "For more information, please refer to our codestyle check guide:" diff --git a/ci_scripts/ci_start.sh b/ci_scripts/ci_start.sh index 839efc0009a..38dda83affa 100644 --- a/ci_scripts/ci_start.sh +++ b/ci_scripts/ci_start.sh @@ -102,17 +102,11 @@ else fi EXIT_CODE=0 -# 3 check code style/format. -ls ${DIR_PATH} -/bin/bash -x ${DIR_PATH}/check_code.sh -if [ $? -ne 0 ];then - EXIT_CODE=1 -fi git merge --no-edit upstream/${BRANCH} need_check_cn_doc_files=$(find_all_cn_api_files_modified_by_pr) echo $need_check_cn_doc_files -# 4 Chinese api docs check +# 3 Chinese api docs check if [ "${need_check_cn_doc_files}" = "" ] ; then echo "chinese api doc fileslist is empty, skip check." else @@ -127,7 +121,7 @@ else fi fi -# 5 Chinese api_label check +# 4 Chinese api_label check /bin/bash -x ${DIR_PATH}/check_api_label_cn.sh if [ $? -ne 0 ];then set +x @@ -141,13 +135,13 @@ fi if [ ${EXIT_CODE} -ne 0 ]; then set +x echo "==========================================================================================" - echo "Code style check or API Chinese doc check failed! Please check the error info above carefully." + echo "API Chinese doc check failed! Please check the error info above carefully." echo "==========================================================================================" set -x exit ${EXIT_CODE} fi -# 6 Approval check +# 5 Approval check /bin/bash ${DIR_PATH}/checkapproval.sh if [ $? -ne 0 ];then exit 1 From 62a364c1dfa41f4103e236b269bf4afd30631947 Mon Sep 17 00:00:00 2001 From: SigureMo Date: Tue, 30 Sep 2025 22:47:52 +0800 Subject: [PATCH 2/4] use pre-commit again --- .github/workflows/codestyle-check.yml | 6 +++--- ci_scripts/check_code.sh | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/codestyle-check.yml b/.github/workflows/codestyle-check.yml index 743832a2c3e..4a384abd5cd 100644 --- a/.github/workflows/codestyle-check.yml +++ b/.github/workflows/codestyle-check.yml @@ -44,11 +44,11 @@ jobs: with: python-version: "3.13" - - name: Install prek + - name: Install pre-commit run: | - uv tool install prek + uv tool install pre-commit - - name: Run prek + - name: Run pre-commit run: | set +e bash -x ci_scripts/check_code.sh;EXCODE=$? diff --git a/ci_scripts/check_code.sh b/ci_scripts/check_code.sh index 5ffea9ba338..ad4d7ed1078 100644 --- a/ci_scripts/check_code.sh +++ b/ci_scripts/check_code.sh @@ -26,12 +26,12 @@ diff_files=$(git diff --name-only --diff-filter=ACMR ${BRANCH}) num_diff_files=$(echo "$diff_files" | wc -l) echo -e "diff files between pr and ${BRANCH}:\n${diff_files}" -echo "Checking code style by prek ..." -prek run --files ${diff_files};check_error=$? +echo "Checking code style by pre-commit ..." +pre-commit run --files ${diff_files};check_error=$? if test ! -z "$(git diff)"; then echo -e '\n************************************************************************************' - echo -e "These files have been formatted by code format hook. You should use prek to \ + echo -e "These files have been formatted by code format hook. You should use pre-commit to \ format them before git push." echo -e '************************************************************************************\n' git diff 2>&1 @@ -40,15 +40,15 @@ fi echo -e '\n************************************************************************************' if [ ${check_error} != 0 ];then echo "Your PR code style check failed." - echo "Please install prek locally and set up git hook scripts:" + echo "Please install pre-commit locally and set up git hook scripts:" echo "" - echo " pip install prek" - echo " prek install" + echo " pip install pre-commit" + echo " pre-commit install" echo "" if [[ $num_diff_files -le 100 ]];then - echo "Then, run prek to check codestyle issues in your PR:" + echo "Then, run pre-commit to check codestyle issues in your PR:" echo "" - echo " prek run --files" $(echo ${diff_files} | tr "\n" " ") + echo " pre-commit run --files" $(echo ${diff_files} | tr "\n" " ") echo "" fi echo "For more information, please refer to our codestyle check guide:" From 484802e28a3e61c0b2e6573bab2150909e6e0440 Mon Sep 17 00:00:00 2001 From: SigureMo Date: Tue, 30 Sep 2025 23:08:53 +0800 Subject: [PATCH 3/4] migrate api approval to codeowner --- .github/CODEOWNERS | 2 ++ .github/workflows/codestyle-check.yml | 4 ++-- ci_scripts/checkapproval.sh | 27 --------------------------- ci_scripts/ci_start.sh | 6 ------ 4 files changed, 4 insertions(+), 35 deletions(-) create mode 100644 .github/CODEOWNERS delete mode 100644 ci_scripts/checkapproval.sh diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000000..51bc6be5185 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# Paddle API Docs +docs/api/paddle @jzhang533 @sunzhongkai588 @mattheliu diff --git a/.github/workflows/codestyle-check.yml b/.github/workflows/codestyle-check.yml index 4a384abd5cd..eb824d83306 100644 --- a/.github/workflows/codestyle-check.yml +++ b/.github/workflows/codestyle-check.yml @@ -14,8 +14,8 @@ jobs: secrets: github-token: ${{ secrets.GITHUB_TOKEN }} - pre-commit: - name: Pre Commit + check-codestyle: + name: Run codestyle check needs: check-bypass if: ${{ github.repository_owner == 'PaddlePaddle' && needs.check-bypass.outputs.can-skip != 'true' }} runs-on: ubuntu-latest diff --git a/ci_scripts/checkapproval.sh b/ci_scripts/checkapproval.sh deleted file mode 100644 index 36e4bea0aa6..00000000000 --- a/ci_scripts/checkapproval.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -set -x - -API_FILES=("docs/api/paddle") - -for API_FILE in ${API_FILES[*]}; do - API_CHANGE=`git diff --name-only upstream/$BRANCH | grep "${API_FILE}"` - if [ "${API_CHANGE}" ];then - set +x - approval_line=`curl -H "Authorization: token ${GITHUB_API_TOKEN}" https://api.github.com/repos/PaddlePaddle/docs/pulls/${GIT_PR_ID}/reviews?per_page=10000` - set -x - if [ "${API_FILE}" == "docs/api/paddle" ];then - APPROVALS=`echo ${approval_line} | python ./check_pr_approval.py 1 29231 79295425 23093488 39876205 70642955 102272920` - fi - fi - if [ "${APPROVALS}" == "FALSE" ]; then - if [ "${API_FILE}" == "docs/api/paddle" ];then - set +x - echo "==========================================================================================" - echo "You must have one TPM (jzhang533/ZhangJun or Ligoml/LiMengLiu or sunzhongkai588/SunZhongKai or mattheliu/LiuZhuoXin) approval for the api change! ${API_FILE} for the management reason of API interface and API document." - echo "==========================================================================================" - set -x - fi - exit 1 - fi -done diff --git a/ci_scripts/ci_start.sh b/ci_scripts/ci_start.sh index 38dda83affa..0a952efee7f 100644 --- a/ci_scripts/ci_start.sh +++ b/ci_scripts/ci_start.sh @@ -141,12 +141,6 @@ if [ ${EXIT_CODE} -ne 0 ]; then exit ${EXIT_CODE} fi -# 5 Approval check -/bin/bash ${DIR_PATH}/checkapproval.sh -if [ $? -ne 0 ];then - exit 1 -fi - echo "PADDLE_WHL=${PADDLE_WHL}" # print preview url echo "${PREVIEW_URL_PROMPT}" From f4f3ad79a7357542bc243c786bcedddf12dcdac0 Mon Sep 17 00:00:00 2001 From: SigureMo Date: Wed, 1 Oct 2025 20:40:57 +0800 Subject: [PATCH 4/4] use prek --- .github/workflows/codestyle-check.yml | 7 ++++--- ci_scripts/check_code.sh | 12 +++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codestyle-check.yml b/.github/workflows/codestyle-check.yml index eb824d83306..d7b3df1c282 100644 --- a/.github/workflows/codestyle-check.yml +++ b/.github/workflows/codestyle-check.yml @@ -43,12 +43,13 @@ jobs: uses: astral-sh/setup-uv@v6 with: python-version: "3.13" + enable-cache: true - - name: Install pre-commit + - name: Install prek run: | - uv tool install pre-commit + uv tool install prek - - name: Run pre-commit + - name: Run prek run: | set +e bash -x ci_scripts/check_code.sh;EXCODE=$? diff --git a/ci_scripts/check_code.sh b/ci_scripts/check_code.sh index ad4d7ed1078..cc8d41fa802 100644 --- a/ci_scripts/check_code.sh +++ b/ci_scripts/check_code.sh @@ -26,8 +26,18 @@ diff_files=$(git diff --name-only --diff-filter=ACMR ${BRANCH}) num_diff_files=$(echo "$diff_files" | wc -l) echo -e "diff files between pr and ${BRANCH}:\n${diff_files}" +PRE_COMMIT_EXE="pre-commit" +# Use prek to replace pre-commit if prek is installed +if command -v prek &> /dev/null +then + echo "Detected prek, use prek to check code style for better performance." + PRE_COMMIT_EXE="prek" +else + echo "prek not found, use pre-commit to check code style." +fi + echo "Checking code style by pre-commit ..." -pre-commit run --files ${diff_files};check_error=$? +$PRE_COMMIT_EXE run --files ${diff_files};check_error=$? if test ! -z "$(git diff)"; then echo -e '\n************************************************************************************'