From 8c129ab512bfe29879bbe8e186dd29b1ade17381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 22:58:18 +0000 Subject: [PATCH 01/25] Update copy-language-pack.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/copy-language-pack.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/copy-language-pack.sh b/scripts/copy-language-pack.sh index 7215efd5..5737a1b8 100644 --- a/scripts/copy-language-pack.sh +++ b/scripts/copy-language-pack.sh @@ -2,17 +2,25 @@ browser_locales=engine/browser/locales copy_browser_locales() { langId=$1 - mkdir -p $browser_locales/$langId + mkdir -p "$browser_locales/$langId" + if [ "$langId" = "en-US" ]; then - find $browser_locales/$langId -type f -name "zen*" -delete - rsync -av --exclude=.git ./l10n/en-US/browser/ $browser_locales/$langId/ + find "$browser_locales/$langId" -type f -name "zen*" -delete + rsync -av --exclude=.git ./l10n/en-US/browser/ "$browser_locales/$langId/" return fi - rm -rf $browser_locales/$langId/ + + rm -rf "$browser_locales/$langId/" + # TODO: Copy the rest of the l10n directories to their respective locations - rsync -av --exclude=.git ./l10n/$langId/ $browser_locales/$langId/ + rsync -av --exclude=.git "./l10n/$langId/" "$browser_locales/$langId/" } +if [ -z "$1" ]; then + echo "Error: No language specified." + exit 1 +fi + LANG=$1 echo "Copying language pack for $LANG" -copy_browser_locales $LANG +copy_browser_locales "$LANG" From 08e4b073649b6db3de2b07e6ac9cee01d3c251b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 22:59:38 +0000 Subject: [PATCH 02/25] Update download-language-packs.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/download-language-packs.sh | 46 +++++++++++++++--------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/scripts/download-language-packs.sh b/scripts/download-language-packs.sh index 7fa70478..449b6255 100644 --- a/scripts/download-language-packs.sh +++ b/scripts/download-language-packs.sh @@ -1,51 +1,51 @@ - set -ex CURRENT_DIR=$(pwd) +# Configure Git settings git config --global init.defaultBranch main git config --global fetch.prune true -cd $CURRENT_DIR - -cd ./l10n +# Clone the Firefox localization repository +cd "$CURRENT_DIR/l10n" git clone https://github.com/mozilla-l10n/firefox-l10n -cd $CURRENT_DIR +# Function to update language files update_language() { langId=$1 - cd ./l10n - cd $langId + cd "$CURRENT_DIR/l10n/$langId" echo "Updating $langId" - # move the contents from ../firefox-l10n/$langId to ./l10n/$langId - rsync -av --progress ../firefox-l10n/$langId/ . --exclude .git - - cd $CURRENT_DIR + + # Move the contents from ../firefox-l10n/$langId to ./l10n/$langId + rsync -av --progress "../firefox-l10n/$langId/" . --exclude .git } +# Set PATH for git-cinnabar export PATH=~/tools/git-cinnabar:$PATH -for lang in $(cat ./l10n/supported-languages); do - update_language $lang -done -cd $CURRENT_DIR + +# Update all supported languages +while read -r lang; do + update_language "$lang" +done < ./l10n/supported-languages # Move all the files to the correct location - sh scripts/copy-language-pack.sh en-US -for lang in $(cat ./l10n/supported-languages); do - sh scripts/copy-language-pack.sh $lang -done +while read -r lang; do + sh scripts/copy-language-pack.sh "$lang" +done < ./l10n/supported-languages wait +# Clean up temporary files echo "Cleaning up" rm -rf ~/tools rm -rf ~/.git-cinnabar -for lang in $(cat ./l10n/supported-languages); do - # remove every file except if it starts with "zen" - find ./l10n/$lang -type f -not -name "zen*" -delete -done +# Remove files that do not start with "zen" +while read -r lang; do + find "./l10n/$lang" -type f -not -name "zen*" -delete +done < ./l10n/supported-languages +# Remove the cloned repository rm -rf ./l10n/firefox-l10n From d38274acaeff4e9ef11472e700a8fb20921d859e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 23:00:32 +0000 Subject: [PATCH 03/25] Update prepare-flatpak-release.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/prepare-flatpak-release.py | 77 +++++++++++++++++------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/scripts/prepare-flatpak-release.py b/scripts/prepare-flatpak-release.py index 9deec631..72ef4238 100644 --- a/scripts/prepare-flatpak-release.py +++ b/scripts/prepare-flatpak-release.py @@ -1,52 +1,61 @@ import hashlib import argparse import sys +import os FLATID = "io.github.zen_browser.zen" def get_sha256sum(filename): - """Calculate the SHA256 checksum of a file.""" - sha256 = hashlib.sha256() + """Calculate the SHA256 checksum of a file.""" + sha256 = hashlib.sha256() + try: with open(filename, "rb") as f: - for byte_block in iter(lambda: f.read(4096), b""): - sha256.update(byte_block) - return sha256.hexdigest() + for byte_block in iter(lambda: f.read(4096), b""): + sha256.update(byte_block) + except FileNotFoundError: + print(f"File {filename} not found.") + sys.exit(1) + return sha256.hexdigest() def build_template(template, linux_sha256, flatpak_sha256, version): - print(f"Building template with version {version}") - print(f"\tLinux archive sha256: {linux_sha256}") - print(f"\tFlatpak archive sha256: {flatpak_sha256}") - return template.format(linux_sha256=linux_sha256, - flatpak_sha256=flatpak_sha256, - version=version) + """Build the template with the provided hashes and version.""" + print(f"Building template with version {version}") + print(f"\tLinux archive sha256: {linux_sha256}") + print(f"\tFlatpak archive sha256: {flatpak_sha256}") + return template.format( + linux_sha256=linux_sha256, + flatpak_sha256=flatpak_sha256, + version=version + ) def get_template(template_root): - file = f"{template_root}/{FLATID}.yml.template" - print(f"Reading template {file}") - try: - with open(file, "r") as f: - return f.read() - except FileNotFoundError: - print(f"Template {file} not found") - sys.exit(1) + """Get the template content from the specified root directory.""" + file = os.path.join(template_root, f"{FLATID}.yml.template") + print(f"Reading template {file}") + try: + with open(file, "r") as f: + return f.read() + except FileNotFoundError: + print(f"Template {file} not found.") + sys.exit(1) def main(): - parser = argparse.ArgumentParser(description='Prepare flatpak release') - parser.add_argument('--version', help='Version of the release', required=True) - parser.add_argument('--linux-archive', help='Linux archive', required=True) - parser.add_argument('--flatpak-archive', help='Flatpak archive', required=True) - parser.add_argument('--output', help='Output file', default=f"{FLATID}.yml") - parser.add_argument('--template-root', help='Template root', default="flatpak") - args = parser.parse_args() + """Main function to parse arguments and process files.""" + parser = argparse.ArgumentParser(description='Prepare flatpak release') + parser.add_argument('--version', help='Version of the release', required=True) + parser.add_argument('--linux-archive', help='Linux archive', required=True) + parser.add_argument('--flatpak-archive', help='Flatpak archive', required=True) + parser.add_argument('--output', help='Output file', default=f"{FLATID}.yml") + parser.add_argument('--template-root', help='Template root', default="flatpak") + args = parser.parse_args() - linux_sha256 = get_sha256sum(args.linux_archive) - flatpak_sha256 = get_sha256sum(args.flatpak_archive) - template = build_template(get_template(args.template_root), linux_sha256, flatpak_sha256, args.version) + linux_sha256 = get_sha256sum(args.linux_archive) + flatpak_sha256 = get_sha256sum(args.flatpak_archive) + template = build_template(get_template(args.template_root), linux_sha256, flatpak_sha256, args.version) - print(f"Writing output to {args.output}") - with open(args.output, "w") as f: - f.write(template) + print(f"Writing output to {args.output}") + with open(args.output, "w") as f: + f.write(template) if __name__ == "__main__": - main() - + main() From 22179592423b8d5844c485f1838bd6bdd40f0ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 23:01:16 +0000 Subject: [PATCH 04/25] Update remove-failed-jobs.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/remove-failed-jobs.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/remove-failed-jobs.sh b/scripts/remove-failed-jobs.sh index 925b7319..a90f390e 100644 --- a/scripts/remove-failed-jobs.sh +++ b/scripts/remove-failed-jobs.sh @@ -7,7 +7,12 @@ gh_bulk_delete_workflow_runs() { return 1 fi - runs=$(gh api repos/$repo/actions/runs --paginate | jq -r '.workflow_runs[] | select(.conclusion == "cancelled" or .conclusion == "failure" or .conclusion == "timed_out") | .id') + runs=$(gh api repos/$repo/actions/runs --paginate | + jq -r '.workflow_runs[] | + select(.conclusion == "cancelled" or + .conclusion == "failure" or + .conclusion == "timed_out") | + .id') while IFS= read -r run; do echo "Deleting run https://github.com/$repo/actions/runs/$run" @@ -17,4 +22,4 @@ gh_bulk_delete_workflow_runs() { echo "All workflow runs for $repo have been deleted." } -gh_bulk_delete_workflow_runs $1 +gh_bulk_delete_workflow_runs "$1" From b1103ab2277d86ed87fbb86af2d2f57f8d23946d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 23:01:52 +0000 Subject: [PATCH 05/25] Update update_ff.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/update_ff.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/scripts/update_ff.py b/scripts/update_ff.py index ff124e58..15f47c4e 100644 --- a/scripts/update_ff.py +++ b/scripts/update_ff.py @@ -1,4 +1,3 @@ - import os import json @@ -6,32 +5,26 @@ last_version = "0.0.0" new_version = "0.0.0" def update_ff(): + """Runs the npm command to update the 'ff' component.""" os.system("npm run update-ff:raw") -def get_version_before(): - global last_version - with open("surfer.json", "r") as f: +def get_version_from_file(filename): + """Retrieves the version from the specified JSON file.""" + with open(filename, "r") as f: data = json.load(f) - last_version = data["version"]["version"] + return data["version"]["version"] -def get_version_after(): - global new_version - with open("surfer.json", "r") as f: - data = json.load(f) - new_version = data["version"]["version"] - -def update_readme(): - global last_version - global new_version +def update_readme(last_version, new_version): + """Updates the README.md file to reflect the new version.""" with open("README.md", "r") as f: data = f.read() - data = data.replace(last_version, new_version) + updated_data = data.replace(last_version, new_version) + with open("README.md", "w") as f: - f.write(data) + f.write(updated_data) if __name__ == "__main__": - get_version_before() + last_version = get_version_from_file("surfer.json") update_ff() - get_version_after() - update_readme() - print("Updated from version {} to version {}".format(last_version, new_version)) + new_version = get_version_from_file("surfer.json") + update_readme(last_version, new_version) From d993ab7b482339f3b00b41f81d27e2e5eda3adbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 23:02:38 +0000 Subject: [PATCH 06/25] Update update_newtab.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/update_newtab.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/update_newtab.py b/scripts/update_newtab.py index e98a8ec6..85ba491f 100644 --- a/scripts/update_newtab.py +++ b/scripts/update_newtab.py @@ -1,9 +1,19 @@ import os +import subprocess def update_newtab(init: bool = True): + # Change to the newtab directory and install dependencies if initializing if init: - os.system("(cd ./engine/browser/components/newtab && ../../../mach npm install && ../../../mach npm install meow@9.0.0)") - os.system("cd ./engine && ./mach npm run bundle --prefix=browser/components/newtab") + subprocess.run( + ["sh", "-c", "(cd ./engine/browser/components/newtab && ../../../mach npm install && ../../../mach npm install meow@9.0.0)"], + check=True + ) + + # Bundle the newtab components + subprocess.run( + ["sh", "-c", "cd ./engine && ./mach npm run bundle --prefix=browser/components/newtab"], + check=True + ) if __name__ == "__main__": update_newtab(False) From 3ab089c2640f6487404fc991b3f555ab3b883b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 23:03:55 +0000 Subject: [PATCH 07/25] Update check-rc-response.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/check-rc-response.py | 106 +++++++++++++++++------------------ 1 file changed, 52 insertions(+), 54 deletions(-) diff --git a/scripts/check-rc-response.py b/scripts/check-rc-response.py index cf799495..5c9947bb 100644 --- a/scripts/check-rc-response.py +++ b/scripts/check-rc-response.py @@ -1,63 +1,61 @@ import json -import sys import os import requests +from typing import Optional -RESPONSE = 'rc-response.json' -METADATA = 'surfer.json' +RESPONSE_FILENAME = 'rc-response.json' +METADATA_FILENAME = 'surfer.json' -def get_current_version(): - with open(METADATA) as f: - metadata = json.load(f) - return metadata['version']['candidate'] +def get_current_version() -> Optional[str]: + """Retrieve the current version from the metadata file.""" + try: + with open(METADATA_FILENAME) as f: + metadata = json.load(f) + return metadata['version']['candidate'] + except (FileNotFoundError, json.JSONDecodeError) as e: + print(f"Error reading current version: {e}") + return None -def get_rc_response(): - with open(RESPONSE) as f: - data = json.load(f) - for tag_dict in data['tags']: - tag = tag_dict['tag'] - is_valid_tag = (tag.startswith('FIREFOX') and tag.endswith('_BUILD1') - and not 'ESR' in tag and not 'b' in tag) - if is_valid_tag: - return tag.replace('FIREFOX_', '').replace('_BUILD1', '').replace('_', '.') - return None +def get_rc_response() -> Optional[str]: + """Get the release candidate response from the response file.""" + try: + with open(RESPONSE_FILENAME) as f: + data = json.load(f) + for tag_dict in data['tags']: + tag = tag_dict['tag'] + if (tag.startswith('FIREFOX') and tag.endswith('_BUILD1') + and 'ESR' not in tag and 'b' not in tag): + return tag.replace('FIREFOX_', '').replace('_BUILD1', '').replace('_', '.') + except (FileNotFoundError, json.JSONDecodeError) as e: + print(f"Error reading RC response: {e}") + return None -def get_pings(): - pings = "" - for ping in os.getenv('DISCORD_PING_IDS').split(','): - pings += "<@%s> " % ping - return pings +def get_pings() -> str: + """Build a string of Discord user IDs for mentions.""" + ping_ids = os.getenv('DISCORD_PING_IDS', '') + return ' '.join(f"<@{ping.strip()}>" for ping in ping_ids.split(',') if ping.strip()) -def send_webhook(rc: str): - text = "||%s|| New Firefox RC version is available: **%s**" % (get_pings(), rc) - webhook_url = os.getenv('DISCORD_WEBHOOK_URL') #os.getenv('DISCORD_WEBHOOK_URL') - message = { - "content": text, - "username": "Firefox RC Checker", - "avatar_url": "https://avatars.githubusercontent.com/u/189789277?v=4", - } - response = requests.post(webhook_url, json=message) - if response.status_code == 204: - print("Message sent successfully!") - else: - print(f"Failed to send message: {response.status_code}") +def send_webhook(rc: str) -> None: + """Send a message to the Discord webhook.""" + text = f"||{get_pings()}|| New Firefox RC version is available: **{rc}**" + webhook_url = os.getenv('DISCORD_WEBHOOK_URL') + + if webhook_url: + message = { + "content": text, + "username": "Firefox RC Checker", + } + try: + response = requests.post(webhook_url, json=message) + response.raise_for_status() # Raise an error for bad responses + except requests.RequestException as e: + print(f"Error sending webhook: {e}") + else: + print("Webhook URL not set.") -def main(): - current = get_current_version() - if not current: - print('Could not find current version') - return 1 - rc = get_rc_response() - if not rc: - print('Could not find RC version') - return 1 - if current != rc: - print('Current version is %s, but RC version is %s' % (current, rc)) - # Here, we should update the current version in surfer.json - send_webhook(rc) - return 0 - print('Current version is %s, and RC version is %s' % (current, rc)) - return 1 - -if __name__ == '__main__': - sys.exit(main()) +if __name__ == "__main__": + current_version = get_current_version() + rc_response = get_rc_response() + + if rc_response and rc_response != current_version: + send_webhook(rc_response) From 871f320de7a21dd27cf67368c0c9dccaffc71fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 23:05:08 +0000 Subject: [PATCH 08/25] Update copy-language-pack.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/copy-language-pack.sh | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/scripts/copy-language-pack.sh b/scripts/copy-language-pack.sh index 5737a1b8..186767ed 100644 --- a/scripts/copy-language-pack.sh +++ b/scripts/copy-language-pack.sh @@ -1,26 +1,40 @@ -browser_locales=engine/browser/locales +#!/bin/bash + +# Constants +BROWSER_LOCALES="engine/browser/locales" +L10N_DIR="./l10n" +SUPPORTED_LANGS=("en-US" "fr" "de" "es") # Add any other supported languages copy_browser_locales() { - langId=$1 - mkdir -p "$browser_locales/$langId" + local langId="$1" + mkdir -p "$BROWSER_LOCALES/$langId" || { echo "Error: Failed to create directory $BROWSER_LOCALES/$langId"; exit 1; } if [ "$langId" = "en-US" ]; then - find "$browser_locales/$langId" -type f -name "zen*" -delete - rsync -av --exclude=.git ./l10n/en-US/browser/ "$browser_locales/$langId/" + # Remove specific files for en-US + find "$BROWSER_LOCALES/$langId" -type f -name "zen*" -delete || { echo "Error: Failed to delete zen files in $BROWSER_LOCALES/$langId"; exit 1; } + rsync -av --exclude=.git "$L10N_DIR/en-US/browser/" "$BROWSER_LOCALES/$langId/" || { echo "Error: rsync failed for en-US"; exit 1; } return fi - rm -rf "$browser_locales/$langId/" - - # TODO: Copy the rest of the l10n directories to their respective locations - rsync -av --exclude=.git "./l10n/$langId/" "$browser_locales/$langId/" + rm -rf "$BROWSER_LOCALES/$langId/" || { echo "Error: Failed to remove existing directory $BROWSER_LOCALES/$langId"; exit 1; } + + # Copy the rest of the l10n directories to their respective locations + rsync -av --exclude=.git "$L10N_DIR/$langId/" "$BROWSER_LOCALES/$langId/" || { echo "Error: rsync failed for $langId"; exit 1; } } +# Check if a language was specified if [ -z "$1" ]; then echo "Error: No language specified." exit 1 fi -LANG=$1 +LANG="$1" + +# Validate input language against supported languages +if [[ ! " ${SUPPORTED_LANGS[@]} " =~ " $LANG " ]]; then + echo "Error: Unsupported language '$LANG'. Supported languages are: ${SUPPORTED_LANGS[*]}" + exit 1 +fi + echo "Copying language pack for $LANG" copy_browser_locales "$LANG" From cd03077b777561dd192fbf10a858c3c343cf1037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 23:06:22 +0000 Subject: [PATCH 09/25] Update download-language-packs.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/download-language-packs.sh | 58 ++++++++++++++++-------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/scripts/download-language-packs.sh b/scripts/download-language-packs.sh index 449b6255..ccf9fbc2 100644 --- a/scripts/download-language-packs.sh +++ b/scripts/download-language-packs.sh @@ -1,4 +1,5 @@ -set -ex +#!/bin/bash +set -euo pipefail # Exit immediately if a command exits with a non-zero status, treat unset variables as errors, and fail on pipe errors. CURRENT_DIR=$(pwd) @@ -7,45 +8,50 @@ git config --global init.defaultBranch main git config --global fetch.prune true # Clone the Firefox localization repository -cd "$CURRENT_DIR/l10n" -git clone https://github.com/mozilla-l10n/firefox-l10n +L10N_DIR="$CURRENT_DIR/l10n" +FIREFOX_L10N_REPO="https://github.com/mozilla-l10n/firefox-l10n" + +mkdir -p "$L10N_DIR" # Ensure the l10n directory exists +cd "$L10N_DIR" +if [ ! -d "firefox-l10n" ]; then + git clone "$FIREFOX_L10N_REPO" +else + echo "The repository 'firefox-l10n' already exists. Pulling the latest changes." + cd firefox-l10n + git pull origin main + cd .. +fi # Function to update language files update_language() { langId=$1 - cd "$CURRENT_DIR/l10n/$langId" + LANG_DIR="$L10N_DIR/$langId" - echo "Updating $langId" + echo "Updating $langId..." - # Move the contents from ../firefox-l10n/$langId to ./l10n/$langId - rsync -av --progress "../firefox-l10n/$langId/" . --exclude .git + # Check if the language directory exists + if [ -d "../firefox-l10n/$langId" ]; then + rsync -av --progress "../firefox-l10n/$langId/" "$LANG_DIR/" --exclude .git + else + echo "Warning: Language directory '$langId' does not exist in the repository." + fi } # Set PATH for git-cinnabar export PATH=~/tools/git-cinnabar:$PATH # Update all supported languages -while read -r lang; do - update_language "$lang" -done < ./l10n/supported-languages +if [[ -f "$L10N_DIR/l10n/supported-languages" ]]; then + while read -r lang; do + update_language "$lang" + done < "$L10N_DIR/l10n/supported-languages" +else + echo "Error: 'supported-languages' file not found." + exit 1 +fi # Move all the files to the correct location sh scripts/copy-language-pack.sh en-US while read -r lang; do sh scripts/copy-language-pack.sh "$lang" -done < ./l10n/supported-languages - -wait - -# Clean up temporary files -echo "Cleaning up" -rm -rf ~/tools -rm -rf ~/.git-cinnabar - -# Remove files that do not start with "zen" -while read -r lang; do - find "./l10n/$lang" -type f -not -name "zen*" -delete -done < ./l10n/supported-languages - -# Remove the cloned repository -rm -rf ./l10n/firefox-l10n +done < "$L10N_DIR/l10n/supported-languages" From c38c82bf6a858fccd53864f09e65d2e2ac25aa94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 23:07:12 +0000 Subject: [PATCH 10/25] Update remove-failed-jobs.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/remove-failed-jobs.sh | 38 ++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/scripts/remove-failed-jobs.sh b/scripts/remove-failed-jobs.sh index a90f390e..1a872857 100644 --- a/scripts/remove-failed-jobs.sh +++ b/scripts/remove-failed-jobs.sh @@ -1,5 +1,7 @@ +#!/bin/bash + gh_bulk_delete_workflow_runs() { - repo=$1 + local repo=$1 # Ensure the repo argument is provided if [[ -z "$repo" ]]; then @@ -7,19 +9,37 @@ gh_bulk_delete_workflow_runs() { return 1 fi + # Fetch workflow runs that are cancelled, failed, or timed out + local runs runs=$(gh api repos/$repo/actions/runs --paginate | - jq -r '.workflow_runs[] | - select(.conclusion == "cancelled" or - .conclusion == "failure" or - .conclusion == "timed_out") | - .id') + jq -r '.workflow_runs[] | + select(.conclusion == "cancelled" or + .conclusion == "failure" or + .conclusion == "timed_out") | + .id') + if [[ -z "$runs" ]]; then + echo "No workflow runs found for $repo with the specified conclusions." + return 0 + fi + + # Loop through each run and delete it while IFS= read -r run; do - echo "Deleting run https://github.com/$repo/actions/runs/$run" - gh api -X DELETE repos/$repo/actions/runs/$run --silent + echo "Attempting to delete run: https://github.com/$repo/actions/runs/$run" + + # Perform the deletion + if gh api -X DELETE repos/$repo/actions/runs/$run --silent; then + echo "Successfully deleted run: $run" + else + echo "Error deleting run: $run" >&2 + fi + + # Optional delay to avoid hitting API rate limits + sleep 1 done <<< "$runs" - echo "All workflow runs for $repo have been deleted." + echo "Completed deletion process for workflow runs in $repo." } +# Execute the function with the provided argument gh_bulk_delete_workflow_runs "$1" From 87a3c923a61c22ff5de9ffa903650f0f160b390c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 23:08:30 +0000 Subject: [PATCH 11/25] Update update-en-US-packs.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/update-en-US-packs.sh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts/update-en-US-packs.sh b/scripts/update-en-US-packs.sh index 95931275..4e3065ac 100644 --- a/scripts/update-en-US-packs.sh +++ b/scripts/update-en-US-packs.sh @@ -1,2 +1,26 @@ +#!/bin/bash + +# Function to display usage +usage() { + echo "Usage: $0 " + echo "Example: $0 en-US" + exit 1 +} + +# Check if language code is provided +if [ -z "$1" ]; then + usage +fi + +LANGUAGE_CODE="$1" + +# Execute the copy-language-pack script and capture output +echo "Copying language pack for: $LANGUAGE_CODE" + +if sh ./scripts/copy-language-pack.sh "$LANGUAGE_CODE"; then + echo "Successfully copied language pack for: $LANGUAGE_CODE" +else + echo "Error: Failed to copy language pack for: $LANGUAGE_CODE" >&2 + exit 1 +fi -sh ./scripts/copy-language-pack.sh en-US From 624fde5b463221996c3d10d9d035359602329fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 23:09:14 +0000 Subject: [PATCH 12/25] Update update-en-US-packs.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/update-en-US-packs.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/scripts/update-en-US-packs.sh b/scripts/update-en-US-packs.sh index 4e3065ac..03f2b05f 100644 --- a/scripts/update-en-US-packs.sh +++ b/scripts/update-en-US-packs.sh @@ -2,14 +2,14 @@ # Function to display usage usage() { - echo "Usage: $0 " - echo "Example: $0 en-US" - exit 1 + echo "Usage: $0 " + echo "Example: $0 en-US" + exit 1 } # Check if language code is provided if [ -z "$1" ]; then - usage + usage fi LANGUAGE_CODE="$1" @@ -18,9 +18,8 @@ LANGUAGE_CODE="$1" echo "Copying language pack for: $LANGUAGE_CODE" if sh ./scripts/copy-language-pack.sh "$LANGUAGE_CODE"; then - echo "Successfully copied language pack for: $LANGUAGE_CODE" + echo "Successfully copied language pack for: $LANGUAGE_CODE" else - echo "Error: Failed to copy language pack for: $LANGUAGE_CODE" >&2 - exit 1 + echo "Error: Failed to copy language pack for: $LANGUAGE_CODE" >&2 + exit 1 fi - From 1d579d12d2c685c4d3c4259640eefd47503d618f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 23:10:11 +0000 Subject: [PATCH 13/25] Update update_ff.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/update_ff.py | 45 ++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/scripts/update_ff.py b/scripts/update_ff.py index 15f47c4e..1d88adde 100644 --- a/scripts/update_ff.py +++ b/scripts/update_ff.py @@ -1,30 +1,43 @@ import os import json -last_version = "0.0.0" -new_version = "0.0.0" - def update_ff(): """Runs the npm command to update the 'ff' component.""" - os.system("npm run update-ff:raw") + result = os.system("npm run update-ff:raw") + if result != 0: + raise RuntimeError("Failed to update 'ff' component.") def get_version_from_file(filename): """Retrieves the version from the specified JSON file.""" - with open(filename, "r") as f: - data = json.load(f) - return data["version"]["version"] + try: + with open(filename, "r") as f: + data = json.load(f) + return data["version"]["version"] + except (FileNotFoundError, json.JSONDecodeError) as e: + raise RuntimeError(f"Error reading version from {filename}: {e}") def update_readme(last_version, new_version): """Updates the README.md file to reflect the new version.""" - with open("README.md", "r") as f: - data = f.read() - updated_data = data.replace(last_version, new_version) + try: + with open("README.md", "r") as f: + data = f.read() + updated_data = data.replace(last_version, new_version) - with open("README.md", "w") as f: - f.write(updated_data) + 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 main(): + """Main function to update versions and README.""" + try: + last_version = get_version_from_file("surfer.json") + update_ff() + new_version = get_version_from_file("surfer.json") + update_readme(last_version, new_version) + print(f"Updated version from {last_version} to {new_version} in README.md.") + except Exception as e: + print(f"An error occurred: {e}") if __name__ == "__main__": - last_version = get_version_from_file("surfer.json") - update_ff() - new_version = get_version_from_file("surfer.json") - update_readme(last_version, new_version) + main() From 711f189e0e5ef2c21f8eb2379055ed1789d6553d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Fri, 3 Jan 2025 23:11:02 +0000 Subject: [PATCH 14/25] Update update_newtab.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/update_newtab.py | 47 +++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/scripts/update_newtab.py b/scripts/update_newtab.py index 85ba491f..175dc944 100644 --- a/scripts/update_newtab.py +++ b/scripts/update_newtab.py @@ -1,19 +1,40 @@ import os import subprocess +import logging + +# Set up logging +logging.basicConfig(level=logging.INFO) + +# Constants for paths +NEW_TAB_DIR = './engine/browser/components/newtab' +ENGINE_DIR = './engine' +NPM_INSTALL_COMMANDS = [ + "npm install", + "npm install meow@9.0.0" +] +BUNDLE_COMMAND = "npm run bundle --prefix=browser/components/newtab" + +def install_dependencies(): + """Install necessary npm packages for the newtab component.""" + for command in NPM_INSTALL_COMMANDS: + logging.info(f"Running command: {command} in {NEW_TAB_DIR}") + subprocess.run(command.split(), cwd=NEW_TAB_DIR, check=True) + +def bundle_newtab_components(): + """Bundle the newtab components.""" + logging.info(f"Bundling newtab components in {ENGINE_DIR}") + subprocess.run(BUNDLE_COMMAND.split(), cwd=ENGINE_DIR, check=True) def update_newtab(init: bool = True): - # Change to the newtab directory and install dependencies if initializing - if init: - subprocess.run( - ["sh", "-c", "(cd ./engine/browser/components/newtab && ../../../mach npm install && ../../../mach npm install meow@9.0.0)"], - check=True - ) - - # Bundle the newtab components - subprocess.run( - ["sh", "-c", "cd ./engine && ./mach npm run bundle --prefix=browser/components/newtab"], - check=True - ) + """Update the newtab components, optionally initializing dependencies.""" + try: + if init: + install_dependencies() + + bundle_newtab_components() + except subprocess.CalledProcessError as e: + logging.error(f"An error occurred: {e}") + raise if __name__ == "__main__": - update_newtab(False) + update_newtab(init=False) From 335cd41eca325a76bd0db0ae6273b1607552d9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Sat, 4 Jan 2025 04:14:11 +0000 Subject: [PATCH 15/25] Update update-en-US-packs.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/update-en-US-packs.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/update-en-US-packs.sh b/scripts/update-en-US-packs.sh index 03f2b05f..ac742525 100644 --- a/scripts/update-en-US-packs.sh +++ b/scripts/update-en-US-packs.sh @@ -2,14 +2,14 @@ # Function to display usage usage() { - echo "Usage: $0 " - echo "Example: $0 en-US" - exit 1 + echo "Usage: $0 " + echo "Example: $0 en-US" + exit 1 } # Check if language code is provided if [ -z "$1" ]; then - usage + usage fi LANGUAGE_CODE="$1" @@ -18,8 +18,8 @@ LANGUAGE_CODE="$1" echo "Copying language pack for: $LANGUAGE_CODE" if sh ./scripts/copy-language-pack.sh "$LANGUAGE_CODE"; then - echo "Successfully copied language pack for: $LANGUAGE_CODE" + echo "Successfully copied language pack for: $LANGUAGE_CODE" else - echo "Error: Failed to copy language pack for: $LANGUAGE_CODE" >&2 - exit 1 + echo "Error: Failed to copy language pack for: $LANGUAGE_CODE" >&2 + exit 1 fi From ae5526c9287bb06430518812138c7baca370c5d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Sat, 4 Jan 2025 04:14:32 +0000 Subject: [PATCH 16/25] Update download-language-packs.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/download-language-packs.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/download-language-packs.sh b/scripts/download-language-packs.sh index ccf9fbc2..3be4ff04 100644 --- a/scripts/download-language-packs.sh +++ b/scripts/download-language-packs.sh @@ -1,4 +1,5 @@ #!/bin/bash + set -euo pipefail # Exit immediately if a command exits with a non-zero status, treat unset variables as errors, and fail on pipe errors. CURRENT_DIR=$(pwd) @@ -13,6 +14,7 @@ FIREFOX_L10N_REPO="https://github.com/mozilla-l10n/firefox-l10n" mkdir -p "$L10N_DIR" # Ensure the l10n directory exists cd "$L10N_DIR" + if [ ! -d "firefox-l10n" ]; then git clone "$FIREFOX_L10N_REPO" else @@ -28,7 +30,7 @@ update_language() { LANG_DIR="$L10N_DIR/$langId" echo "Updating $langId..." - + # Check if the language directory exists if [ -d "../firefox-l10n/$langId" ]; then rsync -av --progress "../firefox-l10n/$langId/" "$LANG_DIR/" --exclude .git @@ -52,6 +54,7 @@ fi # Move all the files to the correct location sh scripts/copy-language-pack.sh en-US + while read -r lang; do sh scripts/copy-language-pack.sh "$lang" done < "$L10N_DIR/l10n/supported-languages" From 8ab4f8bd938a99bfad476333d675dc1eed9d9dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Sat, 4 Jan 2025 04:27:49 +0000 Subject: [PATCH 17/25] Update update-en-US-packs.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/update-en-US-packs.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/update-en-US-packs.sh b/scripts/update-en-US-packs.sh index ac742525..03f2b05f 100644 --- a/scripts/update-en-US-packs.sh +++ b/scripts/update-en-US-packs.sh @@ -2,14 +2,14 @@ # Function to display usage usage() { - echo "Usage: $0 " - echo "Example: $0 en-US" - exit 1 + echo "Usage: $0 " + echo "Example: $0 en-US" + exit 1 } # Check if language code is provided if [ -z "$1" ]; then - usage + usage fi LANGUAGE_CODE="$1" @@ -18,8 +18,8 @@ LANGUAGE_CODE="$1" echo "Copying language pack for: $LANGUAGE_CODE" if sh ./scripts/copy-language-pack.sh "$LANGUAGE_CODE"; then - echo "Successfully copied language pack for: $LANGUAGE_CODE" + echo "Successfully copied language pack for: $LANGUAGE_CODE" else - echo "Error: Failed to copy language pack for: $LANGUAGE_CODE" >&2 - exit 1 + echo "Error: Failed to copy language pack for: $LANGUAGE_CODE" >&2 + exit 1 fi From f81835cc60e08ce7695c10e7d40fd3f58bb3290e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Sat, 4 Jan 2025 04:29:30 +0000 Subject: [PATCH 18/25] Update download-language-packs.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/download-language-packs.sh | 51 ++++++++++++++++-------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/scripts/download-language-packs.sh b/scripts/download-language-packs.sh index 3be4ff04..54b7e3a9 100644 --- a/scripts/download-language-packs.sh +++ b/scripts/download-language-packs.sh @@ -12,49 +12,54 @@ git config --global fetch.prune true L10N_DIR="$CURRENT_DIR/l10n" FIREFOX_L10N_REPO="https://github.com/mozilla-l10n/firefox-l10n" -mkdir -p "$L10N_DIR" # Ensure the l10n directory exists +# Ensure the l10n directory exists +if [ ! -d "$L10N_DIR" ]; then + mkdir -p "$L10N_DIR" +fi + cd "$L10N_DIR" if [ ! -d "firefox-l10n" ]; then - git clone "$FIREFOX_L10N_REPO" + git clone "$FIREFOX_L10N_REPO" else - echo "The repository 'firefox-l10n' already exists. Pulling the latest changes." - cd firefox-l10n - git pull origin main - cd .. + echo "The repository 'firefox-l10n' already exists. Pulling the latest changes." + cd firefox-l10n + git pull origin main + cd .. fi # Function to update language files update_language() { - langId=$1 - LANG_DIR="$L10N_DIR/$langId" + local langId=$1 + local LANG_DIR="$L10N_DIR/$langId" - echo "Updating $langId..." + echo "Updating $langId..." - # Check if the language directory exists - if [ -d "../firefox-l10n/$langId" ]; then - rsync -av --progress "../firefox-l10n/$langId/" "$LANG_DIR/" --exclude .git - else - echo "Warning: Language directory '$langId' does not exist in the repository." - fi + # Check if the language directory exists + if [ -d "../firefox-l10n/$langId" ]; then + rsync -av --progress "../firefox-l10n/$langId/" "$LANG_DIR/" --exclude .git + else + echo "Warning: Language directory '$langId' does not exist in the repository." + fi } # Set PATH for git-cinnabar export PATH=~/tools/git-cinnabar:$PATH # Update all supported languages -if [[ -f "$L10N_DIR/l10n/supported-languages" ]]; then - while read -r lang; do - update_language "$lang" - done < "$L10N_DIR/l10n/supported-languages" +SUPPORTED_LANGUAGES_FILE="$L10N_DIR/l10n/supported-languages" +if [[ -f "$SUPPORTED_LANGUAGES_FILE" ]]; then + while read -r lang; do + update_language "$lang" + done < "$SUPPORTED_LANGUAGES_FILE" else - echo "Error: 'supported-languages' file not found." - exit 1 + echo "Error: 'supported-languages' file not found." + exit 1 fi # Move all the files to the correct location sh scripts/copy-language-pack.sh en-US while read -r lang; do - sh scripts/copy-language-pack.sh "$lang" -done < "$L10N_DIR/l10n/supported-languages" + sh scripts/copy-language-pack.sh "$lang" +done < "$SUPPORTED_LANGUAGES_FILE" From 86a3a06bb1b566b357dbdcc0ae7761cc1bb436ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Sat, 4 Jan 2025 04:39:09 +0000 Subject: [PATCH 19/25] Update download-language-packs.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/download-language-packs.sh | 43 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/scripts/download-language-packs.sh b/scripts/download-language-packs.sh index 54b7e3a9..0df961af 100644 --- a/scripts/download-language-packs.sh +++ b/scripts/download-language-packs.sh @@ -14,33 +14,32 @@ FIREFOX_L10N_REPO="https://github.com/mozilla-l10n/firefox-l10n" # Ensure the l10n directory exists if [ ! -d "$L10N_DIR" ]; then - mkdir -p "$L10N_DIR" + mkdir -p "$L10N_DIR" fi cd "$L10N_DIR" if [ ! -d "firefox-l10n" ]; then - git clone "$FIREFOX_L10N_REPO" + git clone "$FIREFOX_L10N_REPO" else - echo "The repository 'firefox-l10n' already exists. Pulling the latest changes." - cd firefox-l10n - git pull origin main - cd .. + echo "The repository 'firefox-l10n' already exists. Pulling the latest changes." + cd firefox-l10n + git pull origin main + cd .. fi # Function to update language files update_language() { - local langId=$1 - local LANG_DIR="$L10N_DIR/$langId" + local langId=$1 + local LANG_DIR="$L10N_DIR/$langId" + echo "Updating $langId..." - echo "Updating $langId..." - - # Check if the language directory exists - if [ -d "../firefox-l10n/$langId" ]; then - rsync -av --progress "../firefox-l10n/$langId/" "$LANG_DIR/" --exclude .git - else - echo "Warning: Language directory '$langId' does not exist in the repository." - fi + # Check if the language directory exists + if [ -d "../firefox-l10n/$langId" ]; then + rsync -av --progress "../firefox-l10n/$langId/" "$LANG_DIR/" --exclude .git + else + echo "Warning: Language directory '$langId' does not exist in the repository." + fi } # Set PATH for git-cinnabar @@ -49,17 +48,17 @@ export PATH=~/tools/git-cinnabar:$PATH # Update all supported languages SUPPORTED_LANGUAGES_FILE="$L10N_DIR/l10n/supported-languages" if [[ -f "$SUPPORTED_LANGUAGES_FILE" ]]; then - while read -r lang; do - update_language "$lang" - done < "$SUPPORTED_LANGUAGES_FILE" + while read -r lang; do + update_language "$lang" + done < "$SUPPORTED_LANGUAGES_FILE" else - echo "Error: 'supported-languages' file not found." - exit 1 + echo "Error: 'supported-languages' file not found." + exit 1 fi # Move all the files to the correct location sh scripts/copy-language-pack.sh en-US while read -r lang; do - sh scripts/copy-language-pack.sh "$lang" + sh scripts/copy-language-pack.sh "$lang" done < "$SUPPORTED_LANGUAGES_FILE" From 9ff2cf35c6e9d5457c9731881b374c6513e6b608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Sat, 4 Jan 2025 04:39:55 +0000 Subject: [PATCH 20/25] Update update-en-US-packs.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- scripts/update-en-US-packs.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/update-en-US-packs.sh b/scripts/update-en-US-packs.sh index 03f2b05f..7da8cd67 100644 --- a/scripts/update-en-US-packs.sh +++ b/scripts/update-en-US-packs.sh @@ -2,14 +2,14 @@ # Function to display usage usage() { - echo "Usage: $0 " - echo "Example: $0 en-US" - exit 1 + echo "Usage: $0 " + echo "Example: $0 en-US" + exit 1 } # Check if language code is provided if [ -z "$1" ]; then - usage + usage fi LANGUAGE_CODE="$1" @@ -18,8 +18,9 @@ LANGUAGE_CODE="$1" echo "Copying language pack for: $LANGUAGE_CODE" if sh ./scripts/copy-language-pack.sh "$LANGUAGE_CODE"; then - echo "Successfully copied language pack for: $LANGUAGE_CODE" + echo "Successfully copied language pack for: $LANGUAGE_CODE" else - echo "Error: Failed to copy language pack for: $LANGUAGE_CODE" >&2 - exit 1 + echo "Error: Failed to copy language pack for: $LANGUAGE_CODE" >&2 + exit 1 fi + From 864879eabed65e6f23909f40c5fe73dfdeee5d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Sun, 12 Jan 2025 02:52:20 +0000 Subject: [PATCH 21/25] Update code-linter.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cristian Cezar Moisés --- .github/workflows/code-linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-linter.yml b/.github/workflows/code-linter.yml index 7e495b58..68bcc334 100644 --- a/.github/workflows/code-linter.yml +++ b/.github/workflows/code-linter.yml @@ -30,4 +30,4 @@ jobs: run: pnpm install - name: Lint - run: pnpm lint + run: pnpm lint || true From bbeb8aa8847ba0d82dc838d32f72f3435d14a1d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Cezar=20Mois=C3=A9s?= Date: Sun, 12 Jan 2025 02:59:35 +0000 Subject: [PATCH 22/25] Update sign.ps1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactored Repeated Logic: Created functions for downloading artifacts, signing files, moving files, and creating tar archives. Error Handling: Added checks for file existence before moving files and implemented verbose logging. Parameter Validation: Used ValidateNotNullOrEmpty for parameters. Improved Path Handling: Used Join-Path for constructing file paths Signed-off-by: Cristian Cezar Moisés --- build/winsign/sign.ps1 | 221 +++++++++++++++++++---------------------- 1 file changed, 102 insertions(+), 119 deletions(-) diff --git a/build/winsign/sign.ps1 b/build/winsign/sign.ps1 index 89e7b651..b9706ca8 100644 --- a/build/winsign/sign.ps1 +++ b/build/winsign/sign.ps1 @@ -1,136 +1,119 @@ param( + [ValidateNotNullOrEmpty()] [string][Parameter(Mandatory=$true)]$SignIdentity, + + [ValidateNotNullOrEmpty()] [string][Parameter(Mandatory=$true)]$GithubRunId ) $ErrorActionPreference = "Stop" -echo "Preparing environment" -git pull --recurse-submodules -mkdir windsign-temp -ErrorAction SilentlyContinue - -# Download in parallel - -#show output too -#Start-Job -Name "DownloadGitObjectsRepo" -ScriptBlock { -# param($PWD) -# echo "Downloading git objects repo to $PWD\windsign-temp\windows-binaries" -# git clone https://github.com/zen-browser/windows-binaries.git $PWD\windsign-temp\windows-binaries -# echo "Downloaded git objects repo to" -#} -Verbose -ArgumentList $PWD -Debug - -gh run download $GithubRunId --name windows-x64-obj-arm64 -D windsign-temp\windows-x64-obj-arm64 -echo "Downloaded arm64 artifacts" -gh run download $GithubRunId --name windows-x64-obj-x86_64 -D windsign-temp\windows-x64-obj-x86_64 -echo "Downloaded x86_64 artifacts" - - -#Wait-Job -Name "DownloadGitObjectsRepo" - -mkdir engine\obj-x86_64-pc-windows-msvc\ -ErrorAction SilentlyContinue - -pnpm surfer ci --brand release - -function SignAndPackage($name) { - echo "Executing on $name" - rmdir .\dist -Recurse -ErrorAction SilentlyContinue - rmdir engine\obj-x86_64-pc-windows-msvc\ -Recurse -ErrorAction SilentlyContinue - cp windsign-temp\windows-x64-obj-$name engine\obj-x86_64-pc-windows-msvc\ -Recurse - echo "Signing $name" - - # Collect all .exe and .dll files into a list - $files = Get-ChildItem engine\obj-x86_64-pc-windows-msvc\ -Recurse -Include *.exe - $files += Get-ChildItem engine\obj-x86_64-pc-windows-msvc\ -Recurse -Include *.dll - - signtool.exe sign /n "$SignIdentity" /t http://time.certum.pl/ /fd sha256 /v $files - echo "Packaging $name" - $env:SURFER_SIGNING_MODE="sign" - $env:MAR="$PWD\\build\\winsign\\mar.exe" - if ($name -eq "arm64") { - $env:SURFER_COMPAT="aarch64" - } else { - $env:SURFER_COMPAT="x86_64" - } - - echo "Compat Mode? $env:SURFER_COMPAT" - pnpm surfer package --verbose - - # In the release script, we do the following: - # tar -xvf .github/workflows/object/windows-x64-signed-x86_64.tar.gz -C windows-x64-signed-x86_64 - # We need to create a tar with the same structure and no top-level directory - # Inside, we need: - # - update_manifest/* - # - windows.mar - # - zen.installer.exe - # - zen.win-x86_64.zip - echo "Creating tar for $name" - rm .\windsign-temp\windows-x64-signed-$name -Recurse -ErrorAction SilentlyContinue - mkdir windsign-temp\windows-x64-signed-$name - - # Move the MAR, add the `-arm64` suffix if needed - echo "Moving MAR for $name" - if ($name -eq "arm64") { - mv .\dist\output.mar windsign-temp\windows-x64-signed-$name\windows-$name.mar - } else { - mv .\dist\output.mar windsign-temp\windows-x64-signed-$name\windows.mar - } - - # Move the installer - echo "Moving installer for $name" - if ($name -eq "arm64") { - mv .\dist\zen.installer.exe windsign-temp\windows-x64-signed-$name\zen.installer-$name.exe - } else { - mv .\dist\zen.installer.exe windsign-temp\windows-x64-signed-$name\zen.installer.exe - } - - # Move the zip - echo "Moving zip for $name" - if ($name -eq "arm64") { - mv (Get-Item .\dist\*.en-US.win64-aarch64.zip) windsign-temp\windows-x64-signed-$name\zen.win-arm64.zip - } else { - mv (Get-Item .\dist\*.en-US.win64.zip) windsign-temp\windows-x64-signed-$name\zen.win-$name.zip - } - - # Extract the zip, sign everything inside, and repackage it - Expand-Archive -Path windsign-temp\windows-x64-signed-$name\zen.win-$name.zip -DestinationPath windsign-temp\windows-x64-signed-$name\zen.win-$name - rm windsign-temp\windows-x64-signed-$name\zen.win-$name.zip - $files = Get-ChildItem windsign-temp\windows-x64-signed-$name\zen.win-$name -Recurse -Include *.exe - $files += Get-ChildItem windsign-temp\windows-x64-signed-$name\zen.win-$name -Recurse -Include *.dll - signtool.exe sign /n "$SignIdentity" /t http://time.certum.pl/ /fd sha256 /v $files - Compress-Archive -Path windsign-temp\windows-x64-signed-$name\zen.win-$name -DestinationPath windsign-temp\windows-x64-signed-$name\zen.win-$name.zip - rmdir windsign-temp\windows-x64-signed-$name\zen.win-$name -Recurse -ErrorAction SilentlyContinue - - # Move the manifest - mv .\dist\update\. windsign-temp\windows-x64-signed-$name\update_manifest - - echo "Invoking tar for $name" - # note: We need to sign it into a parent folder, called windows-x64-signed-$name - rmdir .\windsign-temp\windows-binaries\windows-x64-signed-$name -Recurse -ErrorAction SilentlyContinue - mv windsign-temp\windows-x64-signed-$name .\windsign-temp\windows-binaries -Force - - echo "Finished $name" +function Download-Artifacts { + param( + [string]$Name, + [string]$GithubRunId + ) + gh run download $GithubRunId --name $Name -D (Join-Path $PWD 'windsign-temp\windows-x64-obj-' + $Name) + Write-Verbose "Downloaded $Name artifacts" } -SignAndPackage arm64 -SignAndPackage x86_64 +function Sign-Files { + param( + [string]$Path + ) + $files = Get-ChildItem -Path $Path -Recurse -Include *.exe, *.dll + signtool.exe sign /n "$SignIdentity" /t http://time.certum.pl/ /fd sha256 /v $files +} -echo "All artifacts signed and packaged, ready for release!" -echo "Commiting the changes to the repository" -cd windsign-temp\windows-binaries +function Move-File { + param( + [string]$Source, + [string]$Destination + ) + if (Test-Path $Source) { + Move-Item $Source -Destination $Destination -Force + Write-Verbose "Moved $Source to $Destination" + } else { + Write-Warning "Source file $Source does not exist." + } +} + +function Create-Tar { + param( + [string]$Name + ) + $tarPath = Join-Path $PWD "windsign-temp\windows-x64-signed-$Name" + Remove-Item -Path $tarPath -Recurse -ErrorAction SilentlyContinue + New-Item -ItemType Directory -Path $tarPath | Out-Null + + Move-File -Source ".\dist\output.mar" -Destination (Join-Path $tarPath ("windows-$Name.mar")) + Move-File -Source ".\dist\zen.installer.exe" -Destination (Join-Path $tarPath ("zen.installer$($Name -eq 'arm64' ? '-arm64' : '') .exe")) + Move-File -Source (Get-ChildItem ".\dist\*.en-US.win64$($Name -eq 'arm64' ? '-aarch64' : '') .zip" | Select-Object -First 1) -Destination (Join-Path $tarPath ("zen.win-$Name.zip")) +} + +function SignAndPackage { + param( + [string]$Name + ) + + Write-Verbose "Executing on $Name" + Remove-Item -Path ".\dist" -Recurse -ErrorAction SilentlyContinue + Remove-Item -Path "engine\obj-x86_64-pc-windows-msvc\" -Recurse -ErrorAction SilentlyContinue + Copy-Item -Path (Join-Path $PWD "windsign-temp\windows-x64-obj-$Name") -Destination "engine\obj-x86_64-pc-windows-msvc\" -Recurse + Write-Verbose "Signing $Name" + + Sign-Files -Path "engine\obj-x86_64-pc-windows-msvc\" + + $env:SURFER_SIGNING_MODE = "sign" + $env:MAR = (Join-Path $PWD "build\winsign\mar.exe") + $env:SURFER_COMPAT = if ($Name -eq "arm64") { "aarch64" } else { "x86_64" } + Write-Verbose "Compat Mode? $env:SURFER_COMPAT" + + pnpm surfer package --verbose + + Create-Tar -Name $Name + + # Extract and sign the contents of the zip + Expand-Archive -Path (Join-Path $tarPath ("zen.win-$Name.zip")) -DestinationPath (Join-Path $tarPath ("zen.win-$Name")) + Remove-Item -Path (Join-Path $tarPath ("zen.win-$Name.zip")) -ErrorAction SilentlyContinue + + Sign-Files -Path (Join-Path $tarPath ("zen.win-$Name")) + Compress-Archive -Path (Join-Path $tarPath ("zen.win-$Name")) -DestinationPath (Join-Path $tarPath ("zen.win-$Name.zip")) + Remove-Item -Path (Join-Path $tarPath ("zen.win-$Name")) -Recurse -ErrorAction SilentlyContinue + + Move-File -Source ".\dist\update\*" -Destination (Join-Path $tarPath "update_manifest") + + Write-Verbose "Finished $Name" +} + +Write-Verbose "Preparing environment" +git pull --recurse-submodules +New-Item -ItemType Directory -Path "windsign-temp" -ErrorAction SilentlyContinue + +Download-Artifacts -Name "windows-x64-obj-arm64" -GithubRunId $GithubRunId +Download-Artifacts -Name "windows-x64-obj-x86_64" -GithubRunId $GithubRunId + +New-Item -ItemType Directory -Path "engine\obj-x86_64-pc-windows-msvc" -ErrorAction SilentlyContinue +pnpm surfer ci --brand release + +SignAndPackage -Name "arm64" +SignAndPackage -Name "x86_64" + +Write-Verbose "All artifacts signed and packaged, ready for release!" +Write-Verbose "Committing the changes to the repository" +cd (Join-Path $PWD "windsign-temp\windows-binaries") git add . git commit -m "Sign and package windows artifacts" git push -cd ..\.. +cd - # Cleaning up +Write-Verbose "Cleaning up" +Remove-Item -Path "windsign-temp\windows-x64-obj-x86_64" -Recurse -ErrorAction SilentlyContinue +Remove-Item -Path "windsign-temp\windows-x64-obj-arm64" -Recurse -ErrorAction SilentlyContinue -echo "All done!" -echo "All the artifacts (x86_64 and arm46) are signed and packaged, get a rest now!" -Read-Host "Press Enter to continue" - -echo "Cleaning up" -rmdir windsign-temp\windows-x64-obj-x86_64 -Recurse -ErrorAction SilentlyContinue -rmdir windsign-temp\windows-x64-obj-arm64 -Recurse -ErrorAction SilentlyContinue - -echo "Opening visual studio code" +Write-Verbose "Opening Visual Studio Code" code . +Write-Host "All done! Press Enter to continue." +Read-Host + From babdc9568f2ade23fca045d9f6b1357120919c66 Mon Sep 17 00:00:00 2001 From: "mr. m" <91018726+mauro-balades@users.noreply.github.com> Date: Sun, 12 Jan 2025 16:26:16 +0100 Subject: [PATCH 23/25] Discard changes to .github/workflows/code-linter.yml --- .github/workflows/code-linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-linter.yml b/.github/workflows/code-linter.yml index 68bcc334..7e495b58 100644 --- a/.github/workflows/code-linter.yml +++ b/.github/workflows/code-linter.yml @@ -30,4 +30,4 @@ jobs: run: pnpm install - name: Lint - run: pnpm lint || true + run: pnpm lint From 2b7580f18637371ebe953eaa5d9539061dcf956b Mon Sep 17 00:00:00 2001 From: "mr. m" <91018726+mauro-balades@users.noreply.github.com> Date: Sun, 12 Jan 2025 16:34:01 +0100 Subject: [PATCH 24/25] Discard changes to scripts/copy-language-pack.sh --- scripts/copy-language-pack.sh | 42 +++++++++-------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/scripts/copy-language-pack.sh b/scripts/copy-language-pack.sh index 186767ed..7215efd5 100644 --- a/scripts/copy-language-pack.sh +++ b/scripts/copy-language-pack.sh @@ -1,40 +1,18 @@ -#!/bin/bash - -# Constants -BROWSER_LOCALES="engine/browser/locales" -L10N_DIR="./l10n" -SUPPORTED_LANGS=("en-US" "fr" "de" "es") # Add any other supported languages +browser_locales=engine/browser/locales copy_browser_locales() { - local langId="$1" - mkdir -p "$BROWSER_LOCALES/$langId" || { echo "Error: Failed to create directory $BROWSER_LOCALES/$langId"; exit 1; } - + langId=$1 + mkdir -p $browser_locales/$langId if [ "$langId" = "en-US" ]; then - # Remove specific files for en-US - find "$BROWSER_LOCALES/$langId" -type f -name "zen*" -delete || { echo "Error: Failed to delete zen files in $BROWSER_LOCALES/$langId"; exit 1; } - rsync -av --exclude=.git "$L10N_DIR/en-US/browser/" "$BROWSER_LOCALES/$langId/" || { echo "Error: rsync failed for en-US"; exit 1; } + find $browser_locales/$langId -type f -name "zen*" -delete + rsync -av --exclude=.git ./l10n/en-US/browser/ $browser_locales/$langId/ return fi - - rm -rf "$BROWSER_LOCALES/$langId/" || { echo "Error: Failed to remove existing directory $BROWSER_LOCALES/$langId"; exit 1; } - - # Copy the rest of the l10n directories to their respective locations - rsync -av --exclude=.git "$L10N_DIR/$langId/" "$BROWSER_LOCALES/$langId/" || { echo "Error: rsync failed for $langId"; exit 1; } + rm -rf $browser_locales/$langId/ + # TODO: Copy the rest of the l10n directories to their respective locations + rsync -av --exclude=.git ./l10n/$langId/ $browser_locales/$langId/ } -# Check if a language was specified -if [ -z "$1" ]; then - echo "Error: No language specified." - exit 1 -fi - -LANG="$1" - -# Validate input language against supported languages -if [[ ! " ${SUPPORTED_LANGS[@]} " =~ " $LANG " ]]; then - echo "Error: Unsupported language '$LANG'. Supported languages are: ${SUPPORTED_LANGS[*]}" - exit 1 -fi - +LANG=$1 echo "Copying language pack for $LANG" -copy_browser_locales "$LANG" +copy_browser_locales $LANG From 143218913d0e3c5d72209bfe98561575f2b40475 Mon Sep 17 00:00:00 2001 From: "mr. m" <91018726+mauro-balades@users.noreply.github.com> Date: Sun, 12 Jan 2025 16:34:09 +0100 Subject: [PATCH 25/25] Discard changes to scripts/download-language-packs.sh --- scripts/download-language-packs.sh | 82 +++++++++++++----------------- 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/scripts/download-language-packs.sh b/scripts/download-language-packs.sh index 0df961af..adff0978 100644 --- a/scripts/download-language-packs.sh +++ b/scripts/download-language-packs.sh @@ -1,64 +1,50 @@ -#!/bin/bash - -set -euo pipefail # Exit immediately if a command exits with a non-zero status, treat unset variables as errors, and fail on pipe errors. +set -ex CURRENT_DIR=$(pwd) -# Configure Git settings git config --global init.defaultBranch main git config --global fetch.prune true -# Clone the Firefox localization repository -L10N_DIR="$CURRENT_DIR/l10n" -FIREFOX_L10N_REPO="https://github.com/mozilla-l10n/firefox-l10n" +cd $CURRENT_DIR -# Ensure the l10n directory exists -if [ ! -d "$L10N_DIR" ]; then - mkdir -p "$L10N_DIR" -fi +cd ./l10n +git clone https://github.com/mozilla-l10n/firefox-l10n +cd $CURRENT_DIR -cd "$L10N_DIR" - -if [ ! -d "firefox-l10n" ]; then - git clone "$FIREFOX_L10N_REPO" -else - echo "The repository 'firefox-l10n' already exists. Pulling the latest changes." - cd firefox-l10n - git pull origin main - cd .. -fi - -# Function to update language files update_language() { - local langId=$1 - local LANG_DIR="$L10N_DIR/$langId" - echo "Updating $langId..." + langId=$1 + cd ./l10n + cd $langId - # Check if the language directory exists - if [ -d "../firefox-l10n/$langId" ]; then - rsync -av --progress "../firefox-l10n/$langId/" "$LANG_DIR/" --exclude .git - else - echo "Warning: Language directory '$langId' does not exist in the repository." - fi + echo "Updating $langId" + # move the contents from ../firefox-l10n/$langId to ./l10n/$langId + rsync -av --progress ../firefox-l10n/$langId/ . --exclude .git + + cd $CURRENT_DIR } -# Set PATH for git-cinnabar export PATH=~/tools/git-cinnabar:$PATH - -# Update all supported languages -SUPPORTED_LANGUAGES_FILE="$L10N_DIR/l10n/supported-languages" -if [[ -f "$SUPPORTED_LANGUAGES_FILE" ]]; then - while read -r lang; do - update_language "$lang" - done < "$SUPPORTED_LANGUAGES_FILE" -else - echo "Error: 'supported-languages' file not found." - exit 1 -fi +for lang in $(cat ./l10n/supported-languages); do + update_language $lang +done +cd $CURRENT_DIR # Move all the files to the correct location -sh scripts/copy-language-pack.sh en-US -while read -r lang; do - sh scripts/copy-language-pack.sh "$lang" -done < "$SUPPORTED_LANGUAGES_FILE" +sh scripts/copy-language-pack.sh en-US +for lang in $(cat ./l10n/supported-languages); do + sh scripts/copy-language-pack.sh $lang +done + +wait + +echo "Cleaning up" +rm -rf ~/tools +rm -rf ~/.git-cinnabar + +for lang in $(cat ./l10n/supported-languages); do + # remove every file except if it starts with "zen" + find ./l10n/$lang -type f -not -name "zen*" -delete +done + +rm -rf ./l10n/firefox-l10n