@@ -127,8 +127,12 @@ jobs:
127
127
headRepository,\
128
128
headRefName,\
129
129
baseRefName"
130
+ NEW_PR_REF : " regen-lockfiles-${{ github.run_id }}"
130
131
run : |
131
- if [[ "${{ inputs.pr }}" == new ]]; then
132
+ NEW_PR_NUMBER="$(gh pr list --json number --head "${NEW_PR_REF}" --state open)"
133
+ pr_list_rc = $?
134
+ if [[ "${{ inputs.pr }}" == new ]] && [ ${pr_list_rc} -gt 0 ]; then
135
+ CHECKOUT_REF="${GITHUB_REF}"
132
136
echo "Planning new Pull Request metadata ..."
133
137
PR=$(
134
138
yq -e -p yaml . -o json -I 0 \
@@ -149,24 +153,38 @@ jobs:
149
153
headRepository:
150
154
id: "${GITHUB_REPOSITORY_ID}"
151
155
name: "${GITHUB_REPOSITORY#*/}"
152
- headRefName: "regen-lockfiles-${GITHUB_RUN_ID }"
156
+ headRefName: "${NEW_PR_REF }"
153
157
baseRefName: "${GITHUB_REF_NAME}"
154
158
HEREYAML
155
159
)
156
- CHECKOUT_REF="${GITHUB_REF}"
160
+ elif [[ "${{ inputs.pr }}" == new ]] && [ ${pr_list_rc} -eq 0 ]; then
161
+ CHECKOUT_REF="${GITHUB_REF}" # will be force pushed
162
+ echo "Planning new Pull Request metadata (PR #${NEW_PR_NUMBER} - workflow re-run ${GITHUB_RUN_ATTEMPT})..."
163
+ PR=$(gh pr view "${NEW_PR_NUMBER}" --json "${PR_FIELDS}")
164
+ pr_search_rc=$?
165
+ if [ ${pr_search_rc} -gt 0 ]; then
166
+ echo "Error looking up PR from prior workflow run."
167
+ echo "JSON=${PR}"
168
+ exit 2
169
+ fi
170
+ echo "Found Pull Request #${NEW_PR_NUMBER} by @$(jq -r .author.login <<< "${PR}")"
171
+ echo "URL: $(jq -r .url <<< "${PR}")"
157
172
else
158
173
CHECKOUT_REF="refs/pull/${{ inputs.pr }}/merge"
159
174
echo "Searching for Pull Request #${{ inputs.pr }} ..."
160
175
PR=$(gh pr view "${{ inputs.pr }}" --json "${PR_FIELDS}")
161
176
pr_search_rc=$?
162
177
if [ ${pr_search_rc} -gt 0 ]; then
163
178
echo "Pull Request #${{ inputs.pr }} not found!"
179
+ echo "JSON=${PR}"
164
180
exit 2
165
181
elif (jq -e .closed <<< "${PR}" >/dev/null); then
166
182
echo "Pull Request #${{ inputs.pr }} is closed!"
183
+ echo "JSON=${PR}"
167
184
exit 3
168
185
elif ! (jq -e .maintainerCanModify <<< "${PR}" >/dev/null); then
169
186
echo "Pull Request #${{ inputs.pr }} does not allow maintainer modification!"
187
+ echo "JSON=${PR}"
170
188
exit 4
171
189
fi
172
190
echo "Found Pull Request #${{ inputs.pr }} by @$(jq -r .author.login <<< "${PR}")"
@@ -416,13 +434,16 @@ jobs:
416
434
submodules : ' true'
417
435
ref : ${{ needs.pr.outputs.CHECKOUT_REF }}
418
436
419
- - name : Create branch for new PR
420
- if : inputs.pr == 'new'
437
+ - name : Configure git author, committer
421
438
run : |
422
439
git config --local author.name "${{ env.BOT_ST2_NAME }}"
423
440
git config --local author.email "${{ env.BOT_ST2_EMAIL }}"
424
441
git config --local committer.name "${{ env.BOT_GHA_NAME }}"
425
442
git config --local committer.email "${{ env.BOT_GHA_EMAIL }}"
443
+
444
+ - name : Create branch for new PR
445
+ if : inputs.pr == 'new'
446
+ run : |
426
447
git checkout -b "${{ needs.pr.outputs.PR_REF }}" FETCH_HEAD
427
448
428
449
- name : Download lockfiles and lockfile diff files
@@ -500,7 +521,7 @@ jobs:
500
521
pants run scripts/lockfiles_to_reqs.py
501
522
git add *requirements.txt st2*/requirements.txt contrib/runners/*/requirements.txt
502
523
503
- - name : Commit and push
524
+ - name : Commit and ${{ inputs.pr == 'new' && 'force-' || '' }} push
504
525
if : env.CHANGED == 'true'
505
526
# git push --force is for workflow re-runs, but only for new PRs.
506
527
run : |
@@ -509,7 +530,7 @@ jobs:
509
530
-u origin "${{ needs.pr.outputs.PR_REF }}"
510
531
511
532
- name : Create new PR
512
- if : inputs.pr == 'new' && env.CHANGED == 'true'
533
+ if : inputs.pr == 'new' && fromJSON(needs.pr.outputs.JSON).number == 'new' && env.CHANGED == 'true'
513
534
env :
514
535
GH_TOKEN : ${{ github.token }}
515
536
run : >
@@ -527,6 +548,17 @@ jobs:
527
548
# so, setting reviewer to a team would mean managing a PAT or similar.
528
549
# --reviewer "${{ github.repository_owner }}/Maintainers"
529
550
551
+ - name : Update new PR (workflow re-run ${{ github.run_attempt }})
552
+ if : inputs.pr == 'new' && fromJSON(needs.pr.outputs.JSON).number != 'new' && env.CHANGED == 'true'
553
+ env :
554
+ GH_TOKEN : ${{ github.token }}
555
+ run : >
556
+ (
557
+ echo '## New PR Update'; echo;
558
+ gh pr edit "${{ fromJSON(needs.pr.outputs.JSON).number }}"
559
+ --body-file "${PR_COMMENT}"
560
+ ) | tee -a "${GITHUB_STEP_SUMMARY}"
561
+
530
562
- name : Update or Add Comment on existing PR
531
563
if : inputs.pr != 'new'
532
564
env :
0 commit comments