Skip to content

Commit 8f7bce3

Browse files
committed
test
Signed-off-by: Tao Peng <[email protected]>
1 parent 2345ad3 commit 8f7bce3

File tree

2 files changed

+141
-77
lines changed

2 files changed

+141
-77
lines changed

.github/workflows/build_x86_64_mlu.yaml

Lines changed: 85 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ on:
2525
- '*.md'
2626
- '*.txt'
2727
- '*.yml'
28-
28+
pull_request_review:
29+
types: [submitted]
30+
paths-ignore:
31+
- 'cmake/**'
32+
- 'docs/**'
33+
- 'third_party/**'
34+
- 'tools/**'
35+
- '*.md'
36+
- '*.txt'
37+
- '*.yml'
2938
env:
3039
JOBNAME: xllm-x86_64-mlu-cibuild-${{ github.run_id }}
3140

@@ -34,18 +43,56 @@ concurrency:
3443
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
3544

3645
jobs:
37-
check-approval-if-needed:
38-
if: ${{ github.event_name == 'pull_request' }}
46+
# need to review code first when sensitive files are modified.
47+
check-sensitive-step-1:
48+
runs-on: [self-hosted]
49+
outputs:
50+
should_check: ${{ steps.decide.outputs.should_check }}
51+
approved: ${{ steps.decide.outputs.approved }}
52+
steps:
53+
- name: Decide whether to check sensitive file
54+
id: decide
55+
run: |
56+
event="${{ github.event_name }}"
57+
if [[ "$event" == "workflow_dispatch" || "$event" == "push" ]]; then
58+
echo "ignore workflow_dispatch and push events in check-sensitive-step-1."
59+
echo "should_check=false" >> $GITHUB_OUTPUT
60+
echo "approved=false" >> $GITHUB_OUTPUT
61+
elif [[ "$event" == "pull_request" ]]; then
62+
echo "should_check=true" >> $GITHUB_OUTPUT
63+
echo "approved=false" >> $GITHUB_OUTPUT
64+
elif [[ "$event" == "pull_request_review" ]]; then
65+
if [[ "${{ github.event.review.state }}" == "approved" ]]; then
66+
echo "should_check=false" >> $GITHUB_OUTPUT
67+
echo "approved=true" >> $GITHUB_OUTPUT
68+
else
69+
echo "should_check=false" >> $GITHUB_OUTPUT
70+
echo "approved=false" >> $GITHUB_OUTPUT
71+
fi
72+
else
73+
echo "should_check=false" >> $GITHUB_OUTPUT
74+
echo "approved=false" >> $GITHUB_OUTPUT
75+
fi
76+
77+
check-sensitive-step-2:
78+
needs: check-sensitive-step-1
79+
#if: >
80+
# needs.check-sensitive-step-1.outputs.should_check == 'true' &&
81+
# (github.event_name == 'pull_request' || github.event_name == 'pull_request_review')
82+
if: >
83+
needs.check-sensitive-step-1.outputs.should_check == 'true' && github.event_name == 'pull_request'
3984
runs-on: [self-hosted]
4085
outputs:
41-
requires_approval: ${{ steps.check_sensitive.outputs.requires_approval }}
42-
approved: ${{ steps.check_approved.outputs.approved }}
86+
do_build: ${{ steps.check.outputs.do_build }}
4387
steps:
4488
- name: Checkout Code
4589
uses: actions/checkout@v4
4690
with:
4791
fetch-depth: 0 # Ensure we can compare commits
4892

93+
- name: Install jq
94+
run: yum install -y jq
95+
4996
- name: Check if sensitive files were changed
5097
id: check_sensitive
5198
run: |
@@ -54,15 +101,8 @@ jobs:
54101
"cibuild/**.sh"
55102
"setup.py"
56103
)
57-
shopt -s globstar nullglob
58104
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
59105
requires_approval="false"
60-
#for file in "${sensitive_files[@]}"; do
61-
# if echo "$changed_files" | grep -Fxq "$file"; then
62-
# requires_approval="true"
63-
# break
64-
# fi
65-
#done
66106
while IFS= read -r changed_file; do
67107
[[ -z "$changed_file" ]] && continue
68108
for pattern in "${sensitive_files[@]}"; do
@@ -77,7 +117,7 @@ jobs:
77117
78118
- name: Check PR approvals
79119
id: check_approved
80-
if: ${{ steps.check_sensitive.outputs.requires_approval == 'true' }}
120+
if: ${{ github.event_name == 'pull_request' && steps.check_sensitive.outputs.requires_approval == 'true' }}
81121
env:
82122
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83123
run: |
@@ -92,9 +132,39 @@ jobs:
92132
echo "approved=false" >> $GITHUB_OUTPUT
93133
fi
94134
135+
- name: Final check
136+
id: check
137+
run: |
138+
if [ "${{ steps.check_sensitive.outputs.requires_approval }}" != "true" ]; then
139+
echo "do_build=true" >> $GITHUB_OUTPUT
140+
elif [ "${{ steps.check_approved.outputs.approved }}" == "true" ]; then
141+
echo "do_build=true" >> $GITHUB_OUTPUT
142+
else
143+
echo "do_build=false" >> $GITHUB_OUTPUT
144+
fi
145+
146+
check-sensitive-step-3:
147+
needs: check-sensitive-step-1
148+
if: >
149+
github.event_name == 'pull_request_review'
150+
runs-on: [self-hosted]
151+
outputs:
152+
do_build: ${{ steps.check.outputs.do_build }}
153+
steps:
154+
- name: Checkout status
155+
id: check
156+
run:
157+
if [ "${{ needs.check-sensitive-step-1.outputs.approved }}" == "true" ]; then
158+
echo "do_build=true" >> $GITHUB_OUTPUT
159+
else
160+
echo "do_build=false" >> $GITHUB_OUTPUT
161+
fi
162+
95163
build:
96-
needs: check-approval-if-needed
97-
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event_name == 'pull_request' }}
164+
needs: [check-sensitive-step-1, check-sensitive-step-2, check-sensitive-step-3]
165+
if: >
166+
(github.event_name == 'workflow_dispatch' || github.event_name == 'push') ||
167+
(needs.check-sensitive-step-2.outputs.do_build == 'true' || needs.check-sensitive-step-3.outputs.do_build == 'true')
98168
runs-on: [self-hosted]
99169
steps:
100170
- name: Checkout Code

