Skip to content

Commit 78a4042

Browse files
committed
chore(ci): share versionNameSuffix rewrite between merge paths
Extract `set_version_name_suffix()` and use it for both the `main->beta` and `beta->release` merges. The release path now uses the same b\d+ pattern as beta, so a beta past b9 no longer aborts the merge, and k9 starts at "b0" like Thunderbird instead of "b1". This should be fine since we don't release k9 beta, and the suffix gets dropped during a release for both apps.
1 parent 39546cb commit 78a4042

1 file changed

Lines changed: 28 additions & 24 deletions

File tree

scripts/ci/merges/merge_gradle.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
ours = sys.argv[1]
99
theirs = sys.argv[2]
1010

11+
BETA_SUFFIX = r"versionNameSuffix = \"b\d+\""
12+
MAIN_SUFFIX = r"versionNameSuffix = \"a1\""
13+
1114

1215
def get_current_branch():
1316
result = subprocess.run(
@@ -43,6 +46,24 @@ def replace_matching_line(file_path, search_term, new_line):
4346
file.write(line)
4447

4548

49+
def set_version_name_suffix(file_path, search_term, suffix):
50+
"""Rewrites the versionNameSuffix line matching search_term.
51+
52+
Sets the suffix to `suffix`, or drops the line entirely when `suffix` is
53+
None. Raises if the line is missing.
54+
"""
55+
found_line = find_matching_line(file_path, search_term)
56+
if not found_line:
57+
raise SystemExit(f"Search term '{search_term}' not found in merge result.")
58+
if suffix is None:
59+
replace_matching_line(file_path, search_term, "")
60+
return
61+
if f'"{suffix}"' in found_line:
62+
return
63+
new_line = '{}= "{}"\n'.format(found_line.split("=")[0], suffix)
64+
replace_matching_line(file_path, search_term, new_line)
65+
66+
4667
branch = get_current_branch()
4768

4869
search_term = "com.fsck.k9"
@@ -62,28 +83,11 @@ def replace_matching_line(file_path, search_term, new_line):
6283
raise SystemExit(f"Search term '{search_term}' not found in ours file.")
6384

6485
if branch == "beta":
65-
if is_k9:
66-
# main carries "a1";
67-
search_term = r"versionNameSuffix = \"a1\""
68-
found_line = find_matching_line(theirs, search_term)
69-
if not found_line:
70-
raise SystemExit(f"Search term '{search_term}' not found in theirs file.")
71-
new_line = "{}{}\n".format(found_line.split("=")[0], '= "b1"')
72-
replace_matching_line(ours, search_term, new_line)
73-
else:
74-
# beta always starts at "b0"; the shippable build workflow
75-
# bumps the suffix per beta release.
76-
search_term = r"versionNameSuffix = \"b\d+\""
77-
found_line = find_matching_line(ours, search_term)
78-
if not found_line:
79-
raise SystemExit(f"Search term '{search_term}' not found in merge result.")
80-
if '"b0"' not in found_line:
81-
new_line = "{}{}\n".format(found_line.split("=")[0], '= "b0"')
82-
replace_matching_line(ours, search_term, new_line)
86+
# beta always starts at "b0"; the shippable build workflow bumps the suffix
87+
# per beta release. k9 has no beta build, so main carries its suffix in
88+
# defaultConfig as "a1" rather than "b0". The suffix is dropped on release
89+
# for both apps below.
90+
set_version_name_suffix(ours, MAIN_SUFFIX if is_k9 else BETA_SUFFIX, "b0")
8391
elif branch == "release":
84-
search_term = r"versionNameSuffix = \"b[1-9]\""
85-
found_line = find_matching_line(theirs, search_term)
86-
if found_line:
87-
replace_matching_line(ours, search_term, "")
88-
else:
89-
raise SystemExit(f"Search term '{search_term}' not found in theirs file.")
92+
# release ships without a suffix, so drop the line beta was carrying.
93+
set_version_name_suffix(ours, BETA_SUFFIX, suffix=None)

0 commit comments

Comments
 (0)