Skip to content

Commit c5fc36f

Browse files
committed
split ci to multiple workflows
1 parent 503521f commit c5fc36f

File tree

4 files changed

+118
-23
lines changed

4 files changed

+118
-23
lines changed

.github/workflows/check-bypass.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
workflow-name:
5+
required: true
6+
type: string
7+
secrets:
8+
github-token:
9+
required: true
10+
outputs:
11+
can-skip:
12+
description: "Whether the workflow can be skipped."
13+
value: ${{ jobs.check-bypass.outputs.can-skip }}
14+
15+
jobs:
16+
check-bypass:
17+
name: Check bypass
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
env:
22+
CI_TEAM_MEMBERS: '["tianshuo78520a", "swgu98", "risemeup1", "XieYunshen", "luotao1"]'
23+
outputs:
24+
can-skip: ${{ steps.check-bypass.outputs.can-skip }}
25+
steps:
26+
- name: Cleanup
27+
run: |
28+
rm -rf * .[^.]*
29+
30+
- id: check-bypass
31+
name: Check Bypass
32+
uses: PFCCLab/ci-bypass@v2
33+
with:
34+
github-token: ${{ secrets.GITHUB_TOKEN }}
35+
non-pull-request-event-strategy: "never-skipped"
36+
type: "composite"
37+
composite-rule: |
38+
{
39+
"any": [
40+
{
41+
"type": "labeled",
42+
"label": ["skip-ci: ${{ inputs.workflow-name }}", "skip-ci: all"],
43+
"username": ${{ env.CI_TEAM_MEMBERS }}
44+
},
45+
{
46+
"type": "commented",
47+
"comment-pattern": [".*/skip-ci ${{ inputs.workflow-name }}.*", ".*/skip-ci all.*"],
48+
"username": ${{ env.CI_TEAM_MEMBERS }}
49+
}
50+
]
51+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Codestyle Check
2+
3+
on:
4+
pull_request:
5+
branches: ["develop"]
6+
7+
jobs:
8+
check-bypass:
9+
name: Check bypass
10+
if: ${{ inputs.can-skip != 'true' }}
11+
uses: ./.github/workflows/check-bypass.yml
12+
with:
13+
workflow-name: "codestyle"
14+
secrets:
15+
github-token: ${{ secrets.GITHUB_TOKEN }}
16+
17+
pre-commit:
18+
name: Pre Commit
19+
needs: check-bypass
20+
if: ${{ github.repository_owner == 'PaddlePaddle' && needs.check-bypass.outputs.can-skip != 'true' }}
21+
runs-on: ubuntu-latest
22+
env:
23+
PR_ID: ${{ github.event.pull_request.number }}
24+
BRANCH: develop
25+
26+
steps:
27+
- name: Cleanup
28+
run: |
29+
rm -rf * .[^.]*
30+
31+
- name: Checkout base repo
32+
uses: actions/checkout@v4
33+
with:
34+
ref: ${{ github.event.pull_request.base.ref }}
35+
fetch-depth: 200
36+
37+
- name: Merge PR to test branch
38+
run: |
39+
git fetch origin pull/${PR_ID}/merge
40+
git checkout -b test FETCH_HEAD
41+
42+
- name: Install uv
43+
uses: astral-sh/setup-uv@v6
44+
with:
45+
python-version: "3.13"
46+
47+
- name: Install prek
48+
run: |
49+
uv tool install prek
50+
51+
- name: Run prek
52+
run: |
53+
set +e
54+
bash -x ci_scripts/check_code.sh;EXCODE=$?
55+
exit $EXCODE

ci_scripts/check_code.sh

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,16 @@ set +x
2222
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
2323
cd $SCRIPT_DIR/..
2424

25-
# use pre-commit 2.17
26-
if ! [[ $(pre-commit --version) == *"2.17.0"* ]]; then
27-
pip install pre-commit==2.17.0 1>nul
28-
fi
29-
3025
diff_files=$(git diff --name-only --diff-filter=ACMR ${BRANCH})
3126
num_diff_files=$(echo "$diff_files" | wc -l)
3227
echo -e "diff files between pr and ${BRANCH}:\n${diff_files}"
3328

34-
echo "Checking code style by pre-commit ..."
35-
pre-commit run --files ${diff_files};check_error=$?
29+
echo "Checking code style by prek ..."
30+
prek run --files ${diff_files};check_error=$?
3631

3732
if test ! -z "$(git diff)"; then
3833
echo -e '\n************************************************************************************'
39-
echo -e "These files have been formatted by code format hook. You should use pre-commit to \
34+
echo -e "These files have been formatted by code format hook. You should use prek to \
4035
format them before git push."
4136
echo -e '************************************************************************************\n'
4237
git diff 2>&1
@@ -45,15 +40,15 @@ fi
4540
echo -e '\n************************************************************************************'
4641
if [ ${check_error} != 0 ];then
4742
echo "Your PR code style check failed."
48-
echo "Please install pre-commit locally and set up git hook scripts:"
43+
echo "Please install prek locally and set up git hook scripts:"
4944
echo ""
50-
echo " pip install pre-commit==2.17.0"
51-
echo " pre-commit install"
45+
echo " pip install prek"
46+
echo " prek install"
5247
echo ""
5348
if [[ $num_diff_files -le 100 ]];then
54-
echo "Then, run pre-commit to check codestyle issues in your PR:"
49+
echo "Then, run prek to check codestyle issues in your PR:"
5550
echo ""
56-
echo " pre-commit run --files" $(echo ${diff_files} | tr "\n" " ")
51+
echo " prek run --files" $(echo ${diff_files} | tr "\n" " ")
5752
echo ""
5853
fi
5954
echo "For more information, please refer to our codestyle check guide:"

ci_scripts/ci_start.sh

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,11 @@ else
102102
fi
103103

104104
EXIT_CODE=0
105-
# 3 check code style/format.
106-
ls ${DIR_PATH}
107-
/bin/bash -x ${DIR_PATH}/check_code.sh
108-
if [ $? -ne 0 ];then
109-
EXIT_CODE=1
110-
fi
111105

112106
git merge --no-edit upstream/${BRANCH}
113107
need_check_cn_doc_files=$(find_all_cn_api_files_modified_by_pr)
114108
echo $need_check_cn_doc_files
115-
# 4 Chinese api docs check
109+
# 3 Chinese api docs check
116110
if [ "${need_check_cn_doc_files}" = "" ] ; then
117111
echo "chinese api doc fileslist is empty, skip check."
118112
else
@@ -127,7 +121,7 @@ else
127121
fi
128122
fi
129123

130-
# 5 Chinese api_label check
124+
# 4 Chinese api_label check
131125
/bin/bash -x ${DIR_PATH}/check_api_label_cn.sh
132126
if [ $? -ne 0 ];then
133127
set +x
@@ -141,13 +135,13 @@ fi
141135
if [ ${EXIT_CODE} -ne 0 ]; then
142136
set +x
143137
echo "=========================================================================================="
144-
echo "Code style check or API Chinese doc check failed! Please check the error info above carefully."
138+
echo "API Chinese doc check failed! Please check the error info above carefully."
145139
echo "=========================================================================================="
146140
set -x
147141
exit ${EXIT_CODE}
148142
fi
149143

150-
# 6 Approval check
144+
# 5 Approval check
151145
/bin/bash ${DIR_PATH}/checkapproval.sh
152146
if [ $? -ne 0 ];then
153147
exit 1

0 commit comments

Comments
 (0)