.github/workflows/build_x86_64_npu.yaml

Lines changed: 56 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ on:
1717
pull_request:
1818
branches: [main]
1919
types: [opened, synchronize, reopened]
20+
paths-ignore:
21+
- 'cmake/**'
22+
- 'docs/**'
23+
- 'third_party/**'
24+
- 'tools/**'
25+
- '*.md'
26+
- '*.txt'
27+
- '*.yml'
2028
pull_request_review:
2129
types: [submitted]
2230
paths-ignore:
@@ -36,56 +44,47 @@ concurrency:
3644
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
3745

3846
jobs:
39-
determine-target:
47+
# need to review code first when sensitive files are modified.
48+
check-sensitive-step-1:
4049
runs-on: [self-hosted]
4150
outputs:
42-
should_run: ${{ steps.decide.outputs.should_run }}
43-
pr_number: ${{ steps.set_vars.outputs.pr_number }}
44-
head_sha: ${{ steps.set_vars.outputs.head_sha }}
51+
should_check: ${{ steps.decide.outputs.should_check }}
52+
approved: ${{ steps.decide.outputs.approved }}
4553
steps:
46-
- name: Set variables based on event
47-
id: set_vars
48-
run: |
49-
if [ "${{ github.event_name }}" == "pull_request_review" ]; then
50-
echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
51-
echo "head_sha=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
52-
elif [ "${{ github.event_name }}" == "pull_request" ]; then
53-
echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
54-
echo "head_sha=${{ github.sha }}" >> $GITHUB_OUTPUT
55-
else
56-
echo "pr_number=" >> $GITHUB_OUTPUT
57-
echo "head_sha=${{ github.sha }}" >> $GITHUB_OUTPUT
58-
fi
59-
60-
- name: Decide whether to run build
54+
- name: Decide whether to check sensitive file
6155
id: decide
6256
run: |
6357
event="${{ github.event_name }}"
6458
if [[ "$event" == "workflow_dispatch" || "$event" == "push" ]]; then
65-
echo "should_run=true" >> $GITHUB_OUTPUT
59+
echo "ignore workflow_dispatch and push events in check-sensitive-step-1."
60+
echo "should_check=false" >> $GITHUB_OUTPUT
61+
echo "approved=false" >> $GITHUB_OUTPUT
6662
elif [[ "$event" == "pull_request" ]]; then
67-
echo "should_run=true" >> $GITHUB_OUTPUT
63+
echo "should_check=true" >> $GITHUB_OUTPUT
64+
echo "approved=false" >> $GITHUB_OUTPUT
6865
elif [[ "$event" == "pull_request_review" ]]; then
6966
if [[ "${{ github.event.review.state }}" == "approved" ]]; then
70-
echo "should_run=true" >> $GITHUB_OUTPUT
67+
echo "should_check=false" >> $GITHUB_OUTPUT
68+
echo "approved=true" >> $GITHUB_OUTPUT
7169
else
72-
echo "should_run=false" >> $GITHUB_OUTPUT
70+
echo "should_check=false" >> $GITHUB_OUTPUT
71+
echo "approved=false" >> $GITHUB_OUTPUT
7372
fi
7473
else
75-
echo "should_run=false" >> $GITHUB_OUTPUT
74+
echo "should_check=false" >> $GITHUB_OUTPUT
75+
echo "approved=false" >> $GITHUB_OUTPUT
7676
fi
7777
78-
check-sensitive-and-approval:
79-
#if: ${{ github.event_name == 'pull_request' }}
80-
needs: determine-target
78+
check-sensitive-step-2:
79+
needs: check-sensitive-step-1
80+
#if: >
81+
# needs.check-sensitive-step-1.outputs.should_check == 'true' &&
82+
# (github.event_name == 'pull_request' || github.event_name == 'pull_request_review')
8183
if: >
82-
needs.determine-target.outputs.should_run == 'true' &&
83-
(github.event_name == 'pull_request' || github.event_name == 'pull_request_review')
84+
needs.check-sensitive-step-1.outputs.should_check == 'true' && github.event_name == 'pull_request'
8485
runs-on: [self-hosted]
8586
outputs:
86-
#requires_approval: ${{ steps.check_sensitive.outputs.requires_approval }}
87-
#approved: ${{ steps.check_approved.outputs.approved }}
88-
can_proceed: ${{ steps.check.outputs.can_proceed }}
87+
do_build: ${{ steps.check.outputs.do_build }}
8988
steps:
9089
- name: Checkout Code
9190
uses: actions/checkout@v4
@@ -104,29 +103,17 @@ jobs:
104103
"setup.py"
105104
)
106105
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
107-
echo "=======================> changed_files: $changed_files"
108106
requires_approval="false"
109-
#for file in "${sensitive_files[@]}"; do
110-
# if echo "$changed_files" | grep -Fxq "$file"; then
111-
# echo "======================> requires_approval=true"
112-
# requires_approval="true"
113-
# break
114-
# fi
115-
#done
116107
while IFS= read -r changed_file; do
117108
[[ -z "$changed_file" ]] && continue
118-
echo "=========================> start -z changed_file"
119109
for pattern in "${sensitive_files[@]}"; do
120-
echo "=========================> start cmp: $changed_file"
121110
if [[ "$changed_file" == $pattern ]]; then
122-
echo "====================> changed_file == pattern: $changed_file"
123111
requires_approval="true"
124112
break 2
125113
fi
126114
done
127115
done < <(git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.sha }}")
128116
129-
echo "=======================> requires_approval = $requires_approval"
130117
echo "requires_approval=$requires_approval" >> $GITHUB_OUTPUT
131118
132119
- name: Check PR approvals
@@ -146,32 +133,39 @@ jobs:
146133
echo "approved=false" >> $GITHUB_OUTPUT
147134
fi
148135
149-
- name: Final decision
136+
- name: Final check
150137
id: check
151138
run: |
152-
if [ "${{ github.event_name }}" == "pull_request_review" ]; then
153-
echo "can_proceed=true" >> $GITHUB_OUTPUT
154-
#if [ "${{ steps.check_sensitive.outputs.requires_approval }}" == "true" ]; then
155-
# echo "can_proceed=true" >> $GITHUB_OUTPUT
156-
#else
157-
# echo "can_proceed=true" >> $GITHUB_OUTPUT
158-
#fi
139+
if [ "${{ steps.check_sensitive.outputs.requires_approval }}" != "true" ]; then
140+
echo "do_build=true" >> $GITHUB_OUTPUT
141+
elif [ "${{ steps.check_approved.outputs.approved }}" == "true" ]; then
142+
echo "do_build=true" >> $GITHUB_OUTPUT
159143
else
160-
if [ "${{ steps.check_sensitive.outputs.requires_approval }}" != "true" ]; then
161-
echo "can_proceed=true" >> $GITHUB_OUTPUT
162-
elif [ "${{ steps.check_approved.outputs.approved }}" == "true" ]; then
163-
echo "can_proceed=true" >> $GITHUB_OUTPUT
164-
else
165-
echo "can_proceed=false" >> $GITHUB_OUTPUT
166-
fi
144+
echo "do_build=false" >> $GITHUB_OUTPUT
145+
fi
146+
147+
check-sensitive-step-3:
148+
needs: check-sensitive-step-1
149+
if: >
150+
github.event_name == 'pull_request_review'
151+
runs-on: [self-hosted]
152+
outputs:
153+
do_build: ${{ steps.check.outputs.do_build }}
154+
steps:
155+
- name: Checkout status
156+
id: check
157+
run:
158+
if [ "${{ needs.check-sensitive-step-1.outputs.approved }}" == "true" ]; then
159+
echo "do_build=true" >> $GITHUB_OUTPUT
160+
else
161+
echo "do_build=false" >> $GITHUB_OUTPUT
167162
fi
168163

169164
build:
170-
needs: [determine-target, check-sensitive-and-approval]
171-
#if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event_name == 'pull_request' }}
165+
needs: [check-sensitive-step-1, check-sensitive-step-2, check-sensitive-step-3]
172166
if: >
173167
(github.event_name == 'workflow_dispatch' || github.event_name == 'push') ||
174-
(needs.check-sensitive-and-approval.outputs.can_proceed == 'true')
168+
(needs.check-sensitive-step-2.outputs.do_build == 'true' || needs.check-sensitive-step-3.outputs.do_build == 'true')
175169
runs-on: [self-hosted]
176170
steps:
177171
- name: Checkout Code

0 commit comments

Comments
 (0)