|
|
|
@ -16,10 +16,11 @@ |
|
|
|
|
''' |
|
|
|
|
Generates release notes for new releases of Meson build system |
|
|
|
|
''' |
|
|
|
|
import argparse |
|
|
|
|
import subprocess |
|
|
|
|
import sys |
|
|
|
|
import os |
|
|
|
|
from glob import glob |
|
|
|
|
import re |
|
|
|
|
import shutil |
|
|
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
|
RELNOTE_TEMPLATE = '''--- |
|
|
|
|
title: Release {} |
|
|
|
@ -31,43 +32,65 @@ short-description: Release notes for {} |
|
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_to_sitemap(from_version, to_version): |
|
|
|
|
def add_to_sitemap(sitemap, output_sitemap): |
|
|
|
|
''' |
|
|
|
|
Adds release note entry to sitemap.txt. |
|
|
|
|
''' |
|
|
|
|
sitemapfile = '../sitemap.txt' |
|
|
|
|
s_f = open(sitemapfile, encoding='utf-8') |
|
|
|
|
sitemapfile = Path(sitemap) |
|
|
|
|
with sitemapfile.open(encoding='utf-8') as s_f: |
|
|
|
|
lines = s_f.readlines() |
|
|
|
|
s_f.close() |
|
|
|
|
with open(sitemapfile, 'w', encoding='utf-8') as s_f: |
|
|
|
|
relnotes = None |
|
|
|
|
to_version = None |
|
|
|
|
output = Path(output_sitemap) |
|
|
|
|
output.parent.mkdir(exist_ok=True, parents=True) |
|
|
|
|
with output.open('w', encoding='utf-8') as s_f: |
|
|
|
|
for line in lines: |
|
|
|
|
if 'Release-notes' in line and from_version in line: |
|
|
|
|
if relnotes is None: |
|
|
|
|
m = re.match(r'[\s]*Release-notes-for-([0-9]+)\.([0-9]+)\.([0-9]+)\.md', line) |
|
|
|
|
if m: |
|
|
|
|
from_version = f'{m[1]}.{m[2]}.{m[3]}' |
|
|
|
|
to_version = f'{m[1]}.{int(m[2]) + 1}.{m[3]}' |
|
|
|
|
new_line = line.replace(from_version, to_version) |
|
|
|
|
relnotes = new_line.strip() |
|
|
|
|
s_f.write(new_line) |
|
|
|
|
s_f.write(line) |
|
|
|
|
|
|
|
|
|
def generate(from_version, to_version): |
|
|
|
|
if sitemapfile == output: |
|
|
|
|
subprocess.check_call(['git', 'add', output]) |
|
|
|
|
|
|
|
|
|
return relnotes, to_version |
|
|
|
|
|
|
|
|
|
def generate(relnotes, to_version, source_dir, output_dir): |
|
|
|
|
''' |
|
|
|
|
Generate notes for Meson build next release. |
|
|
|
|
''' |
|
|
|
|
ofilename = f'Release-notes-for-{to_version}.md' |
|
|
|
|
with open(ofilename, 'w', encoding='utf-8') as ofile: |
|
|
|
|
ofile.write(RELNOTE_TEMPLATE.format(to_version, to_version)) |
|
|
|
|
for snippetfile in glob('snippets/*.md'): |
|
|
|
|
snippet = open(snippetfile, encoding='utf-8').read() |
|
|
|
|
release = f'{to_version} (in development)' if output_dir else to_version |
|
|
|
|
output = Path(output_dir, relnotes) if output_dir else Path('markdown', relnotes) |
|
|
|
|
output.parent.mkdir(exist_ok=True, parents=True) |
|
|
|
|
with output.open('w', encoding='utf-8') as ofile: |
|
|
|
|
ofile.write(RELNOTE_TEMPLATE.format(release, to_version)) |
|
|
|
|
for snippetfile in Path(source_dir, 'markdown/snippets').glob('*.md'): |
|
|
|
|
snippet = snippetfile.read_text(encoding='utf-8') |
|
|
|
|
ofile.write(snippet) |
|
|
|
|
if not snippet.endswith('\n'): |
|
|
|
|
ofile.write('\n') |
|
|
|
|
ofile.write('\n') |
|
|
|
|
subprocess.check_call(['git', 'rm', snippetfile]) |
|
|
|
|
subprocess.check_call(['git', 'add', ofilename]) |
|
|
|
|
add_to_sitemap(from_version, to_version) |
|
|
|
|
|
|
|
|
|
if not output_dir: |
|
|
|
|
subprocess.check_call(['git', 'rm', 'markdown/snippets/*.md']) |
|
|
|
|
subprocess.check_call(['git', 'add', output]) |
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
if len(sys.argv) != 3: |
|
|
|
|
print(sys.argv[0], 'from_version to_version') |
|
|
|
|
sys.exit(1) |
|
|
|
|
FROM_VERSION = sys.argv[1] |
|
|
|
|
TO_VERSION = sys.argv[2] |
|
|
|
|
os.chdir('markdown') |
|
|
|
|
generate(FROM_VERSION, TO_VERSION) |
|
|
|
|
parser = argparse.ArgumentParser(description='Generate meson docs') |
|
|
|
|
parser.add_argument('--input-sitemap', default='sitemap.txt') |
|
|
|
|
parser.add_argument('--output-sitemap', default='sitemap.txt') |
|
|
|
|
parser.add_argument('--source-dir', default='.') |
|
|
|
|
parser.add_argument('--output-dir') |
|
|
|
|
|
|
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
|
|
if Path(args.source_dir, 'markdown/snippets').glob('*.md'): |
|
|
|
|
relnotes, to_version = add_to_sitemap(args.input_sitemap, args.output_sitemap) |
|
|
|
|
generate(relnotes, to_version, args.source_dir, args.output_dir) |
|
|
|
|
elif args.input_sitemap != args.output_sitemap: |
|
|
|
|
shutil.copyfile(args.input_sitemap, args.output_sitemap) |
|
|
|
|