diff --git a/.github/cliff.toml b/.github/cliff.toml new file mode 100644 index 0000000..bc74513 --- /dev/null +++ b/.github/cliff.toml @@ -0,0 +1,116 @@ +[remote.github] +owner = "MAA-AI" +repo = "MaaMCP" + +[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 %}[**breaking**] {% endif %}\ + {{ commit.message | split(pat="\n") | first | upper_first }} \ + {% if commit.remote.username %} @{{ commit.remote.username }}{% else %} {{ commit.author.name }}{% endif %}\ + {%- if commit.footers -%} + {%- for footer in commit.footers -%} + {%- if footer.token == "Co-authored-by" -%} + {%- set co_author_name = footer.value | split(pat=" <") | first | trim %} @{{ co_author_name }} + {%- endif -%} + {%- endfor -%} + {%- endif -%} +{% endmacro -%} + +{% if version %} + ## {{ version | trim_start_matches(pat="v") }} ({{ timestamp | date(format="%Y-%m-%d") }}) +{% else %} + ## 未发布 +{% endif %} + +{% 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 | filter(attribute="is_first_time", value=true) | length != 0 %} + ## 新贡献者 ❤️ +{% endif %} +{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %} + * @{{ contributor.username }} made their first contribution + {%- if contributor.pr_number %} in \ + [#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \ + {%- endif %} +{%- endfor -%} +{%- endif %} +""" + +# 尾部 +footer = """ +{%- set latest_version = "" -%} +{%- for release in releases -%} + {%- if release.version and latest_version == "" -%} + {%- set_global latest_version = release.version -%} + {%- endif -%} +{%- endfor %} +{% if latest_version %} +# 安装 + +```sh +pip install maa-mcp=={{ latest_version }} +``` + +# 使用 + +```sh +maa-mcp +``` +{%- endif %} +""" + +[git] +# 过滤提交 +conventional_commits = true # 使用约定式提交格式 +filter_unconventional = false # 不过滤非约定式提交 +# 启用完整的 commit 信息 +split_commits = false +# 保留完整的 commit body +protect_breaking_commits = false +commit_parsers = [ + # 跳过包含 [skip changelog] 的 commit + { message = ".*\\[skip changelog\\].*", skip = true }, + { body = ".*\\[skip changelog\\].*", skip = true }, + { message = "^feat", group = "✨ 新功能" }, + { message = "^fix", group = "🐛 Bug修复" }, + { message = "^docs", group = "📚 文档" }, + { message = "^perf", group = "🚀 性能优化" }, + { message = "^refactor", group = "🚜 代码重构" }, + { message = "^style", group = "🎨 样式" }, + { message = "^test", group = "🧪 测试" }, + { message = "^chore", group = "🔧 日常维护" }, + { message = "^ci", group = "⚙️ 持续集成" }, + { message = "^remove", group = "🗑️ 移除" }, + { body = ".*security", group = "🔒 安全" }, + { message = "^[Rr]evert", group = "◀️ 撤销" }, +] + +# 排序规则 +sort_commits = "oldest" + +# 启用GitHub集成 +[git.github] +commits = true diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ceadc67..2b86e10 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,8 +11,70 @@ on: required: false jobs: + changelog: + name: Generate changelog + runs-on: ubuntu-latest + permissions: + contents: read # checkout 仓库 + pull-requests: read # git-cliff 拉取 PR 元数据(贡献者统计) + outputs: + release_body: ${{ steps.git-cliff.outputs.content || steps.fallback.outputs.body }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # git-cliff 需要完整历史与 tag 才能算出版本区间 + ref: ${{ inputs.tag || github.ref }} # 检出版本对应的 tag,--current 才有归属 + + - name: Determine release tag + id: meta + run: | + tag="${{ inputs.tag || github.ref_name }}" + if [[ "$tag" =~ ^v[0-9]+[.][0-9]+[.][0-9]+$ ]]; then + echo "is_prerelease=false" >> "$GITHUB_OUTPUT" + else + echo "is_prerelease=true" >> "$GITHUB_OUTPUT" + fi + + - name: Generate a changelog + uses: orhun/git-cliff-action@v4 + id: git-cliff + continue-on-error: true # 生成失败时退回静态说明,不阻塞发版 + with: + config: .github/cliff.toml + # --current 只处理「属于当前 tag 的提交」,即本次要发布的这一版; + # --strip header 去掉「更新日志」大标题 + # 正式版加 tag-pattern 把基线锁定在「上一个正式版」,这样 beta 期间的 + # 提交也会并入本次发布说明;预发布版则用上一个任意 tag 作为基线 + args: >- + -vv --current --strip header + ${{ steps.meta.outputs.is_prerelease == 'false' && '--tag-pattern "^v[0-9]+[.][0-9]+[.][0-9]+$"' || '' }} + env: + OUTPUT: CHANGES.md + GITHUB_REPO: ${{ github.repository }} + + - name: Fallback release body + id: fallback + run: | + { + echo 'body<> "$GITHUB_OUTPUT" + build: name: Build distribution + needs: changelog runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -41,18 +103,7 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} tag_name: ${{ inputs.tag || github.ref_name }} - body: "# Installation - - ```sh - pip install maa-mcp==${{ inputs.tag || github.ref_name }} - ``` - - # Usage - - ```sh - maa-mcp - ``` - " + body: ${{ needs.changelog.outputs.release_body }} publish-to-pypi: name: Publish to PyPI diff --git a/pyproject.toml b/pyproject.toml index 7ed4c45..f006afd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,10 +49,10 @@ dependencies = [ ] [project.urls] -Homepage = "https://github.com/MistEO/MaaMCP" -Documentation = "https://github.com/MistEO/MaaMCP#readme" -Repository = "https://github.com/MistEO/MaaMCP" -Issues = "https://github.com/MistEO/MaaMCP/issues" +Homepage = "https://github.com/MAA-AI/MaaMCP" +Documentation = "https://github.com/MAA-AI/MaaMCP#readme" +Repository = "https://github.com/MAA-AI/MaaMCP" +Issues = "https://github.com/MAA-AI/MaaMCP/issues" [project.scripts] maa-mcp = "maa_mcp.__main__:main"