Files
desktop/scripts/update_ff.py
mr. m 7e7d860c9e chore: Sync upstream Firefox to version 147.0, p=#11822
* chore: Sync upstream to `Firefox 147.0`

* chore: Continued migration, b=no-bug, c=tests

* chore: Finish migration without testing, b=no-bug, c=scripts, tabs, media, common, split-view

* feat: Finish migration, b=no-bug, c=common, compact-mode, split-view, workspaces

* feat: Finish basic migration, b=no-bug, c=kbs, common, folders

* feat: Update surfer, b=no-bug, c=scripts
2026-01-08 18:06:05 +01:00

110 lines
3.8 KiB
Python

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import json
import argparse
import shutil
from check_rc_response import get_rc_response, rc_should_be_updated
def update_rc(last_version: str, last_build: int):
rc_version, rc_build = get_rc_response()
if rc_should_be_updated(rc_version, last_version, rc_build, last_build):
print(f"New Firefox RC version is available: {rc_version}")
print("Removing engine directory and updating surfer.json.")
if os.path.exists("engine"):
shutil.rmtree("engine")
with open("surfer.json", "r") as f:
data = json.load(f)
with open("surfer.json", "w") as f:
data["version"]["candidate"] = rc_version
data["version"]["candidateBuild"] = rc_build
json.dump(data, f, indent=2)
print("Download the new engine by running 'npm run download'.")
os.system("npm run download")
else:
print("No new Firefox RC version available.")
def update_ff(is_rc: bool = False, last_version: str = "", last_build: int = 0):
"""Runs the npm command to sync Firefox."""
if is_rc:
return update_rc(last_version, last_build)
result = os.system("npm run sync:raw")
if result != 0:
raise RuntimeError("Failed to sync Firefox.")
def get_version_from_file(filename, is_rc):
"""Retrieves the version from the specified JSON file."""
try:
with open(filename, "r") as f:
data = json.load(f)
return (data["version"]["version"] if not is_rc else data["version"]["candidate"],
data["version"]["candidateBuild"])
except (FileNotFoundError, json.JSONDecodeError) as e:
raise RuntimeError(f"Error reading version from {filename}: {e}")
def update_readme(last_version, new_version, is_rc=False):
"""Updates the README.md file to reflect the new version."""
prefix = "RC " if is_rc else "`"
try:
with open("README.md", "r") as f:
data = f.read()
updated_data = data.replace(prefix + last_version, prefix + new_version)
with open("README.md", "w") as f:
f.write(updated_data)
except FileNotFoundError as e:
raise RuntimeError(f"README.md file not found: {e}")
def update_l10n_last_commit_hash():
L10N_REPO = "https://github.com/mozilla-l10n/firefox-l10n"
try:
os.system(f"git clone {L10N_REPO} l10n-temp --depth 1")
if not os.path.exists("build/firefox-cache"):
os.mkdir("build/firefox-cache")
os.system("cat l10n-temp/.git/refs/heads/main > build/firefox-cache/l10n-last-commit-hash")
# Remove new line character
data = ""
with open("build/firefox-cache/l10n-last-commit-hash", "r") as f:
data = f.read()
with open("build/firefox-cache/l10n-last-commit-hash", "w") as f:
f.write(data.strip())
except KeyboardInterrupt:
print("Exiting...")
shutil.rmtree("l10n-temp")
def main():
"""Main function to update versions and README."""
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument(
"--rc", help="Indicates that this is a release candidate.", default=False, action="store_true")
arg_parser.add_argument(
"--just-l10n", help="Only update the l10n last commit hash.", default=False, action="store_true")
args = arg_parser.parse_args()
try:
if not args.just_l10n:
last_version, last_build = get_version_from_file("surfer.json", args.rc)
update_ff(args.rc, last_version, last_build)
new_version, new_build = get_version_from_file("surfer.json", args.rc)
update_readme(last_version, new_version, args.rc)
print(
f"Updated version from {last_version} to {new_version} in README.md.")
print("Updating l10n last commit hash.")
update_l10n_last_commit_hash()
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
main()