Skip to content

Commit 26ae381

Browse files
fix(ci): improve changelog with PR hyperlinks and proper contributors (#568)
- Add PR hyperlinks to all changelog entries (CHANGE.md, README, release) - Use GitHub API to get actual PR authors instead of git author names - Filter out bot accounts from contributors list - Fix bot email to use user ID (257041894) instead of App ID for proper avatar Signed-off-by: JasonXuDeveloper - 傑 <jason@xgamedev.net>
1 parent 1c168c0 commit 26ae381

File tree

1 file changed

+53
-21
lines changed

1 file changed

+53
-21
lines changed

.github/workflows/release.yml

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -162,30 +162,50 @@ jobs:
162162
# Generate changelog from conventional commits
163163
- name: Generate changelog
164164
id: generate-changelog
165+
env:
166+
GH_TOKEN: ${{ github.token }}
167+
REPO: ${{ github.repository }}
165168
run: |
166169
BASE_TAG="${{ steps.base-tag.outputs.base_tag }}"
167170
168171
# Get commits since last tag
169172
if git rev-parse "$BASE_TAG" >/dev/null 2>&1; then
170-
COMMITS=$(git log $BASE_TAG..HEAD --pretty=format:"%H|%s|%an" --no-merges)
173+
COMMITS=$(git log $BASE_TAG..HEAD --pretty=format:"%H|%s" --no-merges)
171174
else
172175
echo "Warning: Tag $BASE_TAG not found, using all commits"
173-
COMMITS=$(git log --pretty=format:"%H|%s|%an" --no-merges)
176+
COMMITS=$(git log --pretty=format:"%H|%s" --no-merges)
174177
fi
175178
176179
# Parse conventional commits
177180
FEATURES=""
178181
FIXES=""
179182
BREAKING=""
180183
OTHER=""
181-
CONTRIBUTORS=""
184+
declare -A CONTRIBUTORS_MAP
182185
183186
# Store regex in variable to avoid bash parsing issues with special characters
184187
COMMIT_PATTERN='^([a-z]+)(\(([^)]+)\))?!?:[[:space:]](.+)$'
188+
# Pattern to extract PR number from commit message like "message (#123)"
189+
PR_PATTERN='\(#([0-9]+)\)$'
185190
186-
while IFS='|' read -r hash subject author; do
191+
while IFS='|' read -r hash subject; do
187192
[ -z "$hash" ] && continue
188193
194+
# Extract PR number if present and convert to hyperlink
195+
pr_link=""
196+
if [[ $subject =~ $PR_PATTERN ]]; then
197+
pr_num="${BASH_REMATCH[1]}"
198+
pr_link="[#${pr_num}](https://github.com/${REPO}/pull/${pr_num})"
199+
# Replace (#123) with the hyperlink
200+
subject=$(echo "$subject" | sed "s/(#${pr_num})/(${pr_link})/")
201+
202+
# Get contributor from PR using GitHub API
203+
pr_author=$(gh api "repos/${REPO}/pulls/${pr_num}" --jq '.user.login' 2>/dev/null || echo "")
204+
if [ -n "$pr_author" ] && [ "$pr_author" != "null" ]; then
205+
CONTRIBUTORS_MAP["$pr_author"]=1
206+
fi
207+
fi
208+
189209
# Extract commit type and scope
190210
if [[ $subject =~ $COMMIT_PATTERN ]]; then
191211
type="${BASH_REMATCH[1]}"
@@ -226,14 +246,17 @@ jobs:
226246
OTHER="${OTHER}- $clean_subject\n"
227247
fi
228248
fi
229-
230-
# Collect unique contributors
231-
if ! echo "$CONTRIBUTORS" | grep -q "@$author"; then
232-
CONTRIBUTORS="${CONTRIBUTORS}@$author, "
233-
fi
234249
done <<< "$COMMITS"
235250
236-
# Remove trailing comma from contributors
251+
# Build contributors list from the associative array (excludes bots)
252+
CONTRIBUTORS=""
253+
for contributor in "${!CONTRIBUTORS_MAP[@]}"; do
254+
# Skip bot accounts
255+
if [[ "$contributor" != *"[bot]"* ]] && [[ "$contributor" != *"-bot"* ]]; then
256+
CONTRIBUTORS="${CONTRIBUTORS}[@${contributor}](https://github.com/${contributor}), "
257+
fi
258+
done
259+
# Remove trailing comma
237260
CONTRIBUTORS=$(echo "$CONTRIBUTORS" | sed 's/, $//')
238261
239262
# Build changelog
@@ -399,6 +422,8 @@ jobs:
399422
400423
# Update CHANGE.md
401424
- name: Update CHANGE.md
425+
env:
426+
REPO: ${{ github.repository }}
402427
run: |
403428
DATE=$(date +"%B %d %Y")
404429
@@ -415,14 +440,18 @@ jobs:
415440
CHANGE_ENTRY="## $VERSION ($DATE) - Util v${{ needs.validate.outputs.util_version }}\n\n"
416441
fi
417442
418-
# Extract features and fixes from changelog
443+
# Extract features and fixes from changelog (already contains PR hyperlinks)
419444
if echo "$CHANGELOG" | grep -q "### ✨ Features"; then
420-
FEATURES=$(echo "$CHANGELOG" | sed -n '/### ✨ Features/,/###/p' | grep "^- " | sed 's/^- /- /' || true)
445+
FEATURES=$(echo "$CHANGELOG" | sed -n '/### ✨ Features/,/###/p' | grep "^- " || true)
421446
if [ -n "$FEATURES" ]; then
422447
while IFS= read -r line; do
423-
# Convert **scope**: format to prefix format
448+
# Convert **scope**: format to prefix format, preserve hyperlinks
424449
if [[ $line =~ ^\-\ \*\*([^*]+)\*\*:\ (.+)$ ]]; then
425-
CHANGE_ENTRY="${CHANGE_ENTRY}- **$(echo ${BASH_REMATCH[2]} | sed 's/^./\u&/')** (${BASH_REMATCH[1]})\n"
450+
scope="${BASH_REMATCH[1]}"
451+
desc="${BASH_REMATCH[2]}"
452+
# Capitalize first letter of description
453+
desc_cap="$(echo "${desc:0:1}" | tr '[:lower:]' '[:upper:]')${desc:1}"
454+
CHANGE_ENTRY="${CHANGE_ENTRY}- **${desc_cap}** (${scope})\n"
426455
else
427456
CHANGE_ENTRY="${CHANGE_ENTRY}${line}\n"
428457
fi
@@ -431,21 +460,24 @@ jobs:
431460
fi
432461
433462
if echo "$CHANGELOG" | grep -q "### 🐛 Bug Fixes"; then
434-
FIXES=$(echo "$CHANGELOG" | sed -n '/### 🐛 Bug Fixes/,/###/p' | grep "^- " | sed 's/^- /- /' || true)
463+
FIXES=$(echo "$CHANGELOG" | sed -n '/### 🐛 Bug Fixes/,/###/p' | grep "^- " || true)
435464
if [ -n "$FIXES" ]; then
436465
while IFS= read -r line; do
437466
if [[ $line =~ ^\-\ \*\*([^*]+)\*\*:\ (.+)$ ]]; then
438-
CHANGE_ENTRY="${CHANGE_ENTRY}- **$(echo ${BASH_REMATCH[2]} | sed 's/^./\u&/')** (${BASH_REMATCH[1]})\n"
467+
scope="${BASH_REMATCH[1]}"
468+
desc="${BASH_REMATCH[2]}"
469+
desc_cap="$(echo "${desc:0:1}" | tr '[:lower:]' '[:upper:]')${desc:1}"
470+
CHANGE_ENTRY="${CHANGE_ENTRY}- **${desc_cap}** (${scope})\n"
439471
else
440472
CHANGE_ENTRY="${CHANGE_ENTRY}${line}\n"
441473
fi
442474
done <<< "$FIXES"
443475
fi
444476
fi
445477
446-
# Extract other changes (non-conventional commits)
478+
# Extract other changes (non-conventional commits) - already contains PR hyperlinks
447479
if echo "$CHANGELOG" | grep -q "### 📦 Other Changes"; then
448-
OTHERS=$(echo "$CHANGELOG" | sed -n '/### 📦 Other Changes/,/###/p' | grep "^- " | sed 's/^- /- /' || true)
480+
OTHERS=$(echo "$CHANGELOG" | sed -n '/### 📦 Other Changes/,/###/p' | grep "^- " || true)
449481
if [ -n "$OTHERS" ]; then
450482
while IFS= read -r line; do
451483
CHANGE_ENTRY="${CHANGE_ENTRY}${line}\n"
@@ -466,12 +498,12 @@ jobs:
466498
467499
# Commit and push changes
468500
- name: Commit and push changes
469-
env:
470-
APP_ID: ${{ secrets.RELEASE_APP_ID }}
471501
run: |
472502
# Use GitHub's bot email format so the app avatar shows on commits
503+
# The user ID (257041894) is from: gh api '/users/jengine-release-bot[bot]' --jq '.id'
504+
# This is different from the App ID - it's the bot account's user ID
473505
git config user.name "jengine-release-bot[bot]"
474-
git config user.email "${APP_ID}+jengine-release-bot[bot]@users.noreply.github.com"
506+
git config user.email "257041894+jengine-release-bot[bot]@users.noreply.github.com"
475507
476508
git add UnityProject/Packages/*/package.json README*.md CHANGE.md
477509

0 commit comments

Comments
 (0)