-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add workflow for FE conditional review (#1650)
- Loading branch information
1 parent
935b2d6
commit 466fbef
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: "FE Conditional Review" | ||
|
||
on: | ||
pull_request: | ||
types: | ||
[opened, edited, synchronize, review_requested, review_request_removed] | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} | ||
PR_NUMBER: ${{ github.event.pull_request.number }} | ||
PR_TITLE: ${{ github.event.pull_request.title }} | ||
PATTERN: "^\\w+!:" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
add-fe-review-request: | ||
name: Add FE Review Request | ||
permissions: write-all | ||
runs-on: ubuntu-latest | ||
outputs: | ||
HAS_FE_REVIEW_REQUEST: ${{ steps.reviewers.outputs.HAS_FE_REVIEW_REQUEST }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Add FE Review Request | ||
id: reviewers | ||
run: | | ||
FE_MEMBERS=$(gh api orgs/FuelLabs/teams/frontend/members --jq '.[].login') | ||
PR_DATA=$(gh pr view https://github.com/FuelLabs/fuels-ts/pull/$PR_NUMBER --json reviewRequests,reviews) | ||
HAS_FE_REVIEW_REQUEST=$(echo "$PR_DATA" | jq '[.reviewRequests[].slug | select(. == "FuelLabs/frontend")] | length > 0') | ||
REVIWERS=$(echo "$PR_DATA" | jq -r '.reviews[].author.login') | ||
WAS_REVIEWED_BY_FE="false" | ||
for member in $FE_MEMBERS; do | ||
for reviewer in $REVIWERS; do | ||
if [ "$member" == "$reviewer" ]; then | ||
WAS_REVIEWED_BY_FE="true" | ||
break 2 | ||
fi | ||
done | ||
done | ||
SHOULD_ADD_FE_REVIEW_REQUEST="false" | ||
if [[ $PR_TITLE =~ $PATTERN ]]; then | ||
if [ "$HAS_FE_REVIEW_REQUEST" != "true" ]; then | ||
if [ "$WAS_REVIEWED_BY_FE" != "true" ]; then | ||
SHOULD_ADD_FE_REVIEW_REQUEST="true" | ||
fi | ||
fi | ||
fi | ||
if($SHOULD_ADD_FE_REVIEW_REQUEST == "true"); then | ||
gh pr edit "$PR_NUMBER" --add-reviewer FuelLabs/frontend | ||
fi | ||
echo "HAS_FE_REVIEW_REQUEST=$HAS_FE_REVIEW_REQUEST" >> $GITHUB_OUTPUT | ||
confirm-fe-review-status: | ||
permissions: write-all | ||
name: Confirm FE Review Status | ||
needs: [add-fe-review-request] | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Ensure FE Has Reviewed PR | ||
env: | ||
HAS_FE_REVIEW_REQUEST: ${{needs.add-fe-review-request.outputs.HAS_FE_REVIEW_REQUEST}} | ||
|
||
run: | | ||
if [ "$HAS_FE_REVIEW_REQUEST" == "true" ]; then | ||
exit 1 | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: "Rerun FE Conditional Review Workflow" | ||
|
||
on: | ||
pull_request_review: | ||
types: [submitted, edited, dismissed] | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
rerun-fe-conditional-review-workflow: | ||
runs-on: ubuntu-latest | ||
permissions: write-all | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Get latest workflow run ID | ||
id: get_run_id | ||
run: | | ||
LATEST_RUN_ID=$(gh run list --repo ${{ github.repository }} --branch ${{ github.event.pull_request.head.ref }} --json databaseId,name --jq '.[] | select(.name == "FE Conditional Review") | .databaseId' | head -n 1) | ||
echo "LATEST_RUN_ID=$LATEST_RUN_ID" >> $GITHUB_ENV | ||
- name: Rerun latest workflow | ||
if: env.LATEST_RUN_ID != '' | ||
run: gh run rerun ${{ env.LATEST_RUN_ID }} --repo ${{ github.repository }} |