From d39574442e2202448528840996789c3c9858f605 Mon Sep 17 00:00:00 2001 From: denglihong2007 <98096191+denglihong2007@users.noreply.github.com> Date: Thu, 1 May 2025 10:28:59 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20#132=20=E6=B7=BB=E5=8A=A0=20changelog=20?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=B7=A5=E5=85=B7=E5=92=8C=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 11 ++++--- cliff.toml | 62 +++++++++++++++++++++++++++++++++++ tool/generate-changelog.ps1 | 5 +++ 3 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 cliff.toml create mode 100644 tool/generate-changelog.ps1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f0de305..e828dc5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -68,10 +68,8 @@ jobs: with: dotnet-version: '9.0.x' - - name: Set Encoding - run: | - echo "DOTNET_CLI_UI_LANGUAGE=zh-CN" >> $GITHUB_ENV - chcp 65001 + - name: Set up git-cliff + uses: kenji-miyake/setup-git-cliff@v1 - name: Add GitHub Package Source env: @@ -85,7 +83,9 @@ jobs: dotnet build --configuration Release --no-restore - name: Publish - run: dotnet publish -c Release -o out + run: | + ./tool/generate-changelog.ps1 + dotnet publish -c Release -o out - name: Create Zip Package shell: pwsh @@ -97,5 +97,6 @@ jobs: uses: softprops/action-gh-release@v2 with: tag_name: v${{ needs.check-version.outputs.new_version }} + body_path: ./CHANGELOG.md name: ${{ needs.check-version.outputs.new_version }} files: CRSim-release-${{ needs.check-version.outputs.new_version }}.zip \ No newline at end of file diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 0000000..765e9d8 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,62 @@ +[changelog] +header = "更新日志" +body = """ +{%- macro remote_url() -%} + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }} +{%- endmacro -%} + +{% macro print_commit(commit) -%} + - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ + {% if commit.breaking %}[**破坏性更改**] {% endif %}\ + {{ commit.message | upper_first }}\ +{% endmacro -%} + +{% for group, commits in commits | group_by(attribute="group") %} + ## {{ group | striptags | trim | upper_first }} + {% for commit in commits + | filter(attribute="scope") + | sort(attribute="scope") %} + {{ self::print_commit(commit=commit) }} + {%- endfor %} + {% for commit in commits %} + {%- if not commit.scope -%} + {{ self::print_commit(commit=commit) }} + {% endif -%} + {% endfor -%} +{% endfor -%} +{%- if github -%} +{% if github.contributors | length != 0 %} +## 🙌 贡献者 + +感谢以下贡献者的贡献: +{% endif %}\ +{% for contributor in github.contributors %} + * @{{ contributor.username }} +{%- endfor -%} +{%- endif %} + + +""" +trim = true +footer = "" +postprocessors = [{ pattern = "#([0-9]+)", replace = "([#${1}](https://github.com/denglihong2007/CRSim/issues/${1}))"}] + +[git] +commit_parsers = [ + { message = "^feat", group = "🚀 新功能" }, + { message = "^fix", group = "🐛 Bug 修复" }, + { message = "^doc", group = "📚 文档" }, + { message = "^perf", group = "⚡ 性能" }, + { message = "^refactor", group = "🚜 重构" }, + { message = "^style", group = "🎨 界面" }, + { message = "^test", group = "🧪 测试" }, + { message = "^chore\\(release\\): prepare for", skip = true }, + { message = "^chore\\(deps.*\\)", skip = true }, + { message = "^chore\\(pr\\)", skip = true }, + { message = "^chore\\(pull\\)", skip = true }, + { message = "^chore|^ci", group = "⚙️ 杂项" }, + { message = "^revert", group = "◀️ 回退" }, + { message = ".*", group = "💼 其它" }, +] +[commit_parsers] +exclude = ["\\[skip cliff\\]"] diff --git a/tool/generate-changelog.ps1 b/tool/generate-changelog.ps1 new file mode 100644 index 0000000..a1e75ce --- /dev/null +++ b/tool/generate-changelog.ps1 @@ -0,0 +1,5 @@ +# 获取最新的 Git tag +$latestTag = git describe --tags --abbrev=0 + +# 生成 changelog 并存储为最新 tag 名称的 Markdown 文件 +git cliff -t ${latestTag} --output "..\CHANGELOG.md"