Skip to content

Commit a364f14

Browse files
Add Test Env Require Approval Action (opensearch-project#3005) (opensearch-project#3016)
* Add require approval stage so only maintainers can start CI stage without approval Signed-off-by: Peter Zhu <[email protected]> * Add more Signed-off-by: Peter Zhu <[email protected]> * Add more Signed-off-by: Peter Zhu <[email protected]> * Add old files Signed-off-by: Peter Zhu <[email protected]> * Update require-approval.yml Signed-off-by: Peter Zhu <[email protected]> --------- Signed-off-by: Peter Zhu <[email protected]> (cherry picked from commit 9de2d23) Co-authored-by: Peter Zhu <[email protected]>
1 parent 670e461 commit a364f14

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

.github/workflows/CI-workflow.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ permissions:
1414
contents: read
1515

1616
jobs:
17+
Get-Require-Approval:
18+
uses: ./.github/workflows/require-approval.yml
19+
1720
Get-CI-Image-Tag:
1821
uses: opensearch-project/opensearch-build/.github/workflows/get-ci-image-tag.yml@main
1922
with:
2023
product: opensearch
2124

2225
Build-ml-linux:
23-
needs: Get-CI-Image-Tag
26+
needs: [Get-Require-Approval, Get-CI-Image-Tag]
2427
strategy:
2528
matrix:
2629
java: [11, 17, 21]
@@ -29,7 +32,7 @@ jobs:
2932

3033
name: Build and Test MLCommons Plugin on linux
3134
if: github.repository == 'opensearch-project/ml-commons'
32-
environment: ml-commons-cicd-env
35+
environment: ${{ needs.Get-Require-Approval.outputs.is-require-approval }}
3336
outputs:
3437
build-test-linux: ${{ steps.step-build-test-linux.outputs.build-test-linux }}
3538
runs-on: ubuntu-latest
@@ -87,14 +90,14 @@ jobs:
8790

8891

8992
Test-ml-linux-docker:
90-
needs: Build-ml-linux
93+
needs: [Get-Require-Approval, Build-ml-linux]
9194
strategy:
9295
matrix:
9396
java: [11, 17, 21]
9497

9598
name: Test MLCommons Plugin on linux docker
9699
if: github.repository == 'opensearch-project/ml-commons'
97-
environment: ml-commons-cicd-env
100+
environment: ${{ needs.Get-Require-Approval.outputs.is-require-approval }}
98101
runs-on: ubuntu-latest
99102

100103
steps:
@@ -184,7 +187,8 @@ jobs:
184187
java: [11, 17, 21]
185188
name: Build and Test MLCommons Plugin on Windows
186189
if: github.repository == 'opensearch-project/ml-commons'
187-
environment: ml-commons-cicd-env
190+
needs: [Get-Require-Approval]
191+
environment: ${{ needs.Get-Require-Approval.outputs.is-require-approval }}
188192
runs-on: windows-latest
189193

190194
steps:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: Check if the workflow require approval
3+
on:
4+
workflow_call:
5+
outputs:
6+
is-require-approval:
7+
description: The ci image version for linux build
8+
value: ${{ jobs.Require-Approval.outputs.output-is-require-approval }}
9+
10+
jobs:
11+
Require-Approval:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
output-is-require-approval: ${{ steps.step-is-require-approval.outputs.is-require-approval }}
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
ref: ${{ github.event.pull_request.base.sha }}
19+
- name: Get CodeOwner List
20+
id: step-is-require-approval
21+
run: |
22+
github_event=${{ github.event_name }}
23+
if [[ "$github_event" = "push" ]]; then
24+
echo "Push event does not need approval"
25+
echo "is-require-approval=ml-commons-cicd-env" >> $GITHUB_OUTPUT
26+
else
27+
approvers=$(cat .github/CODEOWNERS | grep @ | tr -d '* ' | sed 's/@/,/g' | sed 's/,//1')
28+
author=${{ github.event.pull_request.user.login }}
29+
if [[ "$approvers" =~ "$author" ]]; then
30+
echo "$author is in the approval list"
31+
echo "is-require-approval=ml-commons-cicd-env" >> $GITHUB_OUTPUT
32+
else
33+
echo "$author is not in the approval list"
34+
echo "is-require-approval=ml-commons-cicd-env-require-approval" >> $GITHUB_OUTPUT
35+
fi
36+
fi

0 commit comments

Comments
 (0)