|
| 1 | +from pathlib import Path |
| 2 | +from subprocess import check_output |
| 3 | + |
| 4 | +import invoke |
| 5 | + |
| 6 | + |
| 7 | +@invoke.task(help={ |
| 8 | + 'version': 'version being released', |
| 9 | +}) |
| 10 | +def announce(ctx, version): |
| 11 | + """Generates a new release announcement entry in the docs.""" |
| 12 | + print("[generate.announce] Generating Announce") |
| 13 | + |
| 14 | + # Get our list of authors |
| 15 | + print("[generate.announce] Collecting author names") |
| 16 | + |
| 17 | + stdout = check_output(["git", "describe", "--abbrev=0", '--tags']) |
| 18 | + stdout = stdout.decode('utf-8') |
| 19 | + last_version = stdout.strip() |
| 20 | + |
| 21 | + stdout = check_output(["git", "log", "{}..HEAD".format(last_version), "--format=%aN"]) |
| 22 | + stdout = stdout.decode('utf-8') |
| 23 | + |
| 24 | + contributors = set(stdout.splitlines()) |
| 25 | + |
| 26 | + template_name = 'release.minor.rst' if version.endswith('.0') else 'release.patch.rst' |
| 27 | + template_text = Path(__file__).parent.joinpath(template_name).read_text(encoding='UTF-8') |
| 28 | + |
| 29 | + contributors_text = '\n'.join('* {}'.format(name) for name in sorted(contributors)) + '\n' |
| 30 | + text = template_text.format(version=version, contributors=contributors_text) |
| 31 | + |
| 32 | + target = Path(__file__).joinpath('../../doc/en/announce/release-{}.rst'.format(version)) |
| 33 | + target.write_text(text, encoding='UTF-8') |
| 34 | + print("[generate.announce] Generated {}".format(target.name)) |
| 35 | + |
| 36 | + # Update index with the new release entry |
| 37 | + index_path = Path(__file__).joinpath('../../doc/en/announce/index.rst') |
| 38 | + lines = index_path.read_text(encoding='UTF-8').splitlines() |
| 39 | + indent = ' ' |
| 40 | + for index, line in enumerate(lines): |
| 41 | + if line.startswith('{}release-'.format(indent)): |
| 42 | + new_line = indent + target.stem |
| 43 | + if line != new_line: |
| 44 | + lines.insert(index, new_line) |
| 45 | + index_path.write_text('\n'.join(lines) + '\n', encoding='UTF-8') |
| 46 | + print("[generate.announce] Updated {}".format(index_path.name)) |
| 47 | + else: |
| 48 | + print("[generate.announce] Skip {} (already contains release)".format(index_path.name)) |
| 49 | + break |
| 50 | + |
| 51 | + print() |
| 52 | + print('Please review the generated files and commit with:') |
| 53 | + print(' git commit -a -m "Generate new release announcement for {}'.format(version)) |
| 54 | + |
| 55 | + |
| 56 | + |
0 commit comments