Skip to content

Commit 7f6f212

Browse files
committed
Link the full report in the release notes coverage section
1 parent 6929307 commit 7f6f212

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

‎README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ https://img.shields.io/endpoint?url=https://openswiftuiproject.github.io/Interfa
285285

286286
To add a release summary to GitHub release notes, run
287287
[`Scripts/update_release_notes.py`](Scripts/update_release_notes.py). It writes
288-
a table between `<!-- interface-coverage:start -->` and
289-
`<!-- interface-coverage:end -->` markers, and replaces that table when it runs
290-
again. Use `--dry-run` to print the result without editing the release.
288+
an `## Interface Coverage` section between `<!-- interface-coverage:start -->`
289+
and `<!-- interface-coverage:end -->` markers, with a link to the version's full
290+
report. When it runs again, it replaces that section in place. Without the
291+
markers, it adds the section at the end of the notes. Use `--dry-run` to print
292+
the result without editing the release.
291293

292294
```sh
293295
python3 Tools/InterfaceCoverage/Scripts/update_release_notes.py --version 0.23.1 \

‎Scripts/update_release_notes.py‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"""Add the interface coverage of a release to its release notes.
33
44
The script reads `summary/<project>/<version>.json` from the coverage site and
5-
writes a Markdown table between two markers in the release notes. Running it
6-
again replaces the table, so it is safe to repeat. It uses `gh` to read and edit
5+
writes an `## Interface Coverage` section between two markers. Running it again
6+
replaces the section in place, so it is safe to repeat. Without the markers, the
7+
section is added at the end of the release notes. It uses `gh` to read and edit
78
the release, which needs a token with write access to the repository contents.
89
"""
910

@@ -12,6 +13,7 @@
1213
import subprocess
1314
import time
1415
import urllib.error
16+
import urllib.parse
1517
import urllib.request
1618

1719
START = '<!-- interface-coverage:start -->'
@@ -42,8 +44,14 @@ def section(summary, baselines, profile):
4244
rows = list(dict.fromkeys(item['baseline'] for item in results))
4345
if baselines:
4446
rows = [baseline for baseline in baselines if baseline in rows]
45-
lines = [START, '### Interface coverage', '',
46-
f"{summary['note']} Coverage is not a measure of completed behavior.", '',
47+
# Summary links are absolute when the site was generated with a site URL.
48+
site = results[0]['url'].split('index.html?', 1)[0]
49+
if not site.startswith(('http://', 'https://')):
50+
raise SystemExit('The summary has relative links. Generate the site with a site URL.')
51+
query = urllib.parse.urlencode(dict(project=summary['project'], version=summary['version']),
52+
quote_via=urllib.parse.quote)
53+
lines = [START, '## Interface Coverage', '',
54+
f"Full report: [{summary['project']} {summary['version']}]({site}index.html?{query})", '',
4755
'| Baseline | ' + ' | '.join(scopes) + ' |', '| --- | ' + ' | '.join('---:' for _ in scopes) + ' |']
4856
for baseline in rows:
4957
cells = []
@@ -58,6 +66,14 @@ def section(summary, baselines, profile):
5866
return '\n'.join(lines + [END])
5967

6068

69+
def replacing_section(body, block):
70+
"""Replaces the section between the markers, or adds it at the end of the notes."""
71+
if START in body and END in body:
72+
before, rest = body.split(START, 1)
73+
return before + block + rest.split(END, 1)[1]
74+
return f'{body}\n\n{block}' if body else block
75+
76+
6177
def main():
6278
parser = argparse.ArgumentParser(description=__doc__.split('\n\n')[0])
6379
parser.add_argument('--repository', default='OpenSwiftUIProject/OpenSwiftUI')
@@ -75,11 +91,7 @@ def main():
7591
block = section(summary, arguments.baseline, arguments.profile)
7692
body = subprocess.check_output(['gh', 'release', 'view', arguments.version, '--repo', arguments.repository,
7793
'--json', 'body', '--jq', '.body'], text=True).rstrip('\n')
78-
if START in body and END in body:
79-
before, rest = body.split(START, 1)
80-
body = before + block + rest.split(END, 1)[1]
81-
else:
82-
body = f'{body}\n\n{block}' if body else block
94+
body = replacing_section(body, block)
8395
if arguments.dry_run:
8496
print(body)
8597
return

0 commit comments

Comments
 (0)