Skip to content

Commit 122c35d

Browse files
ci(hotfix-pr-check): conditionally enforce requirement of main branch PR being merged (#7351)
1 parent 6b52449 commit 122c35d

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

.github/workflows/hotfix-pr-check.yml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
env:
1717
HOTFIX_PR_AUTHOR: ${{ github.event.pull_request.user.login }}
1818
HOTFIX_PR_TITLE: ${{ github.event.pull_request.title }}
19+
HOTFIX_PR_NEEDS_MAIN_BRANCH_PR_MERGED: ${{ vars.HOTFIX_PR_NEEDS_MAIN_BRANCH_PR_MERGED }}
1920
steps:
2021
- name: Checkout repository
2122
uses: actions/checkout@v4
@@ -33,8 +34,8 @@ jobs:
3334
# Extract a list of lines with the format 'juspay/hyperswitch/pull/1200' or '#1200' using 'sed'.
3435
# If empty, then error out and exit.
3536
# else, use 'grep' to extract out 'juspay/hyperswitch/pull/1200' or '#1200' patterns from each line.
36-
# Use 'sed' to remove the part of the matched strings that precedes the last "/" character (in cases like, juspay/hyperswitch/pull/1200 - 1200)
37-
# and sed again to remove any "#" characters from the extracted numeric part (in cases like #1200 - 1200), ultimately getting PR/issue number.
37+
# Use 'sed' to remove the part of the matched strings that precedes the last "/" character (in cases like, juspay/hyperswitch/pull/1200 - 1200)
38+
# and sed again to remove any "#" characters from the extracted numeric part (in cases like #1200 - 1200), ultimately getting PR/issue number.
3839
# Finally, remove (if any) duplicates from the list
3940
4041
SED_OUTPUT=$(sed -E '/\/juspay\/hyperswitch\/pull\/[0-9]+|#[0-9]+/!d' hotfix_pr_body.txt)
@@ -73,10 +74,11 @@ jobs:
7374
pr_base_ref=$(echo "${pr_info}" | jq -r '.baseRefName')
7475
pr_state=$(echo "${pr_info}" | jq -r '.state')
7576
76-
if [[ "${pr_author}" == "${HOTFIX_PR_AUTHOR}" && \
77-
"${pr_title}" == "${HOTFIX_PR_TITLE}" && \
78-
"${pr_base_ref}" == "main" && \
79-
"${pr_state}" == "MERGED" ]]; then
77+
if [[ "${pr_author}" == "${HOTFIX_PR_AUTHOR}" &&
78+
"${pr_title}" == "${HOTFIX_PR_TITLE}" &&
79+
"${pr_base_ref}" == "main" &&
80+
(("${HOTFIX_PR_NEEDS_MAIN_BRANCH_PR_MERGED}" == 'true' && "${pr_state}" == "MERGED") ||
81+
("${HOTFIX_PR_NEEDS_MAIN_BRANCH_PR_MERGED}" != 'true')) ]]; then
8082
8183
all_checks_failed=0
8284
break
@@ -86,7 +88,6 @@ jobs:
8688
PR_TITLES+=("$pr_title")
8789
PR_BASE_REFS+=("$pr_base_ref")
8890
PR_STATES+=("$pr_state")
89-
9091
fi
9192
done
9293
@@ -140,19 +141,21 @@ jobs:
140141
fi
141142
142143
143-
# Set a flag to track if any of the original PR's state is 'MERGED'
144-
original_pr_merged=0
144+
if [[ "${HOTFIX_PR_NEEDS_MAIN_BRANCH_PR_MERGED}" == 'true' ]]; then
145+
# Set a flag to track if any of the original PR's state is 'MERGED'
146+
original_pr_merged=0
145147
146-
for ((i = 0; i < ${#PR_STATES[@]}; i++)); do
147-
if [[ "${PR_STATES[i]}" == "MERGED" ]]; then
148-
# If a match is found, set the flag to 1 and break out of the loop
149-
original_pr_merged=1
150-
break
151-
fi
152-
done
148+
for ((i = 0; i < ${#PR_STATES[@]}; i++)); do
149+
if [[ "${PR_STATES[i]}" == "MERGED" ]]; then
150+
# If a match is found, set the flag to 1 and break out of the loop
151+
original_pr_merged=1
152+
break
153+
fi
154+
done
153155
154-
if [[ $original_pr_merged -eq 0 ]]; then
155-
echo "::error::None of the Original PR is merged"
156+
if [[ $original_pr_merged -eq 0 ]]; then
157+
echo "::error::None of the Original PR is merged"
158+
fi
156159
fi
157160
158161
# Print all Original PR's (number), (pr_title), (pr_author), (pr_base_ref) and (pr_state)

0 commit comments

Comments
 (0)