Skip to content

Commit 378e790

Browse files
committed
cicd: check if sensitive files are modified before cibuild.
Signed-off-by: Tao Peng <[email protected]>
1 parent eee3ee9 commit 378e790

File tree

3 files changed

+134
-4
lines changed

3 files changed

+134
-4
lines changed

.github/workflows/build_x86_64_mlu.yaml

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ on:
1818
branches: [main]
1919
types: [opened, synchronize, reopened]
2020
paths-ignore:
21-
- '.github/**'
22-
- 'cibuild/**'
2321
- 'cmake/**'
2422
- 'docs/**'
2523
- 'third_party/**'
@@ -36,7 +34,66 @@ concurrency:
3634
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
3735

3836
jobs:
37+
check-approval-if-needed:
38+
if: ${{ github.event_name == 'pull_request' }}
39+
runs-on: [self-hosted]
40+
outputs:
41+
requires_approval: ${{ steps.check_sensitive.outputs.requires_approval }}
42+
approved: ${{ steps.check_approved.outputs.approved }}
43+
steps:
44+
- name: Checkout Code
45+
uses: actions/checkout@v4
46+
with:
47+
fetch-depth: 0 # Ensure we can compare commits
48+
49+
- name: Check if sensitive files were changed
50+
id: check_sensitive
51+
run: |
52+
sensitive_files=(
53+
".github/**.yaml"
54+
"cibuild/**.sh"
55+
"setup.py"
56+
)
57+
shopt -s globstar nullglob
58+
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
59+
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
66+
while IFS= read -r changed_file; do
67+
[[ -z "$changed_file" ]] && continue
68+
for pattern in "${sensitive_files[@]}"; do
69+
if [[ "$changed_file" == $pattern ]]; then
70+
requires_approval="true"
71+
break 2
72+
fi
73+
done
74+
done < <(git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.sha }}")
75+
76+
echo "requires_approval=$requires_approval" >> $GITHUB_OUTPUT
77+
78+
- name: Check PR approvals
79+
id: check_approved
80+
if: ${{ steps.check_sensitive.outputs.requires_approval == 'true' }}
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
run: |
84+
pr_number=${{ github.event.pull_request.number }}
85+
response=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
86+
-H "Accept: application/vnd.github.v3+json" \
87+
"https://api.github.com/repos/${{ github.repository }}/pulls/$pr_number/reviews")
88+
89+
if echo "$response" | jq -e '.[] | select(.state == "APPROVED")' > /dev/null; then
90+
echo "approved=true" >> $GITHUB_OUTPUT
91+
else
92+
echo "approved=false" >> $GITHUB_OUTPUT
93+
fi
94+
3995
build:
96+
needs: check-approval-if-needed
4097
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event_name == 'pull_request' }}
4198
runs-on: [self-hosted]
4299
steps:

.github/workflows/build_x86_64_npu.yaml

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ on:
1818
branches: [main]
1919
types: [opened, synchronize, reopened]
2020
paths-ignore:
21-
- '.github/**'
22-
- 'cibuild/**'
2321
- 'cmake/**'
2422
- 'docs/**'
2523
- 'third_party/**'
@@ -36,7 +34,79 @@ concurrency:
3634
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
3735

3836
jobs:
37+
check-approval-if-needed:
38+
if: ${{ github.event_name == 'pull_request' }}
39+
runs-on: [self-hosted]
40+
outputs:
41+
requires_approval: ${{ steps.check_sensitive.outputs.requires_approval }}
42+
approved: ${{ steps.check_approved.outputs.approved }}
43+
steps:
44+
- name: Checkout Code
45+
uses: actions/checkout@v4
46+
with:
47+
fetch-depth: 0 # Ensure we can compare commits
48+
49+
- name: Install jq
50+
run: yum install -y jq
51+
52+
- name: Check if sensitive files were changed
53+
id: check_sensitive
54+
run: |
55+
sensitive_files=(
56+
".github/**.yaml"
57+
"cibuild/**.sh"
58+
"setup.py"
59+
)
60+
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
61+
echo "=======================> changed_files: $changed_files"
62+
requires_approval="false"
63+
#for file in "${sensitive_files[@]}"; do
64+
# if echo "$changed_files" | grep -Fxq "$file"; then
65+
# echo "======================> requires_approval=true"
66+
# requires_approval="true"
67+
# break
68+
# fi
69+
#done
70+
while IFS= read -r changed_file; do
71+
[[ -z "$changed_file" ]] && continue
72+
echo "=========================> start -z changed_file"
73+
for pattern in "${sensitive_files[@]}"; do
74+
echo "=========================> start cmp: $changed_file"
75+
if [[ "$changed_file" == $pattern ]]; then
76+
echo "====================> changed_file == pattern: $changed_file"
77+
requires_approval="true"
78+
break 2
79+
fi
80+
done
81+
done < <(git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.sha }}")
82+
83+
echo "=======================> requires_approval = $requires_approval"
84+
echo "requires_approval=$requires_approval" >> $GITHUB_OUTPUT
85+
86+
- name: Check PR approvals
87+
id: check_approved
88+
if: ${{ steps.check_sensitive.outputs.requires_approval == 'true' }}
89+
echo "=========================> Check PR approvals - true"
90+
env:
91+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
run: |
93+
pr_number=${{ github.event.pull_request.number }}
94+
response=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
95+
-H "Accept: application/vnd.github.v3+json" \
96+
"https://api.github.com/repos/${{ github.repository }}/pulls/$pr_number/reviews")
97+
98+
if echo "$response" | jq -e '.[] | select(.state == "APPROVED")' > /dev/null; then
99+
echo "approved=true" >> $GITHUB_OUTPUT
100+
else
101+
echo "approved=false" >> $GITHUB_OUTPUT
102+
fi
103+
else
104+
echo "=========================> Check PR approvals - no need"
105+
echo "approved=true" >> $GITHUB_OUTPUT
106+
fi
107+
39108
build:
109+
needs: check-approval-if-needed
40110
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event_name == 'pull_request' }}
41111
runs-on: [self-hosted]
42112
steps:

xllm/api_service/chat_service_impl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ ToolCallResult process_tool_calls(std::string text,
5454
google::protobuf::Arena* arena = nullptr) {
5555
ToolCallResult result;
5656

57+
/// --------------
58+
LOG(ERROR) << "====================== test =======================";
59+
5760
function_call::FunctionCallParser parser(tools, parser_format);
5861

5962
if (!parser.has_tool_call(text)) {

0 commit comments

Comments
 (0)