Skip to content

🔖 bump version 0.2.1 -> 0.3.0 #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions .bin/bump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#!/usr/bin/env -S uv run --quiet
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "bumpver",
# "typer",
# ]
# ///
from __future__ import annotations

import re
import subprocess
import sys
from enum import Enum
from pathlib import Path
from typing import Annotated
from typing import Any

import typer
from typer import Option


class CommandRunner:
def run_command(self, command: str) -> tuple[bool, str]:
print(f"about to run command: {command}")
try:
output = subprocess.check_output(
command, shell=True, text=True, stderr=subprocess.STDOUT
).strip()
return True, output
except subprocess.CalledProcessError as e:
return False, e.output

def _build_command_args(self, **params: Any) -> str:
args = []
for key, value in params.items():
key = key.replace("_", "-")
if isinstance(value, bool) and value:
args.append(f"--{key}")
elif value is not None:
args.extend([f"--{key}", str(value)])
return " ".join(args)

def run(self, cmd: str, name: str, *args: str, **params: Any) -> str:
command_parts = [cmd, name]
command_parts.extend(args)
if params:
command_parts.append(self._build_command_args(**params))
success, output = self.run_command(" ".join(command_parts))
if not success:
print(f"{cmd} failed: {output}", file=sys.stderr)
raise typer.Exit(1)
return output


_runner = CommandRunner()


def bumpver(name: str, *args: str, **params: Any) -> str:
return _runner.run("bumpver", name, *args, **params)


def git(name: str, *args: str, **params: Any) -> str:
return _runner.run("git", name, *args, **params)


def gh(name: str, *args: str, **params: Any) -> str:
return _runner.run("gh", name, *args, **params)


def update_CHANGELOG(new_version: str) -> None:
repo_url = git("remote", "get-url", "origin").strip().replace(".git", "")
changelog = Path("CHANGELOG.md")

content = changelog.read_text()

content = re.sub(
r"## \[Unreleased\]",
f"## [{new_version}]",
content,
count=1,
)
content = re.sub(
rf"## \[{new_version}\]",
f"## [Unreleased]\n\n## [{new_version}]",
content,
count=1,
)
content += f"[{new_version}]: {repo_url}/releases/tag/v{new_version}\n"
content = re.sub(
r"\[unreleased\]: .*\n",
f"[unreleased]: {repo_url}/compare/v{new_version}...HEAD\n",
content,
count=1,
)

changelog.write_text(content)

git("add", ".")
git("commit", "-m", f"'update CHANGELOG for version {new_version}'")


class Version(str, Enum):
MAJOR = "major"
MINOR = "minor"
PATCH = "patch"


class Tag(str, Enum):
DEV = "dev"
ALPHA = "alpha"
BETA = "beta"
RC = "rc"
FINAL = "final"


def main(
version: Annotated[
Version, Option("--version", "-v", help="The tag to add to the new version")
],
tag: Annotated[Tag, Option("--tag", "-t", help="The tag to add to the new version")]
| None = None,
):
latest_tag = git("tag", "--sort=-creatordate", "|", "head -n 1")
changes = git(
"log", f"{latest_tag}..HEAD", "--pretty=format:'- `%h`: %s'", "--reverse"
)
new_version = re.search(
r"New Version: (.+)", bumpver("update", dry=True, tag=tag, **{version: True})
)
if new_version is None:
new_version = typer.prompt(
"Failed to get the new version from `bumpver`. Please enter it manually"
)
else:
new_version = new_version.group(1)
release_branch = f"release-v{new_version}"
git("checkout", "-b", release_branch)
bumpver("update", tag=tag, **{version: True})
title = git("log", "-1", "--pretty=%s")
update_CHANGELOG(new_version)
git("push", "--set-upstream", "'origin'", f"'{release_branch}'")
gh(
"pr",
"create",
"--base 'main'",
f"--head '{release_branch}'",
f"--title '{title}'",
f"--body '{changes}'",
)


if __name__ == "__main__":
typer.run(main)
15 changes: 15 additions & 0 deletions .just/project.just
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set unstable := true

justfile := justfile_directory() + "/.just/project.just"

[private]
default:
@just --list --justfile {{ justfile }}

[private]
fmt:
@just --fmt --justfile {{ justfile }}

[no-cd]
@bump *ARGS:
{{ justfile_directory() }}/.bin/bump.py {{ ARGS }}
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/

## [Unreleased]

## [0.3.0]

### Added

- Added `SyncGitHubAPI`, a synchronous implementation of `gidgethub.abc.GitHubAPI` for Django applications running under WSGI. Maintains the familiar gidgethub interface without requiring async/await.
Expand Down Expand Up @@ -58,7 +60,8 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/

- Josh Thomas <[email protected]> (maintainer)

[unreleased]: https://github.com/joshuadavidthomas/django-github-app/compare/v0.2.1...HEAD
[unreleased]: https://github.com/joshuadavidthomas/django-github-app/compare/v0.3.0...HEAD
[0.1.0]: https://github.com/joshuadavidthomas/django-github-app/releases/tag/v0.1.0
[0.2.0]: https://github.com/joshuadavidthomas/django-github-app/releases/tag/v0.2.0
[0.2.1]: https://github.com/joshuadavidthomas/django-github-app/releases/tag/v0.2.1
[0.3.0]: https://github.com/joshuadavidthomas/django-github-app/releases/tag/v0.3.0
1 change: 1 addition & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set dotenv-load := true
set unstable := true

mod docs ".just/documentation.just"
mod project ".just/project.just"

[private]
default:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Source = "https://github.com/joshuadavidthomas/django-github-app"
[tool.bumpver]
commit = true
commit_message = ":bookmark: bump version {old_version} -> {new_version}"
current_version = "0.2.1"
current_version = "0.3.0"
push = false # set to false for CI
tag = false
version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
Expand Down
2 changes: 1 addition & 1 deletion src/django_github_app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import annotations

__version__ = "0.2.1"
__version__ = "0.3.0"
2 changes: 1 addition & 1 deletion tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@


def test_version():
assert __version__ == "0.2.1"
assert __version__ == "0.3.0"