-
Notifications
You must be signed in to change notification settings - Fork 198
54 lines (51 loc) · 2.11 KB
/
require-approval.yml
File metadata and controls
54 lines (51 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
name: Check if the workflow requires approval
on:
workflow_call:
outputs:
is-require-approval:
description: The CI image version for Linux build
value: ${{ jobs.Require-Approval.outputs.output-is-require-approval }}
jobs:
Require-Approval:
runs-on: ubuntu-latest
outputs:
output-is-require-approval: ${{ steps.step-is-require-approval.outputs.is-require-approval }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
- name: Get CodeOwner List
id: step-is-require-approval
run: |
github_event=${{ github.event_name }}
author=${{ github.event.pull_request.user.login }}
if [[ "$github_event" == "push" ]]; then
echo "Push event does not need approval."
echo "is-require-approval=ml-commons-cicd-env" >> $GITHUB_OUTPUT
else
# Handle Pull Request events
# Check if the PR is triggered by opensearch-trigger-bot
if [[ "$author" == "opensearch-trigger-bot[bot]" ]]; then
echo "PR triggered by opensearch-trigger-bot. No approval needed."
echo "is-require-approval=ml-commons-cicd-env" >> $GITHUB_OUTPUT
else
# Check if the author is in the approvers list
approvers=$(cat .github/CODEOWNERS | grep @ | tr -d '* ' | sed 's/@/,/g' | sed 's/,//1')
is_approved=false
IFS=',' read -ra APPROVER_ARRAY <<< "$approvers"
for approver in "${APPROVER_ARRAY[@]}"; do
if [[ "$approver" == "$author" ]]; then
is_approved=true
break
fi
done
if [[ "$is_approved" == "true" ]]; then
echo "$author is in the approval list."
echo "is-require-approval=ml-commons-cicd-env" >> $GITHUB_OUTPUT
else
echo "$author is not in the approval list."
echo "is-require-approval=ml-commons-cicd-env-require-approval" >> $GITHUB_OUTPUT
fi
fi
fi