Skip to content

Commit 46221c0

Browse files
committed
Check for changes applied on post-release steps
easier to spot if something did not work
1 parent 31cc0c7 commit 46221c0

File tree

1 file changed

+57
-18
lines changed

1 file changed

+57
-18
lines changed

scripts/release_helper/post_release_main.py

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import annotations
33

44
import re
5+
import sys
56
from pathlib import Path
67

78
from graphdatascience.semantic_version.semantic_version import SemanticVersion
@@ -85,8 +86,12 @@ def update_version_py(new_version: PythonLibraryVersion) -> None:
8586

8687
updated = re.sub(VERSION_REGEX, f'__version__ = "{new_version.major_minor()}"', content)
8788

89+
if updated == content:
90+
print(f"☑️ No changes needed for {VERSION_FILE}")
91+
return
92+
8893
VERSION_FILE.write_text(updated)
89-
print(f"✅ Updated {VERSION_FILE} to version {new_version}")
94+
print(f"✅ Updated {VERSION_FILE.relative_to(REPO_ROOT)} to version {new_version}")
9095

9196

9297
def update_changelog(new_version: PythonLibraryVersion) -> None:
@@ -95,8 +100,11 @@ def update_changelog(new_version: PythonLibraryVersion) -> None:
95100
template = Path(__file__).parent / "changelog.template"
96101
new_changelog_body = template.read_text().replace("<VERSION>", str(new_version))
97102

98-
changelog_file.write_text(new_changelog_body)
103+
if changelog_file.read_text() == new_changelog_body:
104+
print(f"☑️ No changes needed for {changelog_file.relative_to(REPO_ROOT)}")
105+
return
99106

107+
changelog_file.write_text(new_changelog_body)
100108
print(f"✅ Updated {changelog_file.relative_to(REPO_ROOT)} for version {new_version}")
101109

102110

