Skip to content

Commit c1324a6

Browse files
committed
chore: 修复 releaselog @用户名不正确的问题
1 parent 5ff740f commit c1324a6

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,60 @@ jobs:
164164
run: pnpm run release -- --assets "release_files/*"
165165
env:
166166
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
167+
168+
- name: Fix author mentions in release
169+
env:
170+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
171+
run: |
172+
TAG="${GITHUB_REF_NAME}"
173+
REPO="${GITHUB_REPOSITORY}"
174+
175+
# 获取上一个 tag
176+
PREV_TAG=$(git tag --sort=-creatordate | grep -v "^${TAG}$" | head -1)
177+
if [ -z "$PREV_TAG" ]; then
178+
echo "No previous tag found, skipping"
179+
exit 0
180+
fi
181+
182+
echo "Comparing $PREV_TAG...$TAG"
183+
184+
# 通过 GitHub API 获取两个 tag 之间的提交,提取 author name -> login 映射
185+
COMPARE_DATA=$(gh api "repos/${REPO}/compare/${PREV_TAG}...${TAG}" --jq '.commits[] | select(.author != null) | "\(.commit.author.name)=\(.author.login)"' 2>/dev/null || true)
186+
187+
if [ -z "$COMPARE_DATA" ]; then
188+
echo "No commit data or no linked GitHub accounts, skipping"
189+
exit 0
190+
fi
191+
192+
# 获取当前 release body
193+
RELEASE_BODY=$(gh release view "$TAG" --json body --jq '.body' 2>/dev/null || true)
194+
if [ -z "$RELEASE_BODY" ]; then
195+
echo "Release body is empty, skipping"
196+
exit 0
197+
fi
198+
199+
# 用 node 替换 @AuthorName 为 @github-login
200+
UPDATED_BODY=$(node -e "
201+
const mappings = process.env.COMPARE_DATA.split('\n').filter(Boolean);
202+
const nameToLogin = {};
203+
for (const m of mappings) {
204+
const [name, login] = m.split('=');
205+
if (name && login) nameToLogin[name] = login;
206+
}
207+
let body = process.env.RELEASE_BODY;
208+
for (const [name, login] of Object.entries(nameToLogin)) {
209+
// 替换 **@Name** 或 @Name 格式
210+
body = body.replace(new RegExp('@' + name.replace(/[.*+?^\${}()|[\\]\\\\]/g, '\\\\\\$&'), 'g'), '@' + login);
211+
}
212+
process.stdout.write(body);
213+
")
214+
215+
if [ "$UPDATED_BODY" != "$RELEASE_BODY" ]; then
216+
echo "Updating release with corrected author mentions"
217+
gh release edit "$TAG" --notes "$UPDATED_BODY"
218+
else
219+
echo "No author mentions to fix"
220+
fi
167221
# - name: Create Release
168222
# uses: softprops/action-gh-release@v1
169223
# with:

0 commit comments

Comments
 (0)