Fix set-version script corrupting files when new version is shorter than old one

Summary: We were leaving the last bits of the previous string around if writing a new file which is shorter. See 30b697d3fe for an example.

Reviewed By: cortinico

Differential Revision: D47824696

fbshipit-source-id: 82ebafd9cd1720752cbc62ea93c5b9362395d5c8
This commit is contained in:
Nick Gerleman
2023-07-28 09:48:07 -07:00
committed by Facebook GitHub Bot
parent 44507ec62e
commit c18e2566a0

View File

@@ -19,13 +19,13 @@ version = sys.argv[1]
with open("gradle.properties", "r+") as f:
new_contents = re.sub(r"VERSION_NAME=.*", f"VERSION_NAME={version}", f.read())
f.seek(0)
f.truncate()
f.write(new_contents)
with open("javascript/package.json", "r+") as f:
new_contents = re.sub(r'"version": ".*",', f'"version": "{version}",', f.read())
print(new_contents)
f.seek(0)
f.truncate()
f.write(new_contents)
with open("Yoga.podspec", "r+") as f:
@@ -33,4 +33,5 @@ with open("Yoga.podspec", "r+") as f:
r"spec\.version = '.*'", f"spec.version = '{version}'", f.read()
)
f.seek(0)
f.truncate()
f.write(new_contents)