@@ -107,14 +115,24 @@ def update_publish_yml(released_version: PythonLibraryVersion, next_version: Pyt
107115
# Extract major.minor from released version
108116
new_branch = f"{released_version.major_minor()}"
109117

118+
def update_branches(branches: str) -> str:
119+
if new_branch in branches:
120+
return branches
121+
else:
122+
return f"{branches}, '{new_branch}'"
123+
110124
# Update branches list
111-
updated = re.sub(r"(branches:\s*\[)([^\]]*)", lambda m: f"{m.group(1)}{m.group(2)}, '{new_branch}'", content)
125+
updated = re.sub(r"(branches:\s*\[)([^\]]*)", lambda m: f"{m.group(1)}{update_branches(m.group(2))}", content)
112126
# Update api-version to next version
113127
updated = re.sub(r"api-version:\s*\d+\.\d+", f"api-version: {next_version.major_minor()}", updated)
114128

129+
if updated == content:
130+
print(f"☑️ No changes needed for {publish_file.relative_to(REPO_ROOT)}")
131+
return
132+
115133
publish_file.write_text(updated)
116134
print(
117-
f" Updated {publish_file.relative_to(REPO_ROOT)} - added branch '{new_branch}' and set api-version to {next_version.major_minor()}"
135+
f" Updated {publish_file.relative_to(REPO_ROOT)} - added branch '{new_branch}' and set api-version to {next_version.major_minor()}"
118136
)
119137

120138

@@ -124,8 +142,12 @@ def update_preview_yml(released_version: PythonLibraryVersion) -> None:
124142

125143
updated = re.sub(r"api-version: (\d+)\.(\d+)", f"api-version: {released_version.major_minor()}", content)
126144

145+
if updated == content:
146+
print(f"☑️ No changes needed for {preview_file.relative_to(REPO_ROOT)}")
147+
return
148+
127149
preview_file.write_text(updated)
128-
print(f" Updated {preview_file.relative_to(REPO_ROOT)} to version {released_version}")
150+
print(f" Updated {preview_file.relative_to(REPO_ROOT)} to version {released_version}")
129151

130152

131153
def update_antora_yml(released_version: PythonLibraryVersion) -> None:
@@ -135,8 +157,12 @@ def update_antora_yml(released_version: PythonLibraryVersion) -> None:
135157
updated = re.sub(r"version: '[^']*'", f"version: '{released_version}'", content)
136158
updated = re.sub(r"docs-version: '[^']*'", f"docs-version: '{released_version}'", updated)
137159

160+
if updated == content:
161+
print(f"☑️ No changes needed for {antora_file.relative_to(REPO_ROOT)}")
162+
return
163+
138164
antora_file.write_text(updated)
139-
print(f" Updated {antora_file.relative_to(REPO_ROOT)} to version {released_version}")
165+
print(f" Updated {antora_file.relative_to(REPO_ROOT)} to version {released_version}")
140166

141167

142168
def update_package_json(new_version: PythonLibraryVersion) -> None:
@@ -148,8 +174,12 @@ def update_package_json(new_version: PythonLibraryVersion) -> None:
148174
preview_version = f"{new_version.major_minor()}-preview"
149175
updated = re.sub(r'"version":\s*"[^"]*"', f'"version": "{preview_version}"', content)
150176

177+
if updated == content:
178+
print(f"☑️ No changes needed for {package_file.relative_to(REPO_ROOT)}")
179+
return
180+
151181
package_file.write_text(updated)
152-
print(f" Updated {package_file.relative_to(REPO_ROOT)} to version {preview_version}")
182+
print(f" Updated {package_file.relative_to(REPO_ROOT)} to version {preview_version}")
153183

154184

155185
def update_installation_adoc(next_version: PythonLibraryVersion) -> None:
@@ -168,41 +198,50 @@ def update_installation_adoc(next_version: PythonLibraryVersion) -> None:
168198
if not match:
169199
raise ValueError("Could not find installation table in installation.adoc")
170200
version_table = match.group(2)
201+
202+
if new_compat_table_entry in version_table:
203+
print(f"☑️ No changes needed for {installation_file.relative_to(REPO_ROOT)}")
204+
return
205+
171206
updated_version_table = f"\n{new_compat_table_entry}\n" + version_table
172207
updated = content.replace(version_table, updated_version_table)
173208
installation_file.write_text(updated)
174-
print(f" Updated {installation_file.relative_to(REPO_ROOT)} with new version {next_version}")
209+
print(f" Updated {installation_file.relative_to(REPO_ROOT)} with new version {next_version}")
175210

176211

177212
def main() -> None:
178213
# Get current version
179-
current_version = read_library_version()
214+
released_version = read_library_version()
215+
216+
# read new version from args
180217

181-
print(f"Current version: {current_version}")
218+
print(f"Released version: {released_version}")
182219

183-
# Calculate next version
184-
next_version = bump_version(current_version)
220+
# Calculate next version if not provided
221+
next_version = (
222+
PythonLibraryVersion.from_string(sys.argv[1]) if len(sys.argv) > 1 else bump_version(released_version)
223+
)
185224
print(f"Next version: {next_version}")
186225

187226
print("\nStarting post-release tasks...")
188227

189-
# update_version_py(next_version)
228+
update_version_py(next_version)
190229

191-
if not current_version.is_alpha():
230+
if not released_version.is_alpha():
192231
update_changelog(next_version)
193232

194233
update_package_json(next_version)
195234

196-
update_antora_yml(current_version)
197-
update_publish_yml(current_version, next_version)
198-
update_preview_yml(current_version)
235+
update_antora_yml(released_version)
236+
update_publish_yml(released_version, next_version)
237+
update_preview_yml(released_version)
199238

200239
update_installation_adoc(next_version)
201240

202241
print("\n✅ Post-release tasks completed!")
203242
print("\nNext steps:")
204243
print("* Review the changes")
205-
if not current_version.is_alpha():
244+
if not released_version.is_alpha():
206245
print("* Update installation.adoc")
207246
print(f"* Commit with message: 'Prepare for {next_version} development'")
208247
print("* Push to main branch")

0 commit comments

Comments
 (0)