From 65b2df889729ef9b6ea95370c6e8c17050a07fad Mon Sep 17 00:00:00 2001 From: IsraelleHub <145595240+IsraelleHub@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:57:01 -0500 Subject: [PATCH 1/3] Update workflow name --- .github/workflows/qa_required_approvals.yml | 70 +++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/qa_required_approvals.yml diff --git a/.github/workflows/qa_required_approvals.yml b/.github/workflows/qa_required_approvals.yml new file mode 100644 index 00000000000..d9636aeaa2b --- /dev/null +++ b/.github/workflows/qa_required_approvals.yml @@ -0,0 +1,70 @@ + +# +# Checks if QA approvals are necessary, and if so runs the associated action when a new review is added +# + +name: '[Utils] QA required approval' + +on: + pull_request: + types: [opened, edited, converted_to_draft, ready_for_review, reopened] + paths: + - 'VAMobile/src' + - 'VAMobile/e2e' + - 'VAMobile/package.json' + - 'VAMobile/.detoxrc.json' + - '!VAMobile/src/*.test.tsx' + pull_request_review: + types: [submitted, dismissed] + +jobs: + check_for_qa_approval: + name: Requires QA approval + runs-on: ubuntu-latest + steps: + - name: Check QA approval + shell: bash + run: | + if [[ "${{ github.event.pull_request.user.login }}" == "dependabot[bot]" ]] + then + echo "PR opened by Dependabot. Skipping QA approval check." + exit 0 + fi + approvals=$(curl --request GET \ + --url https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews?per_page=100 \ + --header 'Authorization: ${{ secrets.GITHUB_TOKEN }}' \ + --header 'Content-Type: application/json' | + jq -c '[map(select(.state == "APPROVED")) | .[] .user.login]') + + echo "${{secrets.GH_ACTIONS_PAT}}" >> token.txt + gh auth login --with-token < token.txt + required_approval_count=$(gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/department-of-veterans-affairs/va-mobile-app/branches/develop/protection | + jq -c '.required_pull_request_reviews.required_approving_review_count') + + echo "Approvers: $approvals" + echo "required approval count: $required_approval_count" + + if [[ $(jq '. | length' <<< "$approvals") -ge $required_approval_count ]] + then + if [[ $(jq '[.[] | select(. | IN("timwright12", "alexandec", "theodur", "dumathane", "cadibemma", "Sparowhawk"))] | length' <<< "$approvals") -gt 0 ]] + then + echo 'This PR has at least one engineer approval. Now checking for QA approval...' + if [[ $(jq '[.[] | select(. | IN("timwright12", "rbontrager", "DJUltraTom", "TKDickson"))] | length' <<< "$approvals") -gt 0 ]] + then + echo 'This PR has QA and engineer approval to merge' + exit 0 + else + echo 'This PR requires QA approval to merge' + exit 1 + fi + else + echo 'This PR requires Engineer approval before QA review' + exit 1 + fi + else + echo 'This PR requires two approvals, including one QA approval, before merging.' + exit 1 + fi \ No newline at end of file From 5a0b61c8f3572b1431803ee4871d3555ffe0851d Mon Sep 17 00:00:00 2001 From: IsraelleHub <145595240+IsraelleHub@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:05:52 -0500 Subject: [PATCH 2/3] add github exclusion --- .github/workflows/qa_required_approvals.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/qa_required_approvals.yml b/.github/workflows/qa_required_approvals.yml index d9636aeaa2b..5a31ef68be8 100644 --- a/.github/workflows/qa_required_approvals.yml +++ b/.github/workflows/qa_required_approvals.yml @@ -14,6 +14,7 @@ on: - 'VAMobile/package.json' - 'VAMobile/.detoxrc.json' - '!VAMobile/src/*.test.tsx' + - '!.github/**' pull_request_review: types: [submitted, dismissed] From 5f1c5302ab714a9b10f73c99ea9f0a8e318c5b76 Mon Sep 17 00:00:00 2001 From: IsraelleHub <145595240+IsraelleHub@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:06:41 -0500 Subject: [PATCH 3/3] rename --- .../workflows/pr-checks-for-qa-approvals.yml | 70 ------------------- 1 file changed, 70 deletions(-) delete mode 100644 .github/workflows/pr-checks-for-qa-approvals.yml diff --git a/.github/workflows/pr-checks-for-qa-approvals.yml b/.github/workflows/pr-checks-for-qa-approvals.yml deleted file mode 100644 index d9636aeaa2b..00000000000 --- a/.github/workflows/pr-checks-for-qa-approvals.yml +++ /dev/null @@ -1,70 +0,0 @@ - -# -# Checks if QA approvals are necessary, and if so runs the associated action when a new review is added -# - -name: '[Utils] QA required approval' - -on: - pull_request: - types: [opened, edited, converted_to_draft, ready_for_review, reopened] - paths: - - 'VAMobile/src' - - 'VAMobile/e2e' - - 'VAMobile/package.json' - - 'VAMobile/.detoxrc.json' - - '!VAMobile/src/*.test.tsx' - pull_request_review: - types: [submitted, dismissed] - -jobs: - check_for_qa_approval: - name: Requires QA approval - runs-on: ubuntu-latest - steps: - - name: Check QA approval - shell: bash - run: | - if [[ "${{ github.event.pull_request.user.login }}" == "dependabot[bot]" ]] - then - echo "PR opened by Dependabot. Skipping QA approval check." - exit 0 - fi - approvals=$(curl --request GET \ - --url https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews?per_page=100 \ - --header 'Authorization: ${{ secrets.GITHUB_TOKEN }}' \ - --header 'Content-Type: application/json' | - jq -c '[map(select(.state == "APPROVED")) | .[] .user.login]') - - echo "${{secrets.GH_ACTIONS_PAT}}" >> token.txt - gh auth login --with-token < token.txt - required_approval_count=$(gh api \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - /repos/department-of-veterans-affairs/va-mobile-app/branches/develop/protection | - jq -c '.required_pull_request_reviews.required_approving_review_count') - - echo "Approvers: $approvals" - echo "required approval count: $required_approval_count" - - if [[ $(jq '. | length' <<< "$approvals") -ge $required_approval_count ]] - then - if [[ $(jq '[.[] | select(. | IN("timwright12", "alexandec", "theodur", "dumathane", "cadibemma", "Sparowhawk"))] | length' <<< "$approvals") -gt 0 ]] - then - echo 'This PR has at least one engineer approval. Now checking for QA approval...' - if [[ $(jq '[.[] | select(. | IN("timwright12", "rbontrager", "DJUltraTom", "TKDickson"))] | length' <<< "$approvals") -gt 0 ]] - then - echo 'This PR has QA and engineer approval to merge' - exit 0 - else - echo 'This PR requires QA approval to merge' - exit 1 - fi - else - echo 'This PR requires Engineer approval before QA review' - exit 1 - fi - else - echo 'This PR requires two approvals, including one QA approval, before merging.' - exit 1 - fi \ No newline at end of file