From c6ee767bf7b1e9794d42b051b0fb03bcd12a743a Mon Sep 17 00:00:00 2001 From: Dhrubo Saha Date: Mon, 21 Oct 2024 13:21:12 -0700 Subject: [PATCH 1/2] allowing backport prs to skip approval Signed-off-by: Dhrubo Saha --- .github/workflows/require-approval.yml | 30 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/workflows/require-approval.yml b/.github/workflows/require-approval.yml index 7da166d618..8875418793 100644 --- a/.github/workflows/require-approval.yml +++ b/.github/workflows/require-approval.yml @@ -1,10 +1,10 @@ --- -name: Check if the workflow require approval +name: Check if the workflow requires approval on: workflow_call: outputs: is-require-approval: - description: The ci image version for linux build + description: The CI image version for Linux build value: ${{ jobs.Require-Approval.outputs.output-is-require-approval }} jobs: @@ -20,17 +20,27 @@ jobs: id: step-is-require-approval run: | github_event=${{ github.event_name }} - if [[ "$github_event" = "push" ]]; then - echo "Push event does not need approval" + 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 - 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 "$author is in the approval list" + # Handle Pull Request events + + # Check if the PR is triggered by opensearch-trigger-bot + if [[ "$author" == "opensearch-trigger-bot" ]]; then + echo "PR triggered by opensearch-trigger-bot. No approval needed." 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 + # Check if the author is in the approvers list + approvers=$(cat .github/CODEOWNERS | grep @ | tr -d '* ' | sed 's/@/,/g' | sed 's/,//1') + if [[ "$approvers" =~ "$author" ]]; 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 From c851138bed89912c7e8fd8d2ca60b1492fb3f40d Mon Sep 17 00:00:00 2001 From: Dhrubo Saha Date: Mon, 21 Oct 2024 13:52:12 -0700 Subject: [PATCH 2/2] updating the condition Signed-off-by: Dhrubo Saha --- .github/workflows/require-approval.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/require-approval.yml b/.github/workflows/require-approval.yml index 8875418793..20dc728cdf 100644 --- a/.github/workflows/require-approval.yml +++ b/.github/workflows/require-approval.yml @@ -29,7 +29,7 @@ jobs: # Handle Pull Request events # Check if the PR is triggered by opensearch-trigger-bot - if [[ "$author" == "opensearch-trigger-bot" ]]; then + if [[ "$github_event" == "pull_request" ]] && [[ "$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