Skip to content

Commit

Permalink
Refined the changelog script to only update the head of the log under…
Browse files Browse the repository at this point in the history
… normal cases
  • Loading branch information
JohnVidler committed Nov 6, 2023
1 parent e73235f commit c611445
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 22 deletions.
101 changes: 87 additions & 14 deletions .github/tools/gitchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
2 changes: 1 addition & 1 deletion .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
9 changes: 2 additions & 7 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down

0 comments on commit c611445

Please sign in to comment.