Skip to content

Commit

Permalink
Merge pull request #13 from agateau/prep-release
Browse files Browse the repository at this point in the history
Prepare 0.3.0
  • Loading branch information
agateau authored Nov 13, 2022
2 parents a8d7e74 + 3fc6bba commit 773fdc7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changes/0.3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 0.3.0 - 2022-11-13

### Changed

- Git Bonsai now detects the default branch and always considers it protected.
3 changes: 0 additions & 3 deletions .changes/unreleased/Changed-20221111-191851.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.3.0 - 2022-11-13

### Changed

- Git Bonsai now detects the default branch and always considers it protected.

## 0.2.2 - 2022-07-22

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "git-bonsai"
version = "0.2.2"
version = "0.3.0"
authors = ["Aurélien Gâteau <[email protected]>"]
edition = "2018"
description = "Command-line tool to clean the branches of your git garden"
Expand Down
59 changes: 40 additions & 19 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@
from invoke import task, run


VERSION = os.environ["VERSION"]

ARTIFACTS_DIR = Path("artifacts")

MAIN_BRANCH = "master"

def get_version():
return os.environ["VERSION"]


def erun(*args, **kwargs):
"""Like run, but with echo on"""
kwargs["echo"] = True
run(*args, **kwargs)
return run(*args, **kwargs)


def cerun(c, *args, **kwargs):
"""Like Context.run, but with echo on"""
kwargs["echo"] = True
c.run(*args, **kwargs)
return c.run(*args, **kwargs)


def ask(msg: str) -> str:
Expand All @@ -49,19 +50,30 @@ def is_ok(msg: str) -> bool:
return answer == "y"


@task
def create_pr(c):
"""Create a pull-request and mark it as auto-mergeable"""
result = cerun(c, "gh pr create --fill", warn=True)
if not result:
sys.exit(1)
cerun(c, f"gh pr merge --auto -dm")


@task
def update_version(c):
version = get_version()
path = Path("Cargo.toml")
text = path.read_text()
text, count = re.subn(r"^version = .*", f"version = \"{VERSION}\"", text,
text, count = re.subn(r"^version = .*", f"version = \"{version}\"", text,
flags=re.MULTILINE)
assert count == 0 or count == 1
path.write_text(text)


@task
def prepare_release(c):
run(f"gh issue list -m {VERSION}", pty=True)
version = get_version()
run(f"gh issue list -m {version}", pty=True)
run("gh pr list", pty=True)
if not is_ok("Continue?"):
sys.exit(1)
Expand All @@ -77,12 +89,13 @@ def prepare_release(c):

@task
def prepare_release2(c):
version = get_version()
erun("git checkout -b prep-release")

update_version(c)

erun(f"changie batch {VERSION}")
print(f"Review/edit changelog (.changes/{VERSION}.md)")
erun(f"changie batch {version}")
print(f"Review/edit changelog (.changes/{version}.md)")
if not is_ok("Looks good?"):
sys.exit(1)
erun("changie merge")
Expand All @@ -96,27 +109,34 @@ def prepare_release2(c):

@task
def prepare_release3(c):
erun("git add Cargo.toml CHANGELOG.md .changes")
erun(f"git commit -m 'Prepare {VERSION}'")
erun("git push -u origin prep-release")
version = get_version()
# Rebuild to ensure Cargo.lock is updated
erun("cargo build")
erun("git add Cargo.toml Cargo.lock CHANGELOG.md .changes")

erun("cargo publish --dry-run")
erun("cargo package --list")

erun(f"git commit -m 'Prepare {version}'")
erun("git push -u origin prep-release")
create_pr(c)


@task
def tag(c):
version = get_version()
erun(f"git checkout {MAIN_BRANCH}")
erun("git merge --no-ff prep-release")
erun(f"git tag -a {VERSION} -m 'Releasing version {VERSION}'")

if not is_ok("Push tag?"):
erun("git pull")
changes_file = Path(".changes") / f"{version}.md"
if not changes_file.exists():
print(f"{changes_file} does not exist, check previous PR has been merged")
sys.exit(1)
if not is_ok("Create tag?"):
sys.exit(1)

erun(f"git tag -a {version} -m 'Releasing version {version}'")

erun("git push")
erun("git push --tags")
erun("git push -d origin prep-release")
erun("git branch -d prep-release")


def get_artifact_list() -> List[Path]:
Expand All @@ -134,6 +154,7 @@ def download_artifacts(c):

@task
def publish(c):
version = get_version()
files_str = " ".join(str(x) for x in get_artifact_list())
erun(f"gh release create {VERSION} -F.changes/{VERSION}.md {files_str}")
erun(f"gh release create {version} -F.changes/{version}.md {files_str}")
erun("cargo publish")

0 comments on commit 773fdc7

Please sign in to comment.