diff --git a/.github/workflows/check-beta.yml b/.github/workflows/check-beta.yml index 77c4c14c..166625f5 100644 --- a/.github/workflows/check-beta.yml +++ b/.github/workflows/check-beta.yml @@ -18,7 +18,8 @@ jobs: steps: - name: Obtain the latest beta version number run: - echo "LATEST=$(curl https://product-details.mozilla.org/1.0/firefox_versions.json | jq -r '.FIREFOX_DEVEDITION')" >> "$GITHUB_ENV" + pip install beautifulsoup4 + echo "LATEST=$(python3 ./get_beta_version.py)" >> "$GITHUB_ENV" - name: Checkout repository uses: actions/checkout@v4 - name: Check if the latest version was tested diff --git a/Pipfile b/Pipfile index 60a86178..2ee961a3 100644 --- a/Pipfile +++ b/Pipfile @@ -24,6 +24,7 @@ google-cloud-storage = "2.18.0" google-auth = "2.32.0" psutil = "<6.1" pytest-json-report = "==1.5.0" +beautifulsoup4 = "4.12.3" [dev-packages] werkzeug = "==3.0.3" diff --git a/collect_executables.py b/collect_executables.py index 36273d9a..c6ed1252 100755 --- a/collect_executables.py +++ b/collect_executables.py @@ -7,6 +7,7 @@ from platform import uname from sys import argv, exit from time import sleep +from bs4 import BeautifulSoup import requests @@ -16,18 +17,26 @@ def get_fx_platform(): u = uname() if u.system == "Darwin": - return "osx" + return "mac" if u.system == "Linux": if "64" in u.machine: - return "linux64" - return "linux" + return "linux-x86_64" + return "linux-i686" if u.system == "Windows": if u.machine == "AMD64" and not environ.get("GITHUB_ACTIONS"): return "win64-aarch64" if "64" in u.machine: return "win64" - return "win" + return "win32" +def get_fx_executable_extension(): + u = uname() + if u.system == "Darwin": + return "dmg" + if u.system == "Linux": + return "xz" + if u.system == "Windows": + return "exe" def get_gd_platform(): u = uname() @@ -82,9 +91,35 @@ def get_gd_platform(): channel = "-beta" elif channel: channel = f"-{channel.lower()}" + + latest_beta_ver = environ.get("LATEST") + if not latest_beta_ver: + prefix = "mac" if get_gd_platform()[:3] in ("mac", "lin") else "win" + with open(f"{prefix}-latest-reported-version") as fh: + latest_beta_ver = fh.read() + language = environ.get("FX_LOCALE") if not language: language = "en-US" + + fx_download_dir_url = f"https://archive.mozilla.org/pub/firefox/releases/{latest_beta_ver}/{get_fx_platform()}/{language}/" + + # Fetch the page + response = requests.get(fx_download_dir_url) + response.raise_for_status() + + # Parse the HTML content + soup = BeautifulSoup(response.text, 'html.parser') - fx_download_url = f"https://download.mozilla.org/?product=firefox{channel}-latest-ssl&os={get_fx_platform()}&lang={language}" - print(fx_download_url) + executable_name = "" + # Extract the text of each line + for line in soup.find_all('a'): + line_text = line.getText().split(".") + if not line_text[0]: + continue + # Get the executable name + if line_text[-1] == get_fx_executable_extension(): + executable_name = line.getText().replace(" ", "%20") + + fx_download_executable_url = rf"{fx_download_dir_url}{executable_name}" + print(fx_download_executable_url) diff --git a/get_beta_version.py b/get_beta_version.py new file mode 100644 index 00000000..05d3f892 --- /dev/null +++ b/get_beta_version.py @@ -0,0 +1,27 @@ +import requests +from bs4 import BeautifulSoup + +beta_url = "https://ftp.mozilla.org/pub/firefox/releases/" + +# Fetch the page +response = requests.get(beta_url) +response.raise_for_status() + +# Parse the HTML content +soup = BeautifulSoup(response.text, 'html.parser') + +latest_beta_num = -1 +latest_beta_ver = "" + +# Extract the text of each line +for line in soup.find_all('a'): + line_text = line.getText().split(".") + if len(line_text) < 2 or not line_text[0]: + continue + beta_num = int(line_text[0]) + # Find the latest beta version + if beta_num >= latest_beta_num: + latest_beta_num = beta_num + latest_beta_ver = line.getText()[:-1] + +print(latest_beta_ver) \ No newline at end of file