🔧 更新 bumpversion 配置,允許在有未提交變更的情況下進行版本更新,並新增 bump2version 依賴於鎖定檔案中。

This commit is contained in:
Minidoracat 2025-05-31 03:51:52 +08:00
parent 525e875f24
commit 5fa6e42b28
4 changed files with 27 additions and 10 deletions

View File

@ -2,6 +2,7 @@
current_version = 2.0.0 current_version = 2.0.0
commit = False commit = False
tag = False tag = False
allow_dirty = True
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+) parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
serialize = {major}.{minor}.{patch} serialize = {major}.{minor}.{patch}

View File

@ -36,13 +36,20 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: | run: |
uv add --dev bump2version uv sync --dev
- name: Configure Git - name: Configure Git
run: | run: |
git config --local user.email "action@github.com" git config --local user.email "action@github.com"
git config --local user.name "GitHub Action" git config --local user.name "GitHub Action"
- name: Commit dependency changes if any
run: |
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m "📦 Update dependencies" || true
fi
- name: Get current version - name: Get current version
id: current_version id: current_version
run: | run: |
@ -53,7 +60,7 @@ jobs:
- name: Bump version - name: Bump version
id: bump_version id: bump_version
run: | run: |
uv run bump2version ${{ github.event.inputs.version_type }} uv run bump2version --allow-dirty ${{ github.event.inputs.version_type }}
NEW_VERSION=$(grep '^version =' pyproject.toml | cut -d'"' -f2) NEW_VERSION=$(grep '^version =' pyproject.toml | cut -d'"' -f2)
echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION" echo "New version: $NEW_VERSION"

View File

@ -39,8 +39,8 @@ def bump_version(version_type):
current = get_current_version() current = get_current_version()
print(f"📦 當前版本: {current}") print(f"📦 當前版本: {current}")
# 使用 bump2version # 使用 bump2version with allow-dirty
run_cmd(f"uv run bump2version {version_type}") run_cmd(f"uv run bump2version --allow-dirty {version_type}")
new_version = get_current_version() new_version = get_current_version()
print(f"🎉 新版本: {new_version}") print(f"🎉 新版本: {new_version}")
@ -56,14 +56,12 @@ def main():
print("🚀 開始發布流程...") print("🚀 開始發布流程...")
# 檢查是否有未提交的變更 # 檢查 Git 狀態(僅提示,不阻止)
result = run_cmd("git status --porcelain", check=False) result = run_cmd("git status --porcelain", check=False)
if result.stdout.strip(): if result.stdout.strip():
print("⚠️ 有未提交的變更,請先提交或暫存") print("⚠️ 有未提交的變更")
print(result.stdout) print(result.stdout)
choice = input("是否繼續? (y/N): ") print("💡 將繼續執行(使用 --allow-dirty 模式)")
if choice.lower() != 'y':
sys.exit(1)
# 更新版本 # 更新版本
old_version, new_version = bump_version(version_type) old_version, new_version = bump_version(version_type)
@ -76,7 +74,7 @@ def main():
print("🔍 檢查套件...") print("🔍 檢查套件...")
run_cmd("uv run twine check dist/*") run_cmd("uv run twine check dist/*")
# 提交變更 # 提交所有變更(包括版本更新)
print("💾 提交版本更新...") print("💾 提交版本更新...")
run_cmd("git add .") run_cmd("git add .")
run_cmd(f'git commit -m "🔖 Release v{new_version}"') run_cmd(f'git commit -m "🔖 Release v{new_version}"')

11
uv.lock generated
View File

@ -33,6 +33,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/b9/fa/123043af240e49752f1c4bd24da5053b6bd00cad78c2be53c0d1e8b975bc/backports.tarfile-1.2.0-py3-none-any.whl", hash = "sha256:77e284d754527b01fb1e6fa8a1afe577858ebe4e9dad8919e34c862cb399bc34", size = 30181 }, { url = "https://files.pythonhosted.org/packages/b9/fa/123043af240e49752f1c4bd24da5053b6bd00cad78c2be53c0d1e8b975bc/backports.tarfile-1.2.0-py3-none-any.whl", hash = "sha256:77e284d754527b01fb1e6fa8a1afe577858ebe4e9dad8919e34c862cb399bc34", size = 30181 },
] ]
[[package]]
name = "bump2version"
version = "1.0.1"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/29/2a/688aca6eeebfe8941235be53f4da780c6edee05dbbea5d7abaa3aab6fad2/bump2version-1.0.1.tar.gz", hash = "sha256:762cb2bfad61f4ec8e2bdf452c7c267416f8c70dd9ecb1653fd0bbb01fa936e6", size = 36236 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/1d/e3/fa60c47d7c344533142eb3af0b73234ef8ea3fb2da742ab976b947e717df/bump2version-1.0.1-py2.py3-none-any.whl", hash = "sha256:37f927ea17cde7ae2d7baf832f8e80ce3777624554a653006c9144f8017fe410", size = 22030 },
]
[[package]] [[package]]
name = "certifi" name = "certifi"
version = "2025.1.31" version = "2025.1.31"
@ -493,6 +502,7 @@ dev = [
[package.dev-dependencies] [package.dev-dependencies]
dev = [ dev = [
{ name = "bump2version" },
{ name = "pytest" }, { name = "pytest" },
{ name = "pytest-asyncio" }, { name = "pytest-asyncio" },
{ name = "twine" }, { name = "twine" },
@ -513,6 +523,7 @@ requires-dist = [
[package.metadata.requires-dev] [package.metadata.requires-dev]
dev = [ dev = [
{ name = "bump2version", specifier = ">=1.0.1" },
{ name = "pytest", specifier = ">=7.0.0" }, { name = "pytest", specifier = ">=7.0.0" },
{ name = "pytest-asyncio", specifier = ">=0.21.0" }, { name = "pytest-asyncio", specifier = ">=0.21.0" },
{ name = "twine", specifier = ">=6.1.0" }, { name = "twine", specifier = ">=6.1.0" },