Skip to content

ci: 版本改由 git tag 決定(hatch-vcs)—— 發版不用再改 pyproject#2

Merged
linsamtw merged 2 commits into
masterfrom
ci/tag-driven-version
May 25, 2026
Merged

ci: 版本改由 git tag 決定(hatch-vcs)—— 發版不用再改 pyproject#2
linsamtw merged 2 commits into
masterfrom
ci/tag-driven-version

Conversation

@linsamtw
Copy link
Copy Markdown
Contributor

為什麼

承上一個發版測試:推 tag 0.0.1 時被「tag 要等於 pyproject version(0.1.0)」的守門擋下。問題不在守門,而在根本不該每次發版都手改 pyproject.toml。改成讓 git tag 當版本的唯一來源

改了什麼

  • pyproject.tomlversion 改成 hatch-vcs 動態版本([tool.hatch.version] source = "vcs"),移除寫死的 version(改 dynamic = ["version"]),build-system 加 hatch-vcs
  • src/finmind_mcp/__init__.py__version__ 改用 importlib.metadata 讀,不再寫死。
  • publish.yml:拿掉「tag vs pyproject version」守門(不需要了);checkoutfetch-depth: 0 讓 hatch-vcs 讀得到 tags。
  • ci.ymlcheckoutfetch-depth: 0

發版流程(之後)

git tag v0.1.0
git push origin v0.1.0    # 就這樣,不用碰 pyproject

hatch-vcs 會把 tag v0.1.0 變成套件版本 0.1.0;非 tag 的 commit 會 build 成 dev 版號(例 0.0.2.dev3+g…)。

已驗證(本機)

uv build 從 git 算出版本(0.0.2.dev0+g…,因為現在 HEAD 在 tag 之後)、twine check PASSED、pytest 31 過、knowledge 6 檔仍打包進 wheel、__version__ 正常解析。

注意

  • 之前那個失敗的 tag 0.0.1 沒有發出任何 PyPI 版本(卡在 build 前的守門),可留可刪。要的話我幫你刪掉遠端 0.0.1
  • 實際上傳 PyPI 仍需先做 trusted publisher + pypi environment 一次性設定(見 publish.yml 註解)。

🤖 Generated with Claude Code

linsamtw and others added 2 commits May 26, 2026 01:09
發版應該只要推 tag,不該每次手改 pyproject.toml 的 version。

- pyproject:version 改成 hatch-vcs 動態版本(source = "vcs"),移除寫死的
  version(dynamic = ["version"]);build-system 加 hatch-vcs。
- __init__.py:__version__ 改從 importlib.metadata 讀,不再寫死字串。
- publish.yml:拿掉「tag vs pyproject version」守門(不需要了,tag 本身就是
  版本);checkout 改 fetch-depth: 0 讓 hatch-vcs 讀得到 tags。
- ci.yml:checkout fetch-depth: 0(build 本套件要靠 tags 算版本)。

之後發版流程就是:
  git tag v0.1.0 && git push origin v0.1.0
hatch-vcs 會把 tag 變成套件版本;非 tag commit 則是 dev 版號。本機已驗證:
uv build + twine check 過、31 tests 過、knowledge 仍打包、__version__ 正常。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The finmind-mcp editable entry no longer pins a static version now that the
package version is derived from git tags via hatch-vcs (see this branch's
pyproject change). Regenerated lockfile drops the stale version = "0.1.0".

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@linsamtw linsamtw merged commit f0aeca0 into master May 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant