Skip to content

Commit b564ea3

Browse files
authored
Add tools~/upgrade-version.py (#335)
## Description of Changes I'm tired of messing up version updates. I "vibecoded" a script to do it. ## API - [ ] This is an API breaking change to the SDK No. No changes to runtime code. ## Requires SpacetimeDB PRs None ## Testsuite SpacetimeDB branch name: master ## Testing ``` $ python3 tools~/update-version.py 1.1.1 Updated: ./SpacetimeDB.ClientSDK.csproj Updated: ./tests~/tests.csproj Updated: ./examples~/regression-tests/server/StdbModule.csproj Updated: ./examples~/regression-tests/client/client.csproj Updated: ./examples~/quickstart-chat/server/StdbModule.csproj Updated: ./examples~/quickstart-chat/client/client.csproj Updated version in package.json to 1.1.1 $ git diff -U1 diff --git a/SpacetimeDB.ClientSDK.csproj b/SpacetimeDB.ClientSDK.csproj index 5248df6..b3ca7e8 100644 --- a/SpacetimeDB.ClientSDK.csproj +++ b/SpacetimeDB.ClientSDK.csproj @@ -18,4 +18,4 @@ <RepositoryUrl>https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk</RepositoryUrl> - <AssemblyVersion>1.2.1</AssemblyVersion> - <Version>1.2.1</Version> + <AssemblyVersion>1.1.1</AssemblyVersion> + <Version>1.1.1</Version> <DefaultItemExcludes>$(DefaultItemExcludes);*~/**</DefaultItemExcludes> @@ -27,3 +27,3 @@ <ItemGroup> - <PackageReference Include="SpacetimeDB.BSATN.Runtime" Version="1.2.*" /> + <PackageReference Include="SpacetimeDB.BSATN.Runtime" Version="1.1.*" /> diff --git a/examples~/quickstart-chat/server/StdbModule.csproj b/examples~/quickstart-chat/server/StdbModule.csproj index 0513a81..f290d22 100644 --- a/examples~/quickstart-chat/server/StdbModule.csproj +++ b/examples~/quickstart-chat/server/StdbModule.csproj @@ -16,3 +16,3 @@ <ItemGroup> - <PackageReference Include="SpacetimeDB.Runtime" Version="1.2.*" /> + <PackageReference Include="SpacetimeDB.Runtime" Version="1.1.*" /> </ItemGroup> diff --git a/examples~/regression-tests/server/StdbModule.csproj b/examples~/regression-tests/server/StdbModule.csproj index c6b1cba..3284863 100644 --- a/examples~/regression-tests/server/StdbModule.csproj +++ b/examples~/regression-tests/server/StdbModule.csproj @@ -10,3 +10,3 @@ <ItemGroup> - <PackageReference Include="SpacetimeDB.Runtime" Version="1.2.*" /> + <PackageReference Include="SpacetimeDB.Runtime" Version="1.1.*" /> </ItemGroup> diff --git a/package.json b/package.json index 7839151..a627246 100644 --- a/package.json +++ b/package.json @@ -3,3 +3,3 @@ "displayName": "SpacetimeDB SDK", - "version": "1.2.1", + "version": "1.1.1", "description": "The SpacetimeDB Client SDK is a software development kit (SDK) designed to interact with and manipulate SpacetimeDB modules..", ``` --------- Co-authored-by: Zeke Foppa <[email protected]>
1 parent f74705a commit b564ea3

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

tools~/upgrade-version.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import os
2+
import re
3+
import sys
4+
import json
5+
import argparse
6+
7+
def update_csproj_file(path, version):
8+
with open(path, 'r', encoding='utf-8') as f:
9+
lines = f.readlines()
10+
11+
updated_lines = []
12+
version_prefix = '.'.join(version.split('.')[:2]) + '.*'
13+
version_tag_written = set()
14+
15+
for i, line in enumerate(lines):
16+
# Update PackageReference for SpacetimeDB.*
17+
updated_line = re.sub(
18+
r'(<PackageReference[^>]*Include="SpacetimeDB\.[^"]*"[^>]*Version=")[^"]*(")',
19+
rf'\g<1>{version_prefix}\g<2>',
20+
line
21+
)
22+
23+
for tag in ('Version', 'AssemblyVersion'):
24+
if re.search(rf'<{tag}>.*</{tag}>', updated_line.strip()):
25+
updated_line = re.sub(
26+
rf'(<{tag}>).*(</{tag}>)',
27+
rf'\g<1>{version}\g<2>',
28+
updated_line
29+
)
30+
version_tag_written.add(tag)
31+
32+
updated_lines.append(updated_line)
33+
34+
with open(path, 'w', encoding='utf-8') as f:
35+
f.writelines(updated_lines)
36+
print(f"Updated: {path}")
37+
38+
def update_all_csproj_files(version):
39+
for root, _, files in os.walk('.'):
40+
for file in files:
41+
if file.endswith('.csproj'):
42+
update_csproj_file(os.path.join(root, file), version)
43+
44+
def update_package_json(version):
45+
path = 'package.json'
46+
if os.path.exists(path):
47+
with open(path, 'r', encoding='utf-8') as f:
48+
data = json.load(f)
49+
data['version'] = version
50+
with open(path, 'w', encoding='utf-8') as f:
51+
json.dump(data, f, indent=2)
52+
f.write('\n') # ensure trailing newline
53+
print(f"Updated version in {path} to {version}")
54+
else:
55+
print("package.json not found.")
56+
57+
def main():
58+
parser = argparse.ArgumentParser(
59+
description='Update version numbers in .csproj files and package.json',
60+
formatter_class=argparse.RawDescriptionHelpFormatter,
61+
epilog="""
62+
Examples:
63+
python upgrade-version.py 1.2.3
64+
python upgrade-version.py --version 1.2.3
65+
"""
66+
)
67+
parser.add_argument(
68+
'version',
69+
help='Version number to set (e.g., 1.2.3)'
70+
)
71+
72+
args = parser.parse_args()
73+
74+
update_all_csproj_files(args.version)
75+
update_package_json(args.version)
76+
77+
if __name__ == '__main__':
78+
main()

0 commit comments

Comments
 (0)