2018-02-10 06:59:15 +08:00
|
|
|
"""
|
|
|
|
Invoke development tasks.
|
|
|
|
"""
|
2017-05-10 09:55:27 +08:00
|
|
|
from pathlib import Path
|
2017-05-16 07:23:04 +08:00
|
|
|
from subprocess import check_output, check_call
|
2017-05-10 09:55:27 +08:00
|
|
|
|
|
|
|
import invoke
|
|
|
|
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@invoke.task(help={"version": "version being released"})
|
2017-05-10 09:55:27 +08:00
|
|
|
def announce(ctx, version):
|
|
|
|
"""Generates a new release announcement entry in the docs."""
|
|
|
|
# Get our list of authors
|
2018-05-23 22:48:46 +08:00
|
|
|
stdout = check_output(["git", "describe", "--abbrev=0", "--tags"])
|
|
|
|
stdout = stdout.decode("utf-8")
|
2017-05-10 09:55:27 +08:00
|
|
|
last_version = stdout.strip()
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
stdout = check_output(
|
|
|
|
["git", "log", "{}..HEAD".format(last_version), "--format=%aN"]
|
|
|
|
)
|
|
|
|
stdout = stdout.decode("utf-8")
|
2017-05-10 09:55:27 +08:00
|
|
|
|
|
|
|
contributors = set(stdout.splitlines())
|
|
|
|
|
2018-06-26 21:35:27 +08:00
|
|
|
template_name = (
|
|
|
|
"release.minor.rst" if version.endswith(".0") else "release.patch.rst"
|
|
|
|
)
|
|
|
|
template_text = (
|
|
|
|
Path(__file__).parent.joinpath(template_name).read_text(encoding="UTF-8")
|
2018-05-23 22:48:46 +08:00
|
|
|
)
|
2017-05-10 09:55:27 +08:00
|
|
|
|
2018-06-26 21:35:27 +08:00
|
|
|
contributors_text = (
|
|
|
|
"\n".join("* {}".format(name) for name in sorted(contributors)) + "\n"
|
|
|
|
)
|
2017-05-10 09:55:27 +08:00
|
|
|
text = template_text.format(version=version, contributors=contributors_text)
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
target = Path(__file__).parent.joinpath(
|
|
|
|
"../doc/en/announce/release-{}.rst".format(version)
|
|
|
|
)
|
|
|
|
target.write_text(text, encoding="UTF-8")
|
2017-05-10 09:55:27 +08:00
|
|
|
print("[generate.announce] Generated {}".format(target.name))
|
|
|
|
|
|
|
|
# Update index with the new release entry
|
2018-05-23 22:48:46 +08:00
|
|
|
index_path = Path(__file__).parent.joinpath("../doc/en/announce/index.rst")
|
|
|
|
lines = index_path.read_text(encoding="UTF-8").splitlines()
|
|
|
|
indent = " "
|
2017-05-10 09:55:27 +08:00
|
|
|
for index, line in enumerate(lines):
|
2018-05-23 22:48:46 +08:00
|
|
|
if line.startswith("{}release-".format(indent)):
|
2017-05-10 09:55:27 +08:00
|
|
|
new_line = indent + target.stem
|
|
|
|
if line != new_line:
|
|
|
|
lines.insert(index, new_line)
|
2018-05-23 22:48:46 +08:00
|
|
|
index_path.write_text("\n".join(lines) + "\n", encoding="UTF-8")
|
2017-05-10 09:55:27 +08:00
|
|
|
print("[generate.announce] Updated {}".format(index_path.name))
|
|
|
|
else:
|
2018-05-23 22:48:46 +08:00
|
|
|
print(
|
|
|
|
"[generate.announce] Skip {} (already contains release)".format(
|
|
|
|
index_path.name
|
|
|
|
)
|
|
|
|
)
|
2017-05-10 09:55:27 +08:00
|
|
|
break
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
check_call(["git", "add", str(target)])
|
2017-05-16 07:23:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
@invoke.task()
|
|
|
|
def regen(ctx):
|
|
|
|
"""Call regendoc tool to update examples and pytest output in the docs."""
|
|
|
|
print("[generate.regen] Updating docs")
|
2018-05-23 22:48:46 +08:00
|
|
|
check_call(["tox", "-e", "regen"])
|
2017-05-16 07:23:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
@invoke.task()
|
|
|
|
def make_tag(ctx, version):
|
2018-02-10 06:59:15 +08:00
|
|
|
"""Create a new, local tag for the release, only if the repository is clean."""
|
2017-05-16 07:23:04 +08:00
|
|
|
from git import Repo
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
repo = Repo(".")
|
2017-05-16 07:23:04 +08:00
|
|
|
if repo.is_dirty():
|
2018-05-23 22:48:46 +08:00
|
|
|
print("Current repository is dirty. Please commit any changes and try again.")
|
2017-05-16 07:23:04 +08:00
|
|
|
raise invoke.Exit(code=2)
|
|
|
|
|
|
|
|
tag_names = [x.name for x in repo.tags]
|
|
|
|
if version in tag_names:
|
|
|
|
print("[generate.make_tag] Delete existing tag {}".format(version))
|
|
|
|
repo.delete_tag(version)
|
|
|
|
|
|
|
|
print("[generate.make_tag] Create tag {}".format(version))
|
|
|
|
repo.create_tag(version)
|
2017-05-10 09:55:27 +08:00
|
|
|
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@invoke.task(help={"version": "version being released"})
|
2018-02-10 06:59:15 +08:00
|
|
|
def pre_release(ctx, version):
|
|
|
|
"""Generates new docs, release announcements and creates a local tag."""
|
2017-05-16 07:23:04 +08:00
|
|
|
announce(ctx, version)
|
|
|
|
regen(ctx)
|
2017-05-30 21:54:15 +08:00
|
|
|
changelog(ctx, version, write_out=True)
|
2017-05-16 07:23:04 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
msg = "Preparing release version {}".format(version)
|
|
|
|
check_call(["git", "commit", "-a", "-m", msg])
|
2018-02-10 06:59:15 +08:00
|
|
|
|
2017-05-16 07:23:04 +08:00
|
|
|
make_tag(ctx, version)
|
|
|
|
|
|
|
|
print()
|
2018-05-23 22:48:46 +08:00
|
|
|
print("[generate.pre_release] Please push your branch and open a PR.")
|
2017-05-10 09:55:27 +08:00
|
|
|
|
2017-05-23 06:06:53 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@invoke.task(
|
|
|
|
help={
|
|
|
|
"version": "version being released",
|
|
|
|
"write_out": "write changes to the actual changelog",
|
|
|
|
}
|
|
|
|
)
|
2017-05-30 21:54:15 +08:00
|
|
|
def changelog(ctx, version, write_out=False):
|
|
|
|
if write_out:
|
|
|
|
addopts = []
|
|
|
|
else:
|
2018-05-23 22:48:46 +08:00
|
|
|
addopts = ["--draft"]
|
|
|
|
check_call(["towncrier", "--yes", "--version", version] + addopts)
|