Skip to content

Commit ac46e28

Browse files
authored
fix(ci) Increase robustness of pull-request number retrieval (#4724)
* fix(ci) Increase robustness of pull-request number retrieval * Re-order commands for better flow
1 parent ab767be commit ac46e28

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

.circleci/config.yml

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,40 @@ jobs:
186186
- run: mkdir -p workspace
187187
- install-gh-cli
188188

189+
- run:
190+
name: Get Github pull-request number
191+
command: |
192+
set +e
193+
gh pr view --json number,state,title,url > gh-pull-data.json
194+
for ((x=0 ; x<5 ; x++)) ; do
195+
if [ -z $(cat gh-pull-data.json | jq -r '.number') ] ; then
196+
gh pr view --json number,state,title,url > gh-pull-data.json
197+
else
198+
echo "» Pull-request #"$(cat gh-pull-data.json | jq -r '.number')
199+
break
200+
fi
201+
done
202+
echo
203+
echo "=== Github pull-request API results ==="
204+
cat gh-pull-data.json
205+
echo "---------------------------------------"
206+
cat gh-pull-data.json | jq -r '.number' > workspace/gh-pr-num.txt && cat workspace/gh-pr-num.txt
207+
208+
- run:
209+
name: Verify Github pull-request number
210+
command: |
211+
echo "» Branch: "${CIRCLE_BRANCH}
212+
echo
213+
if [[ ${CIRCLECI_BRANCH} =~ ^\d{3}-(summer|spring|winter)-\d{2}$ ]] ; then
214+
echo "» Does not require a pull-request number"
215+
else
216+
if [ -z $(cat workspace/gh-pr-num.txt) ] ; then
217+
echo "» No pull-request number found!"
218+
echo "» Please try running this CI workflow again."
219+
exit 1
220+
fi
221+
fi
222+
189223
- run:
190224
name: Retrieve Github deployments
191225
command: |
@@ -199,16 +233,6 @@ jobs:
199233
gh api ${STATUS_URL} -f state=in_progress -H "Accept: application/vnd.github.flash-preview+json"
200234
done
201235
202-
- run:
203-
name: Get Github pull-request number
204-
command: |
205-
set +e
206-
gh pr view --json number,state,title,url > gh-pull-data.json
207-
echo "=== Github pull-request API results ==="
208-
cat gh-pull-data.json
209-
echo "---------------------------------------"
210-
cat gh-pull-data.json | jq -r '.number' > workspace/gh-pr-num.txt && cat workspace/gh-pr-num.txt
211-
212236
- persist_to_workspace:
213237
root: workspace
214238
paths:

0 commit comments

Comments
 (0)