Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions landoscript/src/landoscript/actions/android_l10n_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def run(
log.info(f"fetching original files from l10n repository: {dst_files}")
orig_files = await github_client.get_files(dst_files, branch=to_branch)

diffs = []
files_to_diff = []
for l10n_file in l10n_files:
if l10n_file.dst_name not in orig_files:
log.warning(f"WEIRD: {l10n_file.dst_name} not in orig_files, continuing anyways...")
Expand All @@ -106,7 +106,7 @@ async def run(
log.warning(f"old and new contents of {l10n_file.dst_name} are the same, skipping bump...")
continue

diffs.append(diff_contents(orig_file, new_file, l10n_file.dst_name))
files_to_diff.append((l10n_file.dst_name, orig_file, new_file))

for toml_info in android_l10n_import_info.toml_info:
src_path = toml_info.toml_path
Expand All @@ -122,11 +122,18 @@ async def run(
log.warning(f"old and new contents of {dst_path} are the same, skipping bump...")
continue

diffs.append(diff_contents(orig_file, new_file, dst_path))
files_to_diff.append((dst_path, orig_file, new_file))

if not diffs:
if not files_to_diff:
return []

# Sort files by path
files_to_diff.sort(key=lambda x: x[0])

diffs = []
for file_path, orig_file, new_file in files_to_diff:
diffs.append(diff_contents(orig_file, new_file, file_path))

diff = "\n".join(diffs)

with open(os.path.join(public_artifact_dir, "android-import.diff"), "w+") as f:
Expand Down
15 changes: 11 additions & 4 deletions landoscript/src/landoscript/actions/android_l10n_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def run(github_client: GithubClient, public_artifact_dir: str, android_l10
log.info(f"fetching original files from l10n repository: {dst_files}")
orig_files = await github_client.get_files(dst_files, branch=to_branch)

diffs = []
files_to_diff = []
for l10n_file in l10n_files:
if l10n_file.dst_name not in orig_files:
log.warning(f"WEIRD: {l10n_file.dst_name} not in orig_files, continuing anyways...")
Expand All @@ -98,7 +98,7 @@ async def run(github_client: GithubClient, public_artifact_dir: str, android_l10
log.warning(f"old and new contents of {l10n_file.dst_name} are the same, skipping bump...")
continue

diffs.append(diff_contents(orig_file, new_file, l10n_file.dst_name))
files_to_diff.append((l10n_file.dst_name, orig_file, new_file))

for toml_info in android_l10n_sync_info.toml_info:
if toml_info.toml_path not in new_files or toml_info.toml_path not in orig_files:
Expand All @@ -111,11 +111,18 @@ async def run(github_client: GithubClient, public_artifact_dir: str, android_l10
log.warning(f"old and new contents of {toml_info.toml_path} are the same, skipping bump...")
continue

diffs.append(diff_contents(orig_file, new_file, toml_info.toml_path))
files_to_diff.append((toml_info.toml_path, orig_file, new_file))

if not diffs:
if not files_to_diff:
return []

# Sort files by path
files_to_diff.sort(key=lambda x: x[0])

diffs = []
for file_path, orig_file, new_file in files_to_diff:
diffs.append(diff_contents(orig_file, new_file, file_path))

diff = "\n".join(diffs)

with open(os.path.join(public_artifact_dir, "android-sync.diff"), "w+") as f:
Expand Down
16 changes: 12 additions & 4 deletions landoscript/src/landoscript/actions/merge_day.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ async def run(
# process replacements, regex-replacements, and update clobber file
replacements = merge_info.replacements
regex_replacements = merge_info.regex_replacements
diffs = []

files_to_diff = []

if replacements or regex_replacements:
log.info("Performing replacements and regex_replacements")
needed_files = []
Expand All @@ -166,16 +168,22 @@ async def run(
for fn in orig_contents:
if orig_contents[fn] is None:
raise LandoscriptError(f"Couldn't find file '{fn}' in repository!")

diffs.append(diff_contents(str(orig_contents[fn]), new_contents[fn], fn))
files_to_diff.append((fn, str(orig_contents[fn]), new_contents[fn]))

log.info("Touching clobber file")
orig_clobber_file = (await github_client.get_files("CLOBBER", bump_branch))["CLOBBER"]
if orig_clobber_file is None:
raise LandoscriptError("Couldn't find CLOBBER file in repository!")

new_clobber_file = get_new_clobber_file(orig_clobber_file)
diffs.append(diff_contents(orig_clobber_file, new_clobber_file, "CLOBBER"))
files_to_diff.append(("CLOBBER", orig_clobber_file, new_clobber_file))

files_to_diff.sort(key=lambda x: x[0])

# Generate diffs in sorted order
diffs = []
for file_path, orig_file, new_file in files_to_diff:
diffs.append(diff_contents(orig_file, new_file, file_path))

diff = "\n".join(diffs)

Expand Down
9 changes: 8 additions & 1 deletion landoscript/src/landoscript/actions/version_bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ async def run(
log.info(f"{file} contents:")
log_file_contents(str(contents))

for file, orig in orig_files.items():
# Sort files by path to ensure consistent diff ordering
sorted_files = sorted(orig_files.keys())
for file in sorted_files:
orig = orig_files[file]
if not orig:
raise LandoscriptError(f"{file} does not exist!")

Expand All @@ -95,6 +98,10 @@ async def run(
log.info("no files to bump")
return []

def extract_path(diff_text):
return diff_text.split("\n", 1)[0].split(" ")[2][2:]

diffs = sorted(diffs, key=extract_path)
diff = "\n".join(diffs)

with open(os.path.join(public_artifact_dir, "version-bump.diff"), "w+") as f:
Expand Down
16 changes: 16 additions & 0 deletions landoscript/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ def assert_add_commit_response(action, commit_msg_strings, initial_values, expec

diffs = action["diff"].split("\ndiff")

# Extract file paths from diffs and verify they are sorted
file_paths = []
for i, diff in enumerate(diffs):
if not diff:
continue

if i == 0:
path_line = diff.split("\n")[0]
else:
path_line = "diff" + diff.split("\n")[0]

file_path = path_line.split(" ")[2][2:]
file_paths.append(file_path)

assert file_paths == sorted(file_paths), f"Files in diff are not sorted. Got: {file_paths}"

# ensure expected bumps are present to a reasonable degree of certainty
for file, after in expected_bumps.items():
for diff in diffs:
Expand Down