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/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..d7b3df1c282 --- /dev/null +++ b/.github/workflows/codestyle-check.yml @@ -0,0 +1,56 @@ +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 }} + + 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 + 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" + enable-cache: true + + - 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..cc8d41fa802 100644 --- a/ci_scripts/check_code.sh +++ b/ci_scripts/check_code.sh @@ -22,17 +22,22 @@ 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}" +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************************************************************************************' @@ -47,7 +52,7 @@ 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 "" - echo " pip install pre-commit==2.17.0" + echo " pip install pre-commit" echo " pre-commit install" echo "" if [[ $num_diff_files -le 100 ]];then 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 839efc0009a..0a952efee7f 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,18 +135,12 @@ 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 -/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}"