From 3e0535066de1a6ce5362780c6a6b092fafe2fb86 Mon Sep 17 00:00:00 2001 From: wangbill Date: Tue, 24 Mar 2026 13:52:37 -0700 Subject: [PATCH 1/2] Fix CHANGELOG line ending preservation to avoid full-file diff --- .github/workflows/prepare-release.yaml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/prepare-release.yaml b/.github/workflows/prepare-release.yaml index 54923eab..e09bd982 100644 --- a/.github/workflows/prepare-release.yaml +++ b/.github/workflows/prepare-release.yaml @@ -150,10 +150,13 @@ jobs: with open(changelog_file, 'r') as f: changes = f.read().strip() - with open('CHANGELOG.md', 'r') as f: + # Read with newline='' to preserve original line endings (CRLF or LF) + with open('CHANGELOG.md', 'r', newline='') as f: content = f.read() - new_section = f'\n## v{version}\n{changes}\n' + # Detect line ending style used in the file + eol = '\r\n' if '\r\n' in content else '\n' + new_section = f'{eol}## v{version}{eol}{changes}{eol}' # Insert the new version section after '## Unreleased' marker = '## Unreleased' @@ -163,17 +166,19 @@ jobs: # Skip any whitespace/newlines after the marker while insert_pos < len(content) and content[insert_pos] in (' ', '\t', '\n', '\r'): # Stop if we hit another section header - if content[insert_pos] == '\n' and insert_pos + 1 < len(content) and content[insert_pos + 1] == '#': + next_char = insert_pos + 1 if content[insert_pos] == '\r' else insert_pos + if content[insert_pos] in ('\n', '\r') and next_char + 1 < len(content) and content[next_char + 1] == '#': break insert_pos += 1 - content = content[:insert_pos] + '\n' + new_section + content[insert_pos:] + content = content[:insert_pos] + eol + new_section + content[insert_pos:] else: # No Unreleased section found, insert at top after title - title_end = content.find('\n', content.find('# Changelog')) + title_end = content.find(eol, content.find('# Changelog')) if title_end != -1: - content = content[:title_end + 1] + '\n## Unreleased\n' + new_section + content[title_end + 1:] + content = content[:title_end + len(eol)] + eol + '## Unreleased' + eol + new_section + content[title_end + len(eol):] - with open('CHANGELOG.md', 'w') as f: + # Write with newline='' to preserve the detected line endings + with open('CHANGELOG.md', 'w', newline='') as f: f.write(content) print(f'Updated CHANGELOG.md with v{version}') From faf5e96057ee1d919a063fc933ea76416fb8e8eb Mon Sep 17 00:00:00 2001 From: wangbill Date: Tue, 24 Mar 2026 14:03:38 -0700 Subject: [PATCH 2/2] Normalize changelog content line endings to match file EOL style --- .github/workflows/prepare-release.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/prepare-release.yaml b/.github/workflows/prepare-release.yaml index e09bd982..e7d340f7 100644 --- a/.github/workflows/prepare-release.yaml +++ b/.github/workflows/prepare-release.yaml @@ -156,6 +156,7 @@ jobs: # Detect line ending style used in the file eol = '\r\n' if '\r\n' in content else '\n' + changes = changes.replace('\r\n', '\n').replace('\n', eol) new_section = f'{eol}## v{version}{eol}{changes}{eol}' # Insert the new version section after '## Unreleased'