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
3638jobs :
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
85131
86132 - name : Check PR approvals
87133 id : check_approved
88- if : ${{ steps.check_sensitive.outputs.requires_approval == 'true' }}
134+ if ${{ github.event_name == 'pull_request' && steps.check_sensitive.outputs.requires_approval == 'true' }}; then
89135 echo "=========================> Check PR approvals - true"
90136 env :
91137 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -105,9 +151,32 @@ jobs:
105151 echo "approved=true" >> $GITHUB_OUTPUT
106152 fi
107153
154+ - name : Final decision
155+ id : check
156+ run : |
157+ if [ "${{ github.event_name }}" == "pull_request_review" ]; then
158+ echo "can_proceed=true" >> $GITHUB_OUTPUT
159+ #if [ "${{ steps.check_sensitive.outputs.requires_approval }}" == "true" ]; then
160+ # echo "can_proceed=true" >> $GITHUB_OUTPUT
161+ #else
162+ # echo "can_proceed=true" >> $GITHUB_OUTPUT
163+ #fi
164+ else
165+ if [ "${{ steps.check_sensitive.outputs.requires_approval }}" != "true" ]; then
166+ echo "can_proceed=true" >> $GITHUB_OUTPUT
167+ elif [ "${{ steps.check_approved.outputs.approved }}" == "true" ]; then
168+ echo "can_proceed=true" >> $GITHUB_OUTPUT
169+ else
170+ echo "can_proceed=false" >> $GITHUB_OUTPUT
171+ fi
172+ fi
173+
108174 build :
109- needs : check-approval-if-needed
110- if : ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event_name == 'pull_request' }}
175+ needs : [determine-target, check-sensitive-and-approval]
176+ # if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event_name == 'pull_request' }}
177+ if : >
178+ (github.event_name == 'workflow_dispatch' || github.event_name == 'push') ||
179+ (needs.check-sensitive-and-approval.outputs.can_proceed == 'true')
111180 runs-on : [self-hosted]
112181 steps :
113182 - name : Checkout Code
0 commit comments