diff --git a/.github/workflows/full_pr_e2e_test.yml b/.github/workflows/full_pr_e2e_test.yml index d7fea7a5d..1d76ad5e6 100644 --- a/.github/workflows/full_pr_e2e_test.yml +++ b/.github/workflows/full_pr_e2e_test.yml @@ -18,6 +18,28 @@ jobs: full-es68-e2e-aws-test: runs-on: ubuntu-latest steps: + - name: Check Github Actor is a Maintainer + id: check-maintainer + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_ACTOR: ${{ github.actor }} + run: | + echo "Checking if $GITHUB_ACTOR is a maintainer..." + + # Query the API to get the actor's permissions + permission=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + "${{ github.api_url }}/repos/${{ github.repository }}/collaborators/${GITHUB_ACTOR}/permission" \ + | jq -r '.permission') + + echo "Actor permissions: $permission" + echo "actor_permission=$permission" >> $GITHUB_ENV + + # Fail if the actor is not a maintainer + if [ "$permission" != "admin" ] && [ "$permission" != "write" ]; then + echo "::error::This workflow can only be triggered by a maintainer." + exit 1 + fi - name: Sanitize branch and repo names env: BRANCH_NAME: ${{ github.event.pull_request.head.ref || github.ref_name }} @@ -31,6 +53,7 @@ jobs: echo "branch_name=$clean_branch_name" >> $GITHUB_OUTPUT echo "pr_repo_url=$clean_repo_url" >> $GITHUB_OUTPUT - name: Jenkins Job Trigger and Monitor + if: env.actor_permission == 'admin' || env.actor_permission == 'write' uses: lewijacn/jenkins-trigger@1.0.4 with: jenkins_url: "https://migrations.ci.opensearch.org"