From 9bc325a1b75fa66dbcc5698fb49a1b4c967cf37f Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Wed, 28 Aug 2024 13:51:59 +0000 Subject: [PATCH 1/3] Allow maintainers to opt-out of perf workflow approval requests Tweak the logic for the maintainer list that becomes the assigned approvers on GitHub issues so that maintainers can opt out of this approval process. Signed-off-by: Peter Nied --- .github/workflows/benchmark-pull-request.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/benchmark-pull-request.yml b/.github/workflows/benchmark-pull-request.yml index c494df6e27ce3..b975e8b08b15d 100644 --- a/.github/workflows/benchmark-pull-request.yml +++ b/.github/workflows/benchmark-pull-request.yml @@ -121,7 +121,14 @@ jobs: affiliation: 'all', per_page: 100 }); - return maintainersResponse.data.map(item => item.login).join(', '); + // Any maintainers that do not want to be included on these requests + const excludedMaintainers = [ + 'peternied', + ]; + return maintainersResponse.data + .map(item => item.login) + .filter(approvers => !excludedMaintainers.includes(approvers)) + .join(', '); - uses: trstringer/manual-approval@v1 if: (!contains(steps.get_approvers.outputs.result, github.event.comment.user.login)) with: From 9a26fa79bb07189ac3f664b9a3c428e7f9d0355e Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Wed, 28 Aug 2024 14:08:08 +0000 Subject: [PATCH 2/3] Remove Henri since his is an org admin and add a message in the issue for other maintainers to opt-out if desired. Signed-off-by: Peter Nied --- .github/workflows/benchmark-pull-request.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/benchmark-pull-request.yml b/.github/workflows/benchmark-pull-request.yml index b975e8b08b15d..3616342a392de 100644 --- a/.github/workflows/benchmark-pull-request.yml +++ b/.github/workflows/benchmark-pull-request.yml @@ -124,6 +124,7 @@ jobs: // Any maintainers that do not want to be included on these requests const excludedMaintainers = [ 'peternied', + 'hyandell', ]; return maintainersResponse.data .map(item => item.login) @@ -136,7 +137,7 @@ jobs: approvers: ${{ steps.get_approvers.outputs.result }} minimum-approvals: 1 issue-title: 'Request to approve/deny benchmark run for PR #${{ env.PR_NUMBER }}' - issue-body: "Please approve or deny the benchmark run for PR #${{ env.PR_NUMBER }}" + issue-body: "Please approve or deny the benchmark run for PR #${{ env.PR_NUMBER }}, please update this [workflow](../tree/main/.github/workflows/benchmark-pull-request.yml) to opt-out of future requests." exclude-workflow-initiator-as-approver: false - name: Checkout PR Repo uses: actions/checkout@v4 From 782926ba137b35c3964203ad71af05eb4be07f68 Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Thu, 29 Aug 2024 19:27:44 +0000 Subject: [PATCH 3/3] Switch to codeowners based management for workflow approvals Signed-off-by: Peter Nied --- .github/CODEOWNERS | 3 ++ .github/actions/workflow-approvers.yml | 20 +++++++++++++ .github/workflows/benchmark-pull-request.yml | 31 ++++---------------- 3 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 .github/actions/workflow-approvers.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 18a310862dfbb..1736b477074f6 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -35,3 +35,6 @@ /.github/ @jed326 @peternied /MAINTAINERS.md @anasalkouz @andrross @ashking94 @Bukhtawar @CEHENKLE @dblock @dbwiddis @gaobinlong @gbbafna @jed326 @kotwanikunal @mch2 @msfroh @nknize @owaiskazi19 @peternied @reta @Rishikesh1159 @sachinpkale @saratvemulapalli @shwetathareja @sohami @VachaShah + +# Workflow specific approvals checks +/workflows/performance-benchmarks @anasalkouz @andrross @ashking94 @Bukhtawar @CEHENKLE @dblock @dbwiddis @gaobinlong @gbbafna @jed326 @kotwanikunal @mch2 @msfroh @nknize @owaiskazi19 @reta @Rishikesh1159 @sachinpkale @saratvemulapalli @shwetathareja @sohami @VachaShah \ No newline at end of file diff --git a/.github/actions/workflow-approvers.yml b/.github/actions/workflow-approvers.yml new file mode 100644 index 0000000000000..77589e74e3571 --- /dev/null +++ b/.github/actions/workflow-approvers.yml @@ -0,0 +1,20 @@ +name: 'Get the list of approvers for a workflow' + +inputs: + workflow-name: + description: 'The name of the workflow to check for approvals, e.g. performance-benchmarks' + required: true + +outputs: + workflow-approvers: + description: 'The list of approvers for this workflow' + value: ${{ steps.extract-approvers.outputs.workflow-approvers }} + +runs: + using: "composite" + steps: + - id: extract-approvers + shell: bash + run: | + approvers=$(grep "/workflows/${{ inputs.workflow-name }}" .github/CODEOWNERS | cut -d' ' -f2- | sed 's/@//g' | tr ' ' ',') + echo "approvers=$approvers" >> $GITHUB_ENV \ No newline at end of file diff --git a/.github/workflows/benchmark-pull-request.yml b/.github/workflows/benchmark-pull-request.yml index 3616342a392de..7779ca09582ef 100644 --- a/.github/workflows/benchmark-pull-request.yml +++ b/.github/workflows/benchmark-pull-request.yml @@ -107,37 +107,18 @@ jobs: headRefSha=$(echo '${{ steps.get_pr.outputs.result }}' | jq -r '.headRefSha') echo "prHeadRepo=$headRepo" >> $GITHUB_ENV echo "prHeadRefSha=$headRefSha" >> $GITHUB_ENV - - id: get_approvers - uses: actions/github-script@v7 + - id: workflow_approvers + uses: ./.github/actions/get-workflow-approvers with: - github-token: ${{ secrets.GITHUB_TOKEN }} - result-encoding: string - script: | - // Get the collaborators - filtered to maintainer permissions - const maintainersResponse = await github.request('GET /repos/{owner}/{repo}/collaborators', { - owner: context.repo.owner, - repo: context.repo.repo, - permission: 'maintain', - affiliation: 'all', - per_page: 100 - }); - // Any maintainers that do not want to be included on these requests - const excludedMaintainers = [ - 'peternied', - 'hyandell', - ]; - return maintainersResponse.data - .map(item => item.login) - .filter(approvers => !excludedMaintainers.includes(approvers)) - .join(', '); + workflow-name: 'performance-benchmarks' - uses: trstringer/manual-approval@v1 - if: (!contains(steps.get_approvers.outputs.result, github.event.comment.user.login)) + if: (!contains(steps.workflow_approvers.outputs.result, github.event.comment.user.login)) with: secret: ${{ github.TOKEN }} - approvers: ${{ steps.get_approvers.outputs.result }} + approvers: ${{ steps.workflow_approvers.outputs.result }} minimum-approvals: 1 issue-title: 'Request to approve/deny benchmark run for PR #${{ env.PR_NUMBER }}' - issue-body: "Please approve or deny the benchmark run for PR #${{ env.PR_NUMBER }}, please update this [workflow](../tree/main/.github/workflows/benchmark-pull-request.yml) to opt-out of future requests." + issue-body: "Please approve or deny the benchmark run for PR #${{ env.PR_NUMBER }}, please update [CODEOWNERS](../tree/main/.github/CODEOWNERS) to opt-out of future workflow approval requests." exclude-workflow-initiator-as-approver: false - name: Checkout PR Repo uses: actions/checkout@v4