Skip to content

Commit

Permalink
Fix for line terminators on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Jan 16, 2024
1 parent 4ad0a4a commit 0290026
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions scripts/version-patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@

def replace_version(filename, new_text):
pattern = r'(Current : constant String := "[^+]+\+)([^"]*)(";)'
with open(filename, 'r') as file:
with open(filename, 'rb') as file:
content = file.read()

# Depending on the context in which this is run, there may be mix-ups with
# line terminators between the environment detected, github runner, etc...
# So just keep them as they are and that should always work.
content = content.decode()

new_content = re.sub(pattern, r'\g<1>' + new_text + r'\3', content)

if new_content == content:
Expand All @@ -16,8 +21,10 @@ def replace_version(filename, new_text):
else:
print(f"WARNING: failed to update version in {filename}")
else:
with open(filename, 'w') as file:
file.write(new_content)
# Ensure the content line terminators are not changed
with open(filename, 'wb') as file:
file.write(new_content.encode())


# If a flag exists, skip any updating, just print a message and exit
if "ALR_VERSION_DONT_PATCH" in os.environ:
Expand Down

0 comments on commit 0290026

Please sign in to comment.