From 089a8304a58d516b3afb90462e7a4b12298baf61 Mon Sep 17 00:00:00 2001 From: Mats Kindahl Date: Mon, 2 Dec 2024 09:09:38 +0100 Subject: [PATCH] Fix issue with PR approval workflow Remove event information from workflow and count the number of files rather than try to test for them. Also include approvers that have "NONE" as author status. --- .github/workflows/pr-approvals.yaml | 32 +++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pr-approvals.yaml b/.github/workflows/pr-approvals.yaml index 349b29638b8..32fa57001bb 100644 --- a/.github/workflows/pr-approvals.yaml +++ b/.github/workflows/pr-approvals.yaml @@ -25,27 +25,37 @@ jobs: GH_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.number }} run: | - echo "Event is: " - cat <' if [[ $? -ne 0 ]]; then # Get the list of modified files in this pull request echo "Modified files: " gh pr view $PR_NUMBER --json files - # Get modified files, but exclude those that are workflow - # files or are related to Hypercore table access - # method. These require only a single reviewer. - files=$(gh pr view $PR_NUMBER --json files --jq '.files.[].path | select(startswith(".github") or test("hypercore|columnar_scan") | not)') + # Get the number of modified files, but exclude those that + # are workflow files or are related to Hypercore table + # access method. These require only a single reviewer. + files=$(gh pr view $PR_NUMBER --json files --jq '[.files.[].path | select(startswith(".github") or test("hypercore|columnar_scan") | not)] | length') # Get the number of approvals in this pull request echo "Reviews: " gh pr view $PR_NUMBER --json reviews - approvals=$(gh pr view $PR_NUMBER --json reviews --jq '[.reviews.[] | select((.authorAssociation == "MEMBER" or .authorAssociation == "CONTRIBUTOR") and .state == "APPROVED")] | length') - - if [[ $approvals -lt 2 ]] && [[ "${files}" ]] ; then + approvals=$( + gh pr view $PR_NUMBER --json reviews --jq ' + [ + .reviews.[] + | select( + ( + .authorAssociation == "NONE" + or .authorAssociation == "MEMBER" + or .authorAssociation == "CONTRIBUTOR" + ) + and .state == "APPROVED" + ) + ] | length + ' + ) + echo "approvals: $approvals, files: $files" + if [[ $approvals -lt 2 ]] && [[ $files -gt 0 ]] ; then echo "This pull request requires 2 approvals before merging." echo echo "For trivial changes, you may disable this check by adding this trailer to the pull request message:"