diff --git a/.github/workflows/update-releasenotes.yml b/.github/workflows/update-releasenotes.yml index 64b638d1f..3760e8ac3 100644 --- a/.github/workflows/update-releasenotes.yml +++ b/.github/workflows/update-releasenotes.yml @@ -64,64 +64,64 @@ jobs: VERSION_HEADER="# NuGet Version ${CURRENT_VERSION}" python3 - <<'PYEOF' -import os, sys - -file_path = os.environ['FILE'] -ver_header = os.environ['VERSION_HEADER'] -section = os.environ['SECTION'] -pr_number = os.environ['PR_NUMBER'] -pr_title = os.environ['PR_TITLE'] -entry = f"#{pr_number} {pr_title}
" - -with open(file_path, 'r') as f: - content = f.read() - lines = content.splitlines(keepends=True) - -# Find the version block and insert the entry -result = [] -in_version_block = False -section_found = False -inserted = False - -for i, line in enumerate(lines): - stripped = line.rstrip('\n') - - if stripped == ver_header: - in_version_block = True - result.append(line) - continue - - if in_version_block and stripped.startswith('# NuGet Version ') and stripped != ver_header: - # Reached next version block without finding/creating section - if not inserted: - result.append('\n' + section + ':\n\n' + entry + '\n\n') - inserted = True - in_version_block = False - result.append(line) - continue - - if in_version_block and not inserted and stripped == section + ':': - section_found = True - result.append(line) - continue - - if section_found and not inserted: - # Insert after the blank line following the section heading - if stripped == '': - result.append(line) - result.append(entry + '\n') - inserted = True - continue - - result.append(line) - -# If we reached EOF still inside the version block -if in_version_block and not inserted: - result.append('\n' + section + ':\n\n' + entry + '\n') - -with open(file_path, 'w') as f: - f.writelines(result) -PYEOF + import os, sys + + file_path = os.environ['FILE'] + ver_header = os.environ['VERSION_HEADER'] + section = os.environ['SECTION'] + pr_number = os.environ['PR_NUMBER'] + pr_title = os.environ['PR_TITLE'] + entry = f"#{pr_number} {pr_title}
" + + with open(file_path, 'r') as f: + content = f.read() + lines = content.splitlines(keepends=True) + + # Find the version block and insert the entry + result = [] + in_version_block = False + section_found = False + inserted = False + + for i, line in enumerate(lines): + stripped = line.rstrip('\n') + + if stripped == ver_header: + in_version_block = True + result.append(line) + continue + + if in_version_block and stripped.startswith('# NuGet Version ') and stripped != ver_header: + # Reached next version block without finding/creating section + if not inserted: + result.append('\n' + section + ':\n\n' + entry + '\n\n') + inserted = True + in_version_block = False + result.append(line) + continue + + if in_version_block and not inserted and stripped == section + ':': + section_found = True + result.append(line) + continue + + if section_found and not inserted: + # Insert after the blank line following the section heading + if stripped == '': + result.append(line) + result.append(entry + '\n') + inserted = True + continue + + result.append(line) + + # If we reached EOF still inside the version block + if in_version_block and not inserted: + result.append('\n' + section + ':\n\n' + entry + '\n') + + with open(file_path, 'w') as f: + f.writelines(result) + PYEOF - name: Commit and push shell: bash