diff --git a/.github/tools/gitchanges.py b/.github/tools/gitchanges.py index 6282159a..a39af801 100755 --- a/.github/tools/gitchanges.py +++ b/.github/tools/gitchanges.py @@ -24,7 +24,25 @@ import os import json +import re from natsort import natsorted +from optparse import OptionParser + +outBuffer = [] +def output( data, forcePrint = False ): + outBuffer.append( data ) + + if forcePrint: + print( data ) + +def writeOutput(): + if options.outFile != None: + with open( options.outFile, mode="w", encoding="utf-8" ) as out: + for line in outBuffer: + out.write( f"{line}\n" ) + else: + for line in outBuffer: + print( line ) def getTags(): tags = os.popen('git -P tag').read().strip().splitlines() @@ -42,24 +60,79 @@ def getRepoURL(): def printLibraryLinks(): config = json.loads(open( 'target-locked.json' ).read()) for lib in config['libraries']: - print( F" - {lib['name']} = {lib['url']}/tree/{lib['branch']}" ) - -print( '# Changelog' ) -print( '*This file is autogenerated and will be overwritten on the next tag.*' ) -print( '' ) -print( 'For official release notes, please see Releases.md' ) -print( '' ) -print( 'The current tag uses the following library versions:' ) -printLibraryLinks() -print( '' ) + output( F" - {lib['name']} = {lib['url']}/tree/{lib['branch']}" ) tags = getTags() + +defaultTag = "v0.0.1" +if( len(tags) > 0 ): + defaultTag = tags[0] + +parser = OptionParser() +parser.add_option( "--input", dest="inFile", help="read existing changelog from FILE", metavar="FILE" ) +parser.add_option( "--output", dest="outFile", help="write updated changelog to FILE", metavar="FILE" ) +parser.add_option( "--tag", dest="tag", help="Force this to be the tag to update to", default=defaultTag ) + +(options, args) = parser.parse_args() + +if options.tag not in tags: + print( f"No such tag '{options.tag}' found, unable to continue." ) + exit( 1 ) + +if options.outFile == None: + options.outFile = options.inFile + +output( '# Changelog' ) +output( '*The head of this file is autogenerated and will be overwritten on the next tag.*' ) +output( '' ) +output( 'For official release notes, please see Releases.md' ) +output( '' ) +output( 'The current tag uses the following library versions:' ) +printLibraryLinks() +output( '' ) + +if options.inFile != None: + with open( options.inFile, mode="r", encoding="utf-8" ) as input: + lastTag = None + + url = getRepoURL() + + try: + for line in input.readlines(): + line = line.replace( "\n", "" ) + if lastTag == None: + if line.startswith( "##" ): + matches = re.search( "\[(v.+)\]", line ) + lastTag = matches.group(1) + + if lastTag == options.tag: + print( "Nothing to do, Stop." ) + exit( 0 ) + + logURL = f"{url}compare/{lastTag}...{options.tag}" + + output( f"## [{options.tag}]({logURL})", forcePrint=True ) + output( '', forcePrint=True ) + output( getCommitsBetween( lastTag, options.tag ), forcePrint=True ) + output( '', forcePrint=True ) + output( line ) + else: + output( line ) + except: + exit( 1 ) + + writeOutput() + exit( 0 ) + for i in range(0, len(tags)-1): + output( tags[i] ) url = getRepoURL() logURL = f"{url}compare/{tags[i+1]}...{tags[i]}" treeURL = f"{url}tree/{tags[i]}" - print('') - print(f"## [{tags[i]}]({logURL})" ) - print('') - print( getCommitsBetween( tags[i+1], tags[i] ) ) + output('') + output(f"## [{tags[i]}]({logURL})" ) + output('') + output( getCommitsBetween( tags[i+1], tags[i] ) ) + +writeOutput() \ No newline at end of file diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml index 1e746925..b417a216 100644 --- a/.github/workflows/update-changelog.yml +++ b/.github/workflows/update-changelog.yml @@ -26,7 +26,7 @@ jobs: - name: Generate a new Changelog run: | git checkout master - python3 .github/tools/gitchanges.py > Changelog.md + python3 .github/tools/gitchanges.py --input Changelog.md - name: Commit the new Changelog run: | diff --git a/Changelog.md b/Changelog.md index cf8cacc1..6ac440d2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,5 @@ # Changelog -*This file is autogenerated and will be overwritten on the next tag.* +*The head of this file is autogenerated and will be overwritten on the next tag.* For official release notes, please see Releases.md @@ -8,19 +8,14 @@ The current tag uses the following library versions: - codal-nrf52 = https://github.com/lancaster-university/codal-nrf52/tree/0643733703b4f8f788af81a996f40d1f1a1527bc - codal-microbit-nrf5sdk = https://github.com/microbit-foundation/codal-microbit-nrf5sdk/tree/5714cbe338c3544793bbb841a7ae81708a3ffae1 - ## [v0.2.63](https://github.com/lancaster-university/codal-microbit-v2/compare/v0.2.62...v0.2.63) Dr John Vidler (9): - Removed deactivateLevelSPL entirely as per codal-microbit-v2 issue #222 - Fix for the microphone failing to wake after a sleep event - - Commented out a temporary alias for the face/logo touch button, staged for removal - - Revert for the face alias removal, for v0.2.63 release - - Snapshot v0.2.63 - - Reverted the power saving for the LED Matrix to avoid strange issues with Pins. - Merge branch 'master' of ssh://github.com/lancaster-university/codal-microbit-v2 - - Snapshot v0.2.64 - Updated target-locked with the corrected tag version + - Snapshot v0.2.64 Github Actions (3): - Updated the Changelog