Skip to content

Commit

Permalink
Add require approval stage so only maintainers can start CI stage wit…
Browse files Browse the repository at this point in the history
…hout approval

Signed-off-by: Peter Zhu <[email protected]>
  • Loading branch information
peterzhuamazon committed Sep 30, 2024
1 parent f4b4724 commit ae5244e
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 179 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/CI-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ permissions:
contents: read

jobs:
Get-Require-Approval:
uses: ./.github/workflows/require-approval.yml

Get-CI-Image-Tag:
uses: opensearch-project/opensearch-build/.github/workflows/get-ci-image-tag.yml@main
with:
product: opensearch

Build-ml-linux:
needs: Get-CI-Image-Tag
needs: [Get-Require-Approval, Get-CI-Image-Tag]
strategy:
matrix:
java: [21]
Expand All @@ -29,7 +32,7 @@ jobs:

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


Test-ml-linux-docker:
needs: Build-ml-linux
needs: [Get-Require-Approval, Build-ml-linux]
strategy:
matrix:
java: [21]

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

steps:
Expand Down Expand Up @@ -189,7 +192,8 @@ jobs:
java: [21]
name: Build and Test MLCommons Plugin on Windows
if: github.repository == 'opensearch-project/ml-commons'
environment: ml-commons-cicd-env
needs: [Get-Require-Approval]
environment: ${{ needs.Get-Require-Approval.outputs.is-require-approval }}
runs-on: windows-latest

steps:
Expand Down
19 changes: 0 additions & 19 deletions .github/workflows/add-untriaged.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/auto-release.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/backport.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/delete_backport_branch.yml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/draft-release-notes-workflow.yml

This file was deleted.

26 changes: 0 additions & 26 deletions .github/workflows/labeler.yml

This file was deleted.

38 changes: 0 additions & 38 deletions .github/workflows/maven-publish.yml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/require-approval.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Check if the workflow require 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 }}
if [[ "$github_event" = "push" ]]; then
echo "Push event does not need approval"
echo "is-require-approval=ml-commons-cicd-env" >> $GITHUB_OUTPUT
else
approvers=$(cat .github/CODEOWNERS | grep @ | tr -d '* ' | sed 's/@/,/g' | sed 's/,//1')
author=${{ github.event.pull_request.user.login }}
if [[ "$approvers" =~ "$author" ]]; then
echo "$authoer 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

0 comments on commit ae5244e

Please sign in to comment.