Skip to content

Commit f0aeca0

Browse files
authored
Merge pull request #2 from FinMind/ci/tag-driven-version
ci: 版本改由 git tag 決定(hatch-vcs)—— 發版不用再改 pyproject
2 parents a130535 + 45fed7d commit f0aeca0

5 files changed

Lines changed: 22 additions & 20 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
python-version: ["3.10", "3.11", "3.12"]
1818
steps:
1919
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0 # hatch-vcs 需要 tags/history 才能決定版本(build 本套件時)
2022

2123
- name: Install uv
2224
uses: astral-sh/setup-uv@v5

.github/workflows/publish.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ name: Publish to PyPI
1414
# 2. GitHub repo → Settings → Environments → 新增名為 `pypi` 的 environment
1515
# (名稱要跟上面 PyPI 設定一致;可另設保護規則,例如限定 reviewer 才能發版)
1616
#
17-
# 發版流程(tag 驅動):
18-
# - 先把 pyproject.toml 的 version bump 好(PyPI 版本號不可重複)
19-
# - git tag vX.Y.Z(要跟 version 一致,下方 job 會檢查)
20-
# - git push origin vX.Y.Z ← 推 tag 就觸發本 workflow,自動 build → 上傳 PyPI
17+
# 發版流程(tag 驅動,版本號 = tag,不用改 pyproject.toml):
18+
# - git tag v0.1.0
19+
# - git push origin v0.1.0 ← 推 tag 就觸發;hatch-vcs 從 tag 算出版本 0.1.0
20+
# 自動 build → 上傳 PyPI(PyPI 版本號不可重複,所以每次用新 tag)
2121

2222
on:
2323
push:
@@ -31,22 +31,13 @@ jobs:
3131
runs-on: ubuntu-latest
3232
steps:
3333
- uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0 # hatch-vcs 需要完整 history + tags 才能從 tag 算版本
3436

3537
- name: Install uv
3638
uses: astral-sh/setup-uv@v5
3739

38-
- name: Verify pushed tag matches pyproject version
39-
if: startsWith(github.ref, 'refs/tags/')
40-
run: |
41-
VERSION=$(grep -m1 '^version' pyproject.toml | sed -E 's/.*"(.*)".*/\1/')
42-
TAG="${GITHUB_REF_NAME#v}"
43-
echo "pyproject version: $VERSION pushed tag: $TAG"
44-
if [ "$VERSION" != "$TAG" ]; then
45-
echo "::error::pushed tag ($TAG) does not match pyproject version ($VERSION). Bump the version or fix the tag."
46-
exit 1
47-
fi
48-
49-
- name: Build sdist + wheel
40+
- name: Build sdist + wheel (version derived from the pushed tag)
5041
run: uv build
5142

5243
- name: Check distribution metadata

pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "finmind-mcp"
3-
version = "0.1.0"
3+
dynamic = ["version"] # 版本由 git tag 決定(hatch-vcs),發版只要推 tag,不用改這裡
44
description = "FinMind MCP server — Taiwan / global financial data for Claude, Gemini CLI, Cursor, Windsurf, and other MCP hosts"
55
readme = "README.md"
66
license = { text = "Apache-2.0" }
@@ -35,9 +35,14 @@ finmind-mcp = "finmind_mcp.server:main"
3535
dev = ["pytest>=7", "pytest-asyncio>=0.23", "respx>=0.21"]
3636

3737
[build-system]
38-
requires = ["hatchling"]
38+
requires = ["hatchling", "hatch-vcs"]
3939
build-backend = "hatchling.build"
4040

41+
# 版本來源 = git tag(透過 hatch-vcs / setuptools-scm)。
42+
# 推 tag vX.Y.Z → build 出來就是 X.Y.Z;非 tag commit 會是 dev 版號。
43+
[tool.hatch.version]
44+
source = "vcs"
45+
4146
[tool.hatch.build.targets.wheel]
4247
packages = ["src/finmind_mcp"]
4348

src/finmind_mcp/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
"""FinMind MCP server."""
22

3-
__version__ = "0.1.0"
3+
from importlib.metadata import PackageNotFoundError, version
4+
5+
try:
6+
__version__ = version("finmind-mcp")
7+
except PackageNotFoundError: # running from a source tree that isn't installed
8+
__version__ = "0.0.0+unknown"

uv.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)