Skip to content

Commit 3b58c94

Browse files
authored
fix: ensure PR list is in numerical order in the update changelog CI (#52)
ci: sort PR list in numerical order in the update-changelog PR body. - Fixed the "Create or update changelog PR" step in the changelog CI to sort the PR list in numerical order in the existing update changelog PR body. This ensures that if a the CI run fails and a concurrent run succeeds, the PR number won't be in the wrong order when re-running the failed runs. The PR numbers will always be in numerical order.
1 parent ad0b9cb commit 3b58c94

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

.github/workflows/changelog-ci.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,28 @@ jobs:
238238
239239
if [ "$CHANGELOG_PR_EXISTS" = "true" ]; then
240240
# Update existing PR
241+
241242
EXISTING_PR_NUMBER="${{ steps.check-existing-changelog-pr.outputs.changelog-pr-number }}"
242243
EXISTING_BODY="${{ steps.check-existing-changelog-pr.outputs.changelog-pr-body }}"
243-
UPDATED_BODY="$EXISTING_BODY
244-
- #$PR_NUMBER"
244+
245+
# Extract the existing PR list
246+
PR_LIST=$(printf '%s\n' "$EXISTING_BODY" |
247+
sed -n '/^### Included PRs:/,$p' |
248+
sed '1d')
249+
250+
# Add the new PR and sort numerically
251+
SORTED_PR_LIST=$(
252+
{
253+
printf '%s\n' "$PR_LIST" |
254+
sed 's/^- #//'
255+
printf '%s\n' "$PR_NUMBER"
256+
} |
257+
sort -n |
258+
sed 's/^/- #/'
259+
)
260+
261+
# Replace only the existing PR list
262+
UPDATED_BODY="${EXISTING_BODY/"$PR_LIST"/"$SORTED_PR_LIST"}"
245263
246264
gh pr edit "$EXISTING_PR_NUMBER" --body "$UPDATED_BODY"
247265
echo "✅ Updated changelog PR #$EXISTING_PR_NUMBER"

0 commit comments

Comments
 (0)