New approvals workflow #318
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Enforce Tiered Approvals | |
on: | |
pull_request_review: | |
pull_request: # TODO: remove | |
env: | |
TIER2_REVIEWERS: | | |
jstjohn | |
trvachov | |
pstjohn | |
jomitchellnv | |
jobs: | |
enforce_tiered_approvals: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get PR reviews | |
id: get_reviews | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { data: reviews } = await github.rest.pulls.listReviews({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.payload.pull_request.number, | |
}); | |
const latestReviews = {}; | |
for (const review of reviews) { | |
latestReviews[review.user.login] = review.state; | |
} | |
console.log('Latest Reviews:', latestReviews); | |
const approvedUsers = Object.keys(latestReviews).filter(user => latestReviews[user] === 'APPROVED'); | |
core.setOutput('approvedUsers', approvedUsers.join(',')); | |
- name: Check +2 approvals (global tier) | |
id: check_tier2 | |
run: | | |
echo "Checking for +2 approvals..." | |
APPROVED_USERS="${{ steps.get_reviews.outputs.approvedUsers }}" | |
TIER2_APPROVED=false | |
echo "Approved Users: $APPROVED_USERS" | |
echo "Tier 2 Reviewers: $TIER2_REVIEWERS" | |
# Iterate over approved users and compare with cleaned TIER2_REVIEWERS | |
for USER in ${APPROVED_USERS//,/ }; do | |
echo "Checking approved USER: $USER" | |
for REVIEWER in "${TIER2_REVIEWERS[@]}"; do | |
echo "Comparing USER: $USER with REVIEWER: $REVIEWER" | |
if [[ "$USER" == "$REVIEWER" ]]; then | |
TIER2_APPROVED=true | |
break 2 | |
fi | |
done | |
done | |
if [[ "$TIER2_APPROVED" == "true" ]]; then | |
echo "A +2 reviewer has approved the pull request." | |
else | |
echo "No +2 reviewer has approved the pull request." | |
exit 1 | |
fi |