1+ # Copyright 2025 The Authors (see AUTHORS file)
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ name : ' multi-approvers'
16+
17+ on :
18+ workflow_call :
19+ inputs :
20+ # Path to a JSON file containing the members of the org. This should be
21+ # the full path from the repo root without a leading `/`.
22+ # See the README for more.
23+ org-members-path :
24+ required : true
25+ type : ' string'
26+ multi-approvers-js-url :
27+ description : ' The URL to multi-approvers.js. This should typically not need to be set.'
28+ type : ' string'
29+ default : ' https://raw.githubusercontent.com/abcxyz/pkg/main/.github/workflows/multi-approvers.js'
30+
31+
32+ permissions :
33+ actions : ' write'
34+ contents : ' read'
35+ pull-requests : ' read'
36+
37+ jobs :
38+ multi-approvers :
39+ if : |-
40+ contains(fromJSON('["pull_request", "pull_request_review"]'), github.event_name)
41+ runs-on : ' ubuntu-latest'
42+ steps :
43+ - name : ' Checkout the calling repo'
44+ uses : ' actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4
45+
46+ - name : ' Download multi-approvers.js'
47+ id : ' download-multi-approvers-js'
48+ run : |-
49+ MULTI_APPROVERS_JS="${RUNNER_TEMP}/${GITHUB_SHA:0:7}.multi-approvers.js"
50+
51+ # Download the file, passing in authentication to get a higher rate
52+ # limit: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limits-for-requests-from-github-actions
53+ curl "${{ inputs.multi-approvers-js-url }}" \
54+ --silent \
55+ --fail \
56+ --location \
57+ --header "Authorization: Token ${{ github.token }}" \
58+ --output "${MULTI_APPROVERS_JS}"
59+
60+ # Save the result to an output.
61+ echo "::notice::Downloaded multi-approvers.js to ${MULTI_APPROVERS_JS}"
62+ echo "output-file=${MULTI_APPROVERS_JS}" >> "${GITHUB_OUTPUT}"
63+
64+ - name : ' Check approver requirements'
65+ uses : ' actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7
66+ with :
67+ retries : 3
68+ script : |-
69+ let orgMembersPath = '${{ inputs.org-members-path }}';
70+ if (!orgMembersPath.startsWith('/')) {
71+ orgMembersPath = '${{ github.workspace }}/${{ inputs.org-members-path }}';
72+ }
73+ // Warning: this should not be quoted, otherwise comparisons will not work in JS.
74+ const prNumber = ${{ github.event.pull_request.number }}
75+ const repoName = '${{ github.event.repository.name }}'
76+ const repoOwner = '${{ github.event.repository.owner.login }}'
77+ const {onPullRequest} = require('${{ steps.download-multi-approvers-js.outputs.output-file }}');
78+ await onPullRequest({
79+ orgMembersPath,
80+ prNumber,
81+ repoName,
82+ repoOwner,
83+ github,
84+ core,
85+ });
86+
87+ - name : ' Re-run approver checks'
88+ if : |-
89+ github.event_name == 'pull_request_review'
90+ uses : ' actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7
91+ with :
92+ retries : 3
93+ script : |-
94+ const branch = '${{ github.event.pull_request.head.ref }}'
95+ // Warning: this should not be quoted, otherwise comparisons will not work in JS.
96+ const prNumber = ${{ github.event.pull_request.number }}
97+ const repoName = '${{ github.event.repository.name }}'
98+ const repoOwner = '${{ github.event.repository.owner.login }}'
99+ const workflowRef = '${{ github.workflow_ref }}';
100+ const {onPullRequestReview} = require('${{ steps.download-multi-approvers-js.outputs.output-file }}');
101+ await onPullRequestReview({
102+ branch,
103+ prNumber,
104+ repoName,
105+ repoOwner,
106+ workflowRef,
107+ github,
108+ core,
109+ });
0 commit comments