Files
yoga/set-version.py
Nick Gerleman c18e2566a0 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
2023-07-28 09:48:07 -07:00

38 lines
973 B
Python
Executable File

#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import re
import sys
os.chdir(os.path.dirname(__file__))
if len(sys.argv) != 2:
print("usage: ./set-version <version>", file=sys.stderr)
sys.exit(1)
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())
f.seek(0)
f.truncate()
f.write(new_contents)
with open("Yoga.podspec", "r+") as f:
new_contents = re.sub(
r"spec\.version = '.*'", f"spec.version = '{version}'", f.read()
)
f.seek(0)
f.truncate()
f.write(new_contents)