From f3f21f1e0cee2f3c8f286f07b632d013c103d85f Mon Sep 17 00:00:00 2001 From: Nemo Date: Wed, 25 May 2022 12:09:14 +0530 Subject: [PATCH] [ci skip] Fix huge release notes --- .gitignore | 3 ++- Makefile | 8 ++++---- src/diff.py | 22 +++++++++++++++++++++- src/release.mako | 7 +++---- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 17dfcb8..78433da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ pup release.md pup.zip -IN*.csv \ No newline at end of file +IN*.csv +notes.md \ No newline at end of file diff --git a/Makefile b/Makefile index 127e29b..16607fc 100644 --- a/Makefile +++ b/Makefile @@ -30,8 +30,8 @@ update: ISIN old: git show HEAD^:ISIN.csv > /tmp/ISIN.csv -release.md: old - python3 src/diff.py > release.md +release-notes: old + python3 src/diff.py -release: release.md - gh release create "$(version)" --notes-file release.md ISIN.csv +release: release-notes + gh release create "$(version)" --notes-file notes.md ISIN.csv release.md diff --git a/src/diff.py b/src/diff.py index ece6e08..befee65 100644 --- a/src/diff.py +++ b/src/diff.py @@ -17,4 +17,24 @@ diff = compare( True ) -print(template.render(added=diff['added'], changed=diff['changed'], removed=diff['removed'])) \ No newline at end of file +contents = template.render(added=diff['added'], changed=diff['changed'], removed=diff['removed']) + +# GitHub supports a maximum limit of 125000 for release notes. +# 124800 = 124000 - 200 for buffer and the warning line +# To get around this, we add a warning if we hit the limit +# and attach a release.md file with the complete notes +if len(contents) >= 125000: + notes = """This file is truncated due to GitHub limitations. +please see the attached `release.md` file for complete notes""" + contents[:124800] +else: + notes = contents + +""" +notes are the viewable notes on the release page on GitHub +while release.md is the attached notes. This is the complete text. +""" +with open('notes.md', 'w') as f: + f.write(notes) + +with open('release.md', 'w') as f: + f.write(contents) \ No newline at end of file diff --git a/src/release.mako b/src/release.mako index 0661a9b..a10ef75 100644 --- a/src/release.mako +++ b/src/release.mako @@ -1,6 +1,5 @@ ## Generates a single diff for a single row, ignoring the Status field -<%def name="singlediff(row)"> -@@ ${row['key']} +<%def name="singlediff(row)">@@ ${row['key']} %for k in row['changes']: %if k != 'Status': -${k}:${row['changes'][k][0]} @@ -19,7 +18,7 @@ ${row['changes']['Description'][1]} %endif -% if len(added) > 0 +% if len(added) > 0:

Additions

The following new ISINs were added: @@ -33,7 +32,7 @@ ISIN|Description|Issuer|Type|Status %endif -% if len(changed) > 0 +% if len(changed) > 0:

Changes

The following ISINs changed their status: