From 015c2f53d46d121a36ae42bdb0b6e2dd7a10c83a Mon Sep 17 00:00:00 2001 From: Taegyun Ha Date: Wed, 15 Apr 2026 12:00:18 +0100 Subject: [PATCH 1/2] add version bump action --- .github/workflows/bump-version.yml | 76 ++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/bump-version.yml diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml new file mode 100644 index 0000000..6c4ec62 --- /dev/null +++ b/.github/workflows/bump-version.yml @@ -0,0 +1,76 @@ +name: Bump Version + +on: + workflow_dispatch: + inputs: + bump_type: + description: "Version bump type" + required: true + type: choice + options: + - patch + - minor + - major + +jobs: + bump-version: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/dev' + permissions: + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Bump version in pyproject.toml + id: bump + env: + BUMP_TYPE: ${{ github.event.inputs.bump_type }} + run: | + python3 << 'EOF' + import re, os, sys + + bump_type = os.environ["BUMP_TYPE"] + + with open("pyproject.toml") as f: + content = f.read() + + match = re.search(r'^version = "(\d+)\.(\d+)\.(\d+)"', content, re.MULTILINE) + if not match: + print("Could not find version in pyproject.toml", file=sys.stderr) + sys.exit(1) + + major, minor, patch = int(match.group(1)), int(match.group(2)), int(match.group(3)) + old_version = f"{major}.{minor}.{patch}" + + if bump_type == "major": + major += 1; minor = 0; patch = 0 + elif bump_type == "minor": + minor += 1; patch = 0 + else: + patch += 1 + + new_version = f"{major}.{minor}.{patch}" + new_content = content.replace(f'version = "{old_version}"', f'version = "{new_version}"', 1) + + with open("pyproject.toml", "w") as f: + f.write(new_content) + + with open(os.environ["GITHUB_OUTPUT"], "a") as f: + f.write(f"old_version={old_version}\n") + f.write(f"new_version={new_version}\n") + + print(f"Version bumped: {old_version} -> {new_version}") + EOF + + - name: Configure git + run: | + git config user.name "${{ github.actor }}" + git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" + + - name: Commit and push + run: | + git add pyproject.toml + git commit -m "bump version ${{ steps.bump.outputs.old_version }} -> ${{ steps.bump.outputs.new_version }}" + git push origin dev From e5346c1a14b8320a79a6d4a4d26e7cc635ad46d2 Mon Sep 17 00:00:00 2001 From: Taegyun Ha Date: Mon, 27 Apr 2026 16:47:08 +0100 Subject: [PATCH 2/2] update PR feedback --- .github/workflows/bump-version.yml | 63 ++++++++++++++++++++---------- .github/workflows/release.yml | 2 +- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml index 6c4ec62..87f6c55 100644 --- a/.github/workflows/bump-version.yml +++ b/.github/workflows/bump-version.yml @@ -15,47 +15,60 @@ on: jobs: bump-version: runs-on: ubuntu-latest - if: github.ref == 'refs/heads/dev' permissions: contents: write + pull-requests: write steps: + - name: Assert dev branch + run: | + if [ "$GITHUB_REF" != "refs/heads/dev" ]; then + echo "Error: This workflow must be run from the dev branch (got $GITHUB_REF)." + exit 1 + fi + - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 + + - name: Install uv + uses: astral-sh/setup-uv@v8.1.0 + with: + python-version: "3.12" - name: Bump version in pyproject.toml id: bump env: BUMP_TYPE: ${{ github.event.inputs.bump_type }} run: | - python3 << 'EOF' - import re, os, sys + uv run - << 'EOF' + # /// script + # dependencies = ["tomli-w"] + # /// + import tomllib, tomli_w, os bump_type = os.environ["BUMP_TYPE"] - with open("pyproject.toml") as f: - content = f.read() + with open("pyproject.toml", "rb") as f: + data = tomllib.load(f) - match = re.search(r'^version = "(\d+)\.(\d+)\.(\d+)"', content, re.MULTILINE) - if not match: - print("Could not find version in pyproject.toml", file=sys.stderr) - sys.exit(1) - - major, minor, patch = int(match.group(1)), int(match.group(2)), int(match.group(3)) - old_version = f"{major}.{minor}.{patch}" + old_version = data["project"]["version"] + major, minor, patch = map(int, old_version.split(".")) if bump_type == "major": - major += 1; minor = 0; patch = 0 + major += 1 + minor = 0 + patch = 0 elif bump_type == "minor": - minor += 1; patch = 0 + minor += 1 + patch = 0 else: patch += 1 new_version = f"{major}.{minor}.{patch}" - new_content = content.replace(f'version = "{old_version}"', f'version = "{new_version}"', 1) + data["project"]["version"] = new_version - with open("pyproject.toml", "w") as f: - f.write(new_content) + with open("pyproject.toml", "wb") as fp: + tomli_w.dump(data, fp) with open(os.environ["GITHUB_OUTPUT"], "a") as f: f.write(f"old_version={old_version}\n") @@ -69,8 +82,18 @@ jobs: git config user.name "${{ github.actor }}" git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" - - name: Commit and push + - name: Create PR + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | + BRANCH="bump-version/${{ steps.bump.outputs.new_version }}" + git checkout -b "$BRANCH" git add pyproject.toml git commit -m "bump version ${{ steps.bump.outputs.old_version }} -> ${{ steps.bump.outputs.new_version }}" - git push origin dev + git push origin "$BRANCH" + gh pr create \ + --title "bump version ${{ steps.bump.outputs.old_version }} -> ${{ steps.bump.outputs.new_version }}" \ + --body "Automated ${{ github.event.inputs.bump_type }} version bump triggered by @${{ github.actor }}." \ + --base dev \ + --head "$BRANCH" \ + --label "release" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9a83c6e..6bf7609 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: fetch-depth: 0 - name: Install uv - uses: astral-sh/setup-uv@v8.0.0 + uses: astral-sh/setup-uv@v8.1.0 with: python-version: "3.12"