| 1 |
#!/usr/bin/env python3 |
| 2 |
# SPDX-License-Identifier: Apache-2.0 |
| 3 |
# Copyright 2019 The Meson development team |
| 4 |
|
| 5 |
''' |
| 6 |
Generates release notes for new releases of Meson build system |
| 7 |
''' |
| 8 |
import argparse |
| 9 |
import subprocess |
| 10 |
import re |
| 11 |
import shutil |
| 12 |
import datetime |
| 13 |
from pathlib import Path |
| 14 |
|
| 15 |
RELNOTE_TEMPLATE = '''--- |
| 16 |
title: Release {} |
| 17 |
short-description: Release notes for {} |
| 18 |
... |
| 19 |
|
| 20 |
# New features{} |
| 21 |
|
| 22 |
''' |
| 23 |
|
| 24 |
|
| 25 |
def add_to_sitemap(sitemap, output_sitemap): |
| 26 |
''' |
| 27 |
Adds release note entry to sitemap.txt. |
| 28 |
''' |
| 29 |
sitemapfile = Path(sitemap) |
| 30 |
with sitemapfile.open(encoding='utf-8') as s_f: |
| 31 |
lines = s_f.readlines() |
| 32 |
relnotes = None |
| 33 |
to_version = None |
| 34 |
output = Path(output_sitemap) |
| 35 |
output.parent.mkdir(exist_ok=True, parents=True) |
| 36 |
with output.open('w', encoding='utf-8') as s_f: |
| 37 |
for line in lines: |
| 38 |
if relnotes is None: |
| 39 |
m = re.match(r'[\s]*Release-notes-for-([0-9]+)\.([0-9]+)\.([0-9]+)\.md', line) |
| 40 |
if m: |
| 41 |
from_version = f'{m[1]}.{m[2]}.{m[3]}' |
| 42 |
if from_version == '0.64.0': |
| 43 |
to_version = '1.0.0' |
| 44 |
else: |
| 45 |
to_version = f'{m[1]}.{int(m[2]) + 1}.{m[3]}' |
| 46 |
new_line = line.replace(from_version, to_version) |
| 47 |
relnotes = new_line.strip() |
| 48 |
s_f.write(new_line) |
| 49 |
s_f.write(line) |
| 50 |
|
| 51 |
if sitemapfile == output: |
| 52 |
subprocess.check_call(['git', 'add', output]) |
| 53 |
|
| 54 |
return relnotes, to_version |
| 55 |
|
| 56 |
def generate(relnotes, to_version, source_dir, output_dir): |
| 57 |
''' |
| 58 |
Generate notes for Meson build next release. |
| 59 |
''' |
| 60 |
title_suffix = ' (in development)' if output_dir else '' |
| 61 |
title = f'{to_version}{title_suffix}' |
| 62 |
output = Path(output_dir, relnotes) if output_dir else Path('markdown', relnotes) |
| 63 |
output.parent.mkdir(exist_ok=True, parents=True) |
| 64 |
with output.open('w', encoding='utf-8') as ofile: |
| 65 |
ofile.write(RELNOTE_TEMPLATE.format(title, to_version, title_suffix)) |
| 66 |
if not output_dir: |
| 67 |
date = datetime.date.today() |
| 68 |
date_str = date.strftime("%d %B %Y") |
| 69 |
ofile.write(f'Meson {to_version} was released on {date_str}\n') |
| 70 |
for snippetfile in sorted(Path(source_dir, 'markdown/snippets').glob('*.md')): |
| 71 |
snippet = snippetfile.read_text(encoding='utf-8') |
| 72 |
ofile.write(snippet) |
| 73 |
if not snippet.endswith('\n'): |
| 74 |
ofile.write('\n') |
| 75 |
ofile.write('\n') |
| 76 |
|
| 77 |
if not output_dir: |
| 78 |
subprocess.check_call(['git', 'rm', 'markdown/snippets/*.md']) |
| 79 |
subprocess.check_call(['git', 'add', output]) |
| 80 |
|
| 81 |
if __name__ == '__main__': |
| 82 |
parser = argparse.ArgumentParser(description='Generate meson docs') |
| 83 |
parser.add_argument('--input-sitemap', default='sitemap.txt') |
| 84 |
parser.add_argument('--output-sitemap', default='sitemap.txt') |
| 85 |
parser.add_argument('--source-dir', default='.') |
| 86 |
parser.add_argument('--output-dir') |
| 87 |
|
| 88 |
args = parser.parse_args() |
| 89 |
|
| 90 |
if Path(args.source_dir, 'markdown/snippets').glob('*.md'): |
| 91 |
relnotes, to_version = add_to_sitemap(args.input_sitemap, args.output_sitemap) |
| 92 |
generate(relnotes, to_version, args.source_dir, args.output_dir) |
| 93 |
elif args.input_sitemap != args.output_sitemap: |
| 94 |
shutil.copyfile(args.input_sitemap, args.output_sitemap) |