From 5fa6e42b281a95b64d0e3f8a4cd47a9f7a8b86b1 Mon Sep 17 00:00:00 2001 From: Minidoracat Date: Sat, 31 May 2025 03:51:52 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20=E6=9B=B4=E6=96=B0=20bumpversion?= =?UTF-8?q?=20=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=85=81=E8=A8=B1=E5=9C=A8?= =?UTF-8?q?=E6=9C=89=E6=9C=AA=E6=8F=90=E4=BA=A4=E8=AE=8A=E6=9B=B4=E7=9A=84?= =?UTF-8?q?=E6=83=85=E6=B3=81=E4=B8=8B=E9=80=B2=E8=A1=8C=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=8C=E4=B8=A6=E6=96=B0=E5=A2=9E=20bump2v?= =?UTF-8?q?ersion=20=E4=BE=9D=E8=B3=B4=E6=96=BC=E9=8E=96=E5=AE=9A=E6=AA=94?= =?UTF-8?q?=E6=A1=88=E4=B8=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 1 + .github/workflows/publish.yml | 11 +++++++++-- scripts/release.py | 14 ++++++-------- uv.lock | 11 +++++++++++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index f559689..8e5b6f8 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -2,6 +2,7 @@ current_version = 2.0.0 commit = False tag = False +allow_dirty = True parse = (?P\d+)\.(?P\d+)\.(?P\d+) serialize = {major}.{minor}.{patch} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 38048c6..8c1c990 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -36,13 +36,20 @@ jobs: - name: Install dependencies run: | - uv add --dev bump2version + uv sync --dev - name: Configure Git run: | git config --local user.email "action@github.com" 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 id: current_version run: | @@ -53,7 +60,7 @@ jobs: - name: Bump version id: bump_version 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) echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT echo "New version: $NEW_VERSION" diff --git a/scripts/release.py b/scripts/release.py index 60a909a..cdc4b11 100644 --- a/scripts/release.py +++ b/scripts/release.py @@ -39,8 +39,8 @@ def bump_version(version_type): current = get_current_version() print(f"📦 當前版本: {current}") - # 使用 bump2version - run_cmd(f"uv run bump2version {version_type}") + # 使用 bump2version with allow-dirty + run_cmd(f"uv run bump2version --allow-dirty {version_type}") new_version = get_current_version() print(f"🎉 新版本: {new_version}") @@ -56,14 +56,12 @@ def main(): print("🚀 開始發布流程...") - # 檢查是否有未提交的變更 + # 檢查 Git 狀態(僅提示,不阻止) result = run_cmd("git status --porcelain", check=False) if result.stdout.strip(): - print("⚠️ 有未提交的變更,請先提交或暫存") + print("⚠️ 有未提交的變更:") print(result.stdout) - choice = input("是否繼續? (y/N): ") - if choice.lower() != 'y': - sys.exit(1) + print("💡 將繼續執行(使用 --allow-dirty 模式)") # 更新版本 old_version, new_version = bump_version(version_type) @@ -76,7 +74,7 @@ def main(): print("🔍 檢查套件...") run_cmd("uv run twine check dist/*") - # 提交變更 + # 提交所有變更(包括版本更新) print("💾 提交版本更新...") run_cmd("git add .") run_cmd(f'git commit -m "🔖 Release v{new_version}"') diff --git a/uv.lock b/uv.lock index 4507a00..b6a92fd 100644 --- a/uv.lock +++ b/uv.lock @@ -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 }, ] +[[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]] name = "certifi" version = "2025.1.31" @@ -493,6 +502,7 @@ dev = [ [package.dev-dependencies] dev = [ + { name = "bump2version" }, { name = "pytest" }, { name = "pytest-asyncio" }, { name = "twine" }, @@ -513,6 +523,7 @@ requires-dist = [ [package.metadata.requires-dev] dev = [ + { name = "bump2version", specifier = ">=1.0.1" }, { name = "pytest", specifier = ">=7.0.0" }, { name = "pytest-asyncio", specifier = ">=0.21.0" }, { name = "twine", specifier = ">=6.1.0" },