Skip to content

Commit

Permalink
nox: add_tag_for_release
Browse files Browse the repository at this point in the history
  • Loading branch information
paugier committed Feb 3, 2024
1 parent 62a9752 commit f62a457
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,58 @@ def doc(session):
session.chdir("doc")
session.run("make", "cleanall", external=True)
session.run("make", external=True)


def _get_version_from_pyproject(path=Path.cwd()):
if isinstance(path, str):
path = Path(path)

if not path.name == "pyproject.toml":
path /= "pyproject.toml"

in_project = False
version = None
with open(path, encoding="utf-8") as file:
for line in file:
if line.startswith("[project]"):
in_project = True
if line.startswith("version =") and in_project:
version = line.split("=")[1].strip()
version = version[1:-1]
break

assert version is not None
return version


@nox.session(name="add-tag-for-release", venv_backend="none")
def add_tag_for_release(session):
session.run("hg", "pull", external=True)

result = session.run(
*"hg log -r default -G".split(), external=True, silent=True
)
if result[0] != "@":
session.run("hg", "update", "default", external=True)

version = _get_version_from_pyproject()
print(f"{version = }")

result = session.run("hg", "tags", "-T", "{tag},", external=True, silent=True)
last_tag = result.split(",", 2)[1]
print(f"{last_tag = }")

if last_tag == version:
session.error("last_tag == version")

answer = input(
f'Do you really want to add and push the new tag "{version}"? (yes/[no]) '
)

if answer != "yes":
print("Maybe next time then. Bye!")
return

print("Let's go!")
session.run("hg", "tag", version, external=True)
session.run("hg", "push", external=True)

0 comments on commit f62a457

Please sign in to comment.