-
Notifications
You must be signed in to change notification settings - Fork 13
63 lines (56 loc) · 1.95 KB
/
changelog.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: Update Changelog After Release
# 触发条件:每次创建 Release 后触发
on:
release:
types:
- published
jobs:
update-changelog:
name: Update Changelog
runs-on: ubuntu-latest
steps:
# 1. 检出代码
- name: Checkout repository
uses: actions/checkout@v3
# 2. 获取 Release Notes
- name: Fetch Release Notes
id: get_release_notes
uses: actions/github-script@v6
with:
script: |
const release = context.payload.release;
const tagName = release.tag_name;
const releaseNotes = release.body || "No release notes provided.";
return {
tagName,
releaseNotes,
};
# 输出 Release Notes 和 Tag 名
outputs:
tag: ${{ steps.get_release_notes.outputs.tagName }}
notes: ${{ steps.get_release_notes.outputs.releaseNotes }}
# 3. 更新 CHANGELOG.md 文件
- name: Update CHANGELOG.md
run: |
# 如果 CHANGELOG.md 文件不存在,创建一个新的
if [ ! -f CHANGELOG.md ]; then
echo "# Changelog" > CHANGELOG.md
fi
# 创建临时文件,将新内容写到最前面
{
echo "## Release ${{ steps.get_release_notes.outputs.tag }} - $(date +"%Y-%m-%d")"
echo ""
echo "${{ steps.get_release_notes.outputs.notes }}"
echo ""
cat CHANGELOG.md
} > TEMP_CHANGELOG.md
# 覆盖原文件
mv TEMP_CHANGELOG.md CHANGELOG.md
# 4. 提交变更到仓库
- name: Commit and push changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "docs: update CHANGELOG.md for release ${{ steps.get_release_notes.outputs.tag }}"
git push