Skip to content

Commit 2345ad3

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

File tree

2 files changed

+98
-40
lines changed

2 files changed

+98
-40
lines changed

.github/workflows/build_x86_64_mlu.yaml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,19 @@ jobs:
7878
- name: Check PR approvals
7979
id: check_approved
8080
if: ${{ steps.check_sensitive.outputs.requires_approval == 'true' }}
81-
echo "=========================> Check PR approvals - true"
82-
env:
83-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84-
run: |
85-
pr_number=${{ github.event.pull_request.number }}
86-
response=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
87-
-H "Accept: application/vnd.github.v3+json" \
88-
"https://api.github.com/repos/${{ github.repository }}/pulls/$pr_number/reviews")
89-
90-
if echo "$response" | jq -e '.[] | select(.state == "APPROVED")' > /dev/null; then
91-
echo "approved=true" >> $GITHUB_OUTPUT
92-
else
93-
echo "approved=false" >> $GITHUB_OUTPUT
94-
fi
95-
else
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")
9688
97-
echo "=========================> Check PR approvals - no need"
98-
echo "approved=true" >> $GITHUB_OUTPUT
99-
fi
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
10094
10195
build:
10296
needs: check-approval-if-needed

.github/workflows/build_x86_64_npu.yaml

Lines changed: 86 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ on:
1717
pull_request:
1818
branches: [main]
1919
types: [opened, synchronize, reopened]
20+
pull_request_review:
21+
types: [submitted]
2022
paths-ignore:
2123
- 'cmake/**'
2224
- 'docs/**'
@@ -34,12 +36,56 @@ concurrency:
3436
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
3537

3638
jobs:
37-
check-approval-if-needed:
38-
if: ${{ github.event_name == 'pull_request' }}
39+
determine-target:
3940
runs-on: [self-hosted]
4041
outputs:
41-
requires_approval: ${{ steps.check_sensitive.outputs.requires_approval }}
42-
approved: ${{ steps.check_approved.outputs.approved }}
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 }}
45+
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
61+
id: decide
62+
run: |
63+
event="${{ github.event_name }}"
64+
if [[ "$event" == "workflow_dispatch" || "$event" == "push" ]]; then
65+
echo "should_run=true" >> $GITHUB_OUTPUT
66+
elif [[ "$event" == "pull_request" ]]; then
67+
echo "should_run=true" >> $GITHUB_OUTPUT
68+
elif [[ "$event" == "pull_request_review" ]]; then
69+
if [[ "${{ github.event.review.state }}" == "approved" ]]; then
70+
echo "should_run=true" >> $GITHUB_OUTPUT
71+
else
72+
echo "should_run=false" >> $GITHUB_OUTPUT
73+
fi
74+
else
75+
echo "should_run=false" >> $GITHUB_OUTPUT
76+
fi
77+
78+
check-sensitive-and-approval:
79+
#if: ${{ github.event_name == 'pull_request' }}
80+
needs: determine-target
81+
if: >
82+
needs.determine-target.outputs.should_run == 'true' &&
83+
(github.event_name == 'pull_request' || github.event_name == 'pull_request_review')
84+
runs-on: [self-hosted]
85+
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 }}
4389
steps:
4490
- name: Checkout Code
4591
uses: actions/checkout@v4
@@ -85,29 +131,47 @@ jobs:
85131
86132
- name: Check PR approvals
87133
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")
134+
if: ${{ github.event_name == 'pull_request' && steps.check_sensitive.outputs.requires_approval == 'true' }}
135+
env:
136+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
137+
run: |
138+
pr_number=${{ github.event.pull_request.number }}
139+
response=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
140+
-H "Accept: application/vnd.github.v3+json" \
141+
"https://api.github.com/repos/${{ github.repository }}/pulls/$pr_number/reviews")
97142
98-
if echo "$response" | jq -e '.[] | select(.state == "APPROVED")' > /dev/null; then
99-
echo "approved=true" >> $GITHUB_OUTPUT
143+
if echo "$response" | jq -e '.[] | select(.state == "APPROVED")' > /dev/null; then
144+
echo "approved=true" >> $GITHUB_OUTPUT
145+
else
146+
echo "approved=false" >> $GITHUB_OUTPUT
147+
fi
148+
149+
- name: Final decision
150+
id: check
151+
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
159+
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
100164
else
101-
echo "approved=false" >> $GITHUB_OUTPUT
165+
echo "can_proceed=false" >> $GITHUB_OUTPUT
102166
fi
103-
else
104-
echo "=========================> Check PR approvals - no need"
105-
echo "approved=true" >> $GITHUB_OUTPUT
106-
fi
167+
fi
107168
108169
build:
109-
needs: check-approval-if-needed
110-
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event_name == 'pull_request' }}
170+
needs: [determine-target, check-sensitive-and-approval]
171+
#if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event_name == 'pull_request' }}
172+
if: >
173+
(github.event_name == 'workflow_dispatch' || github.event_name == 'push') ||
174+
(needs.check-sensitive-and-approval.outputs.can_proceed == 'true')
111175
runs-on: [self-hosted]
112176
steps:
113177
- name: Checkout Code

0 commit comments

Comments
 (0)