Skip to content

Commit 782926b

Browse files
committed
Switch to codeowners based management for workflow approvals
Signed-off-by: Peter Nied <peternied@hotmail.com>
1 parent 9a26fa7 commit 782926b

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

.github/CODEOWNERS

+3
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@
3535
/.github/ @jed326 @peternied
3636

3737
/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
38+
39+
# Workflow specific approvals checks
40+
/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
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: 'Get the list of approvers for a workflow'
2+
3+
inputs:
4+
workflow-name:
5+
description: 'The name of the workflow to check for approvals, e.g. performance-benchmarks'
6+
required: true
7+
8+
outputs:
9+
workflow-approvers:
10+
description: 'The list of approvers for this workflow'
11+
value: ${{ steps.extract-approvers.outputs.workflow-approvers }}
12+
13+
runs:
14+
using: "composite"
15+
steps:
16+
- id: extract-approvers
17+
shell: bash
18+
run: |
19+
approvers=$(grep "/workflows/${{ inputs.workflow-name }}" .github/CODEOWNERS | cut -d' ' -f2- | sed 's/@//g' | tr ' ' ',')
20+
echo "approvers=$approvers" >> $GITHUB_ENV

.github/workflows/benchmark-pull-request.yml

+6-25
Original file line numberDiff line numberDiff line change
@@ -107,37 +107,18 @@ jobs:
107107
headRefSha=$(echo '${{ steps.get_pr.outputs.result }}' | jq -r '.headRefSha')
108108
echo "prHeadRepo=$headRepo" >> $GITHUB_ENV
109109
echo "prHeadRefSha=$headRefSha" >> $GITHUB_ENV
110-
- id: get_approvers
111-
uses: actions/github-script@v7
110+
- id: workflow_approvers
111+
uses: ./.github/actions/get-workflow-approvers
112112
with:
113-
github-token: ${{ secrets.GITHUB_TOKEN }}
114-
result-encoding: string
115-
script: |
116-
// Get the collaborators - filtered to maintainer permissions
117-
const maintainersResponse = await github.request('GET /repos/{owner}/{repo}/collaborators', {
118-
owner: context.repo.owner,
119-
repo: context.repo.repo,
120-
permission: 'maintain',
121-
affiliation: 'all',
122-
per_page: 100
123-
});
124-
// Any maintainers that do not want to be included on these requests
125-
const excludedMaintainers = [
126-
'peternied',
127-
'hyandell',
128-
];
129-
return maintainersResponse.data
130-
.map(item => item.login)
131-
.filter(approvers => !excludedMaintainers.includes(approvers))
132-
.join(', ');
113+
workflow-name: 'performance-benchmarks'
133114
- uses: trstringer/manual-approval@v1
134-
if: (!contains(steps.get_approvers.outputs.result, github.event.comment.user.login))
115+
if: (!contains(steps.workflow_approvers.outputs.result, github.event.comment.user.login))
135116
with:
136117
secret: ${{ github.TOKEN }}
137-
approvers: ${{ steps.get_approvers.outputs.result }}
118+
approvers: ${{ steps.workflow_approvers.outputs.result }}
138119
minimum-approvals: 1
139120
issue-title: 'Request to approve/deny benchmark run for PR #${{ env.PR_NUMBER }}'
140-
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."
121+
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."
141122
exclude-workflow-initiator-as-approver: false
142123
- name: Checkout PR Repo
143124
uses: actions/checkout@v4

0 commit comments

Comments
 (0)