|
| 1 | +# Copyright (c) Lawrence Livermore National Security, LLC and other Ascent |
| 2 | +# Project developers. See top-level LICENSE AND COPYRIGHT files for dates and |
| 3 | +# other details. No copyright assignment is required to contribute to Ascent. |
| 4 | +""" |
| 5 | +file: gen_relnotes_variants_from_changelog.py |
| 6 | +description: |
| 7 | + Release helper -- converts change log entries into text for: |
| 8 | + - the github release entry |
| 9 | + - the sphinx docs release entry |
| 10 | + - the release entry for the llnl open source news github url |
| 11 | +
|
| 12 | +usage: |
| 13 | + python gen_relnotes_variants_from_changelog.py Unreleased |
| 14 | + python gen_relnotes_variants_from_changelog.py 0.5.1 |
| 15 | +
|
| 16 | +note: |
| 17 | + assumes CHANGELOG.md is at ".." |
| 18 | +""" |
| 19 | + |
| 20 | +import os |
| 21 | +import sys |
| 22 | +import datetime |
| 23 | + |
| 24 | +def proc_changelog_rel_id_line(l): |
| 25 | + active_rel = l.split()[1] |
| 26 | + if active_rel.startswith("["): |
| 27 | + active_rel =active_rel[1:-1] |
| 28 | + return active_rel |
| 29 | + |
| 30 | +def timestamp(t=None,sep="_"): |
| 31 | + """ Creates a timestamp that can easily be included in a filename. """ |
| 32 | + if t is None: |
| 33 | + t = datetime.datetime.now() |
| 34 | + #sargs = (t.year,t.month,t.day,t.hour,t.minute,t.second) |
| 35 | + #sbase = "".join(["%04d",sep,"%02d",sep,"%02d",sep,"%02d",sep,"%02d",sep,"%02d"]) |
| 36 | + sargs = (t.year,t.month,t.day) |
| 37 | + sbase = "".join(["%04d",sep,"%02d",sep,"%02d"]) |
| 38 | + return sbase % sargs |
| 39 | + |
| 40 | +def ascent_blurb(): |
| 41 | + return "[Ascent](https://github.com/Alpine-DAV/ascent) is flyweight in situ visualization and analysis runtime for multi-physics HPC simulations" |
| 42 | + |
| 43 | +def gen_llnl_news_entry(release_id,src): |
| 44 | + txt = "---\n" |
| 45 | + txt += 'title: "Ascent {0} Released"\n'.format(release_id) |
| 46 | + txt += 'categories: release\n' |
| 47 | + txt += "---\n\n" |
| 48 | + txt += ascent_blurb() |
| 49 | + txt += "\n" |
| 50 | + txt += "\n\n" |
| 51 | + txt += "Learn more:\n" |
| 52 | + txt += "- [Release notes](https://github.com/Alpine-DAV/ascent/releases/tag/v{0})\n".format(release_id) |
| 53 | + txt += "- [Documentation](http://ascent.readthedocs.io/)\n" |
| 54 | + txt += "- [GitHub repo](https://github.com/Alpine-DAV/ascent)\n" |
| 55 | + return txt |
| 56 | + |
| 57 | +def gen_sphinx_entry(release_id,src): |
| 58 | + txt = "v{0}\n".format(release_id) |
| 59 | + txt += "---------------------------------\n\n" |
| 60 | + txt += "* `Source Tarball <https://github.com/Alpine-DAV/ascent/releases/download/v{0}/ascent-v{0}-src-with-blt.tar.gz>`__\n\n".format(release_id) |
| 61 | + txt += "* Docker Containers\n" |
| 62 | + txt += " * ``alpinedav/ascent:{0}``\n".format(release_id) |
| 63 | + txt += " * ``alpinedav/ascent-jupyter:{0}``\n\n".format(release_id) |
| 64 | + txt += "Highlights\n" |
| 65 | + txt += "++++++++++++++++++++++++++++++++++++\n\n" |
| 66 | + txt += "(Extracted from Ascent's :download:`Changelog <../../../CHANGELOG.md>`)\n\n" |
| 67 | + sub_open = False |
| 68 | + active_rel = "" |
| 69 | + for l in src.split("\n"): |
| 70 | + if l.startswith("## "): |
| 71 | + sub_open = False |
| 72 | + active_rel = proc_changelog_rel_id_line(l) |
| 73 | + #print(active_rel) |
| 74 | + #print("BEGIN RELEASE {0}",l) |
| 75 | + elif l.startswith("### ") and active_rel == release_id: |
| 76 | + sub_open = True |
| 77 | + sub_title = l[3:].strip() |
| 78 | + txt += "\n"+ sub_title +"\n" |
| 79 | + txt += "~" * len(sub_title) + "\n\n" |
| 80 | + elif l.startswith("#### ") and active_rel == release_id: |
| 81 | + sub_open = True |
| 82 | + sub_title = l[4:].strip() |
| 83 | + txt += "\n* **" + sub_title +"**\n\n" |
| 84 | + elif sub_open and active_rel == release_id and l.startswith("-"): |
| 85 | + txt += " * " + sphinx_translate_ticks(l[1:].strip())+"\n" |
| 86 | + return txt |
| 87 | + |
| 88 | +def sphinx_translate_ticks(l): |
| 89 | + # todo, we may need to do a more robust job of this .. |
| 90 | + return l.replace("`","``") |
| 91 | + |
| 92 | +def gen_github_entry(release_id,src): |
| 93 | + txt = "# {0} Release Highlights\n\n".format(release_id) |
| 94 | + txt += "(adapted from Ascent's [Changelog](https://github.com/Alpine-DAV/ascent/blob/develop/CHANGELOG.md)\n" |
| 95 | + sub_open = False |
| 96 | + active_rel = "" |
| 97 | + for l in src.split("\n"): |
| 98 | + if l.startswith("## "): |
| 99 | + sub_open = False |
| 100 | + active_rel = proc_changelog_rel_id_line(l) |
| 101 | + #print(active_rel) |
| 102 | + #print("BEGIN RELEASE {0}",l) |
| 103 | + elif l.startswith("### ") and active_rel == release_id: |
| 104 | + sub_open = True |
| 105 | + txt += l +"\n" |
| 106 | + print("BEGIN SUB {0}",l) |
| 107 | + elif sub_open and active_rel == release_id: |
| 108 | + txt += l +"\n" |
| 109 | + txt += "## Docker Containers\n" |
| 110 | + txt += " - **alpinedav/ascent:{0}**\n".format(release_id) |
| 111 | + txt += " - **alpinedav/ascent-jupyter:{0}**\n".format(release_id) |
| 112 | + return txt |
| 113 | + |
| 114 | +def main(): |
| 115 | + release_id = "Unreleased" |
| 116 | + if len(sys.argv) > 1: |
| 117 | + release_id = sys.argv[1] |
| 118 | + src = open("../CHANGELOG.md").read() |
| 119 | + print("----GITHUB_ENTRY----BEG----") |
| 120 | + print(gen_github_entry(release_id,src)) |
| 121 | + print("----GITHUB_ENTRY----END----") |
| 122 | + print("") |
| 123 | + print("----SPHINX_ENTRY----BEG----") |
| 124 | + print(gen_sphinx_entry(release_id,src)) |
| 125 | + print("----SPHINX_ENTRY----END----") |
| 126 | + print("") |
| 127 | + print("----LLNLNEWS_ENTRY----BEG----") |
| 128 | + ntxt = gen_llnl_news_entry(release_id,src) |
| 129 | + print(ntxt) |
| 130 | + print("----LLNLNEWS_ENTRY----END----") |
| 131 | + nfile = timestamp(sep="-") + "-ascent.md" |
| 132 | + print("[saving llnl news entry to: {0}]".format(nfile)) |
| 133 | + open(nfile,"w").write(ntxt) |
| 134 | + |
| 135 | + |
| 136 | +if __name__ == "__main__": |
| 137 | + main() |
| 138 | + |
0 commit comments