-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-version.py
More file actions
214 lines (186 loc) · 6.72 KB
/
update-version.py
File metadata and controls
214 lines (186 loc) · 6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env python3
"""
Update version across all components of pdfdiff-turbo project.
This script is cross-platform and works on Windows, Linux, and macOS.
Usage: python update-version.py <version>
Example: python update-version.py 1.1.0
"""
import sys
import re
import json
from pathlib import Path
def validate_version(version: str) -> bool:
"""Validate semantic version format."""
pattern = r'^\d+\.\d+\.\d+$'
return bool(re.match(pattern, version))
def update_file(file_path: Path, pattern: str, replacement: str, description: str):
"""Update a file with regex pattern replacement."""
if not file_path.exists():
print(f" ⚠ Skipping {file_path} (not found)")
return
content = file_path.read_text(encoding='utf-8')
updated_content = re.sub(pattern, replacement, content)
if content != updated_content:
file_path.write_text(updated_content, encoding='utf-8')
print(f" ✓ Updated {description}")
else:
print(f" ⚠ No changes needed for {description}")
def update_json_version(file_path: Path, new_version: str, description: str):
"""Update version in a JSON file."""
if not file_path.exists():
print(f" ⚠ Skipping {file_path} (not found)")
return
data = json.loads(file_path.read_text(encoding='utf-8'))
data['version'] = new_version
file_path.write_text(json.dumps(data, indent=2) + '\n', encoding='utf-8')
print(f" ✓ Updated {description}")
def main():
if len(sys.argv) != 2:
print("❌ Error: Version number required")
print("Usage: python update-version.py <version>")
print("Example: python update-version.py 1.1.0")
sys.exit(1)
new_version = sys.argv[1]
if not validate_version(new_version):
print("❌ Error: Version must be in format MAJOR.MINOR.PATCH (e.g., 1.2.3)")
sys.exit(1)
print(f"🔄 Updating pdfdiff-turbo to version {new_version}")
# Get project root (script location)
root = Path(__file__).parent
# Update root VERSION file
version_file = root / "VERSION"
version_file.write_text(new_version, encoding='utf-8')
print(f" ✓ Updated VERSION")
# Update package.json files
update_json_version(
root / "admin" / "package.json",
new_version,
"admin/package.json"
)
update_json_version(
root / "viewer" / "package.json",
new_version,
"viewer/package.json"
)
update_json_version(
root / "admin" / "package-lock.json",
new_version,
"admin/package-lock.json"
)
update_json_version(
root / "viewer" / "package-lock.json",
new_version,
"viewer/package-lock.json"
)
# Update environment.ts files
update_file(
root / "admin" / "src" / "environments" / "environment.ts",
r"version: '[^']*'",
f"version: '{new_version}'",
"admin/src/environments/environment.ts"
)
update_file(
root / "viewer" / "src" / "environments" / "environment.ts",
r"version: '[^']*'",
f"version: '{new_version}'",
"viewer/src/environments/environment.ts"
)
# Update docker-compose.yml
update_file(
root / "docker-compose.yml",
r'pdfdiff-turbo-(api|worker|beat|flower|viewer|admin):\d+\.\d+\.\d+',
f'pdfdiff-turbo-\\1:{new_version}',
"docker-compose.yml image tags"
)
# Update k8s base image tags
update_file(
root / "k8s" / "base" / "api.yaml",
r'(?P<prefix>[^\s"\']*/)?pdfdiff-turbo-api:\d+\.\d+\.\d+',
f'\\g<prefix>pdfdiff-turbo-api:{new_version}',
"k8s/base/api.yaml image tag"
)
update_file(
root / "k8s" / "base" / "worker.yaml",
r'(?P<prefix>[^\s"\']*/)?pdfdiff-turbo-worker:\d+\.\d+\.\d+',
f'\\g<prefix>pdfdiff-turbo-worker:{new_version}',
"k8s/base/worker.yaml image tag"
)
update_file(
root / "k8s" / "base" / "beat.yaml",
r'(?P<prefix>[^\s"\']*/)?pdfdiff-turbo-beat:\d+\.\d+\.\d+',
f'\\g<prefix>pdfdiff-turbo-beat:{new_version}',
"k8s/base/beat.yaml image tag"
)
update_file(
root / "k8s" / "base" / "flower.yaml",
r'(?P<prefix>[^\s"\']*/)?pdfdiff-turbo-flower:\d+\.\d+\.\d+',
f'\\g<prefix>pdfdiff-turbo-flower:{new_version}',
"k8s/base/flower.yaml image tag"
)
update_file(
root / "k8s" / "base" / "viewer.yaml",
r'(?P<prefix>[^\s"\']*/)?pdfdiff-turbo-viewer:\d+\.\d+\.\d+',
f'\\g<prefix>pdfdiff-turbo-viewer:{new_version}',
"k8s/base/viewer.yaml image tag"
)
update_file(
root / "k8s" / "base" / "admin.yaml",
r'(?P<prefix>[^\s"\']*/)?pdfdiff-turbo-admin:\d+\.\d+\.\d+',
f'\\g<prefix>pdfdiff-turbo-admin:{new_version}',
"k8s/base/admin.yaml image tag"
)
# Update k8s base image tags
update_file(
root / "k8s" / "base" / "api.yaml",
r'pdfdiff-turbo-api:\d+\.\d+\.\d+',
f'pdfdiff-turbo-api:{new_version}',
"k8s/base/api.yaml image tag"
)
update_file(
root / "k8s" / "base" / "worker.yaml",
r'pdfdiff-turbo-worker:\d+\.\d+\.\d+',
f'pdfdiff-turbo-worker:{new_version}',
"k8s/base/worker.yaml image tag"
)
update_file(
root / "k8s" / "base" / "flower.yaml",
r'pdfdiff-turbo-flower:\d+\.\d+\.\d+',
f'pdfdiff-turbo-flower:{new_version}',
"k8s/base/flower.yaml image tag"
)
update_file(
root / "k8s" / "base" / "viewer.yaml",
r'pdfdiff-turbo-viewer:\d+\.\d+\.\d+',
f'pdfdiff-turbo-viewer:{new_version}',
"k8s/base/viewer.yaml image tag"
)
update_file(
root / "k8s" / "base" / "admin.yaml",
r'pdfdiff-turbo-admin:\d+\.\d+\.\d+',
f'pdfdiff-turbo-admin:{new_version}',
"k8s/base/admin.yaml image tag"
)
# Update k8s local overlay tags
update_file(
root / "k8s" / "overlays" / "local" / "kustomization.yaml",
r'newTag:\s*\d+\.\d+\.\d+',
f'newTag: {new_version}',
"k8s/overlays/local/kustomization.yaml newTag entries"
)
# Update k8s prod overlay tags
update_file(
root / "k8s" / "overlays" / "prod" / "kustomization.yaml",
r'newTag:\s*\d+\.\d+\.\d+',
f'newTag: {new_version}',
"k8s/overlays/prod/kustomization.yaml newTag entries"
)
print()
print(f"✅ Version updated to {new_version} successfully!")
print()
print("Next steps:")
print(f" 1. Review changes: git diff")
print(f" 2. Commit: git commit -am 'chore: bump version to {new_version}'")
print(f" 3. Tag: git tag v{new_version}")
print(f" 4. Push: git push && git push --tags")
if __name__ == "__main__":
main()