Last active
March 4, 2026 13:38
-
-
Save pascalchevrel/bc96b848b723d6f9901670c006a02a3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env php | |
| <?php | |
| /* | |
| PHP script to fetch Firefox Desktop and Android shipped versions from API | |
| and output readable results to your terminal. | |
| chmod +x this file and set it as a bash alias: | |
| alias v="path/to/firefox_versions.php" | |
| The output will look like this: | |
| DESKTOP | |
| ESR 115 115.18.0esr | |
| ESR 128 128.5.1esr | |
| Release 133.0 | |
| Beta 134.0b5 | |
| DevEdition 134.0b5 | |
| Nightly 135.0a1 | |
| ANDROID | |
| Release 133.0.1 | |
| Beta 134.0b4 | |
| Nightly 135.0a1 | |
| DESKTOP ROLLOUT | |
| Release 100 | |
| Beta 100 | |
| DevEdition 100 | |
| Nightly OK | |
| */ | |
| /** | |
| * Extracts bug numbers and generates their Bugzilla URLs. | |
| * * @param string $text The source string. | |
| * @return array A list of arrays, each containing 'id' and 'url'. | |
| */ | |
| function extractBugNumbers(string $text): array { | |
| $results = []; | |
| $baseUrl = "https://bugzilla.mozilla.org/show_bug.cgi?id="; | |
| if (preg_match_all("/bug\s+(\d+)/i", $text, $matches)) { | |
| // Use array_unique if you don't want the same bug listed twice | |
| $results = array_unique($matches[1]); | |
| } | |
| return $results; | |
| } | |
| function output(string $header, ?string $data = null):void { | |
| $boldgreen = "\e[1;32m"; | |
| $cyan = "\e[96m"; | |
| $endcolor = "\e[0m"; | |
| if(! $data) { | |
| echo $boldgreen . $header . $endcolor . PHP_EOL; | |
| } else { | |
| $header = ' ' . $header . ''; | |
| $header = str_pad($header, 12, ' '); | |
| echo $cyan . $header . $endcolor . $data . PHP_EOL; | |
| } | |
| } | |
| function red(string $s):string { | |
| return "\e[1;31m" . $s . "\e[0m"; | |
| } | |
| function green(string $s):string { | |
| return "\e[1;32m" . $s . "\e[0m"; | |
| } | |
| function multiCurl(array $urls): array { | |
| $multi_handle = curl_multi_init(); | |
| $handles = []; | |
| $options = [ | |
| CURLOPT_RETURNTRANSFER => true, | |
| CURLOPT_HEADER => false, | |
| CURLOPT_FOLLOWLOCATION => true, | |
| CURLOPT_CONNECTTIMEOUT => 5, | |
| CURLOPT_TIMEOUT => 15, | |
| CURLOPT_SSL_VERIFYPEER => true, | |
| CURLOPT_HTTPHEADER => ['Accept: application/json'], | |
| ]; | |
| // $key is your "nice name", $url is the endpoint | |
| foreach($urls as $key => $url) { | |
| $handles[$key] = curl_init($url); | |
| curl_setopt_array($handles[$key], $options); | |
| curl_multi_add_handle($multi_handle, $handles[$key]); | |
| } | |
| $running = null; | |
| do { | |
| $status = curl_multi_exec($multi_handle, $running); | |
| if ($running) { | |
| curl_multi_select($multi_handle); | |
| } | |
| } while ($running && $status == CURLM_OK); | |
| $results = []; | |
| foreach ($handles as $key => $handle) { | |
| $content = curl_multi_getcontent($handle); | |
| $http_code = curl_getinfo($handle, CURLINFO_HTTP_CODE); | |
| // Attempt to decode the JSON | |
| $decoded = json_decode($content, true); | |
| // Store result using the original "nice name" key | |
| $results[$key] = [ | |
| 'status' => $http_code, | |
| 'data' => (json_last_error() === JSON_ERROR_NONE) ? $decoded : null, | |
| 'error' => (json_last_error() !== JSON_ERROR_NONE) ? 'JSON Decode Error' : null | |
| ]; | |
| curl_multi_remove_handle($multi_handle, $handle); | |
| curl_close($handle); | |
| } | |
| curl_multi_close($multi_handle); | |
| return $results; | |
| } | |
| $aus = 'https://aus-api.mozilla.org/api/v1/'; | |
| $pd = 'https://product-details.mozilla.org/1.0/'; | |
| $endpoints = [ | |
| 'desktop' => $pd . 'firefox_versions.json', | |
| 'android' => $pd . 'mobile_versions.json', | |
| 'release_rollout' => $aus . 'rules/firefox-release', | |
| 'beta_rollout' => $aus . 'rules/firefox-beta', | |
| 'deved_rollout' => $aus . 'rules/devedition', | |
| 'nightly_status' => $aus . 'emergency_shutoff/Firefox/nightly', | |
| ]; | |
| $response = multiCurl($endpoints); | |
| $desktop = $response['desktop']['data']; | |
| $android = $response['android']['data']; | |
| $release_rollout = $response['release_rollout']['data']; | |
| $beta_rollout = $response['beta_rollout']['data']; | |
| $deved_rollout = $response['deved_rollout']['data']; | |
| $nightly_status = !isset($response['nightly_status']['comment']); | |
| output('DESKTOP'); | |
| output('ESR 115', $desktop['FIREFOX_ESR115']); | |
| output('ESR 140', $desktop['FIREFOX_ESR']); | |
| // output('ESR 140', $desktop['FIREFOX_ESR_NEXT']); | |
| output('Release', $desktop['LATEST_FIREFOX_VERSION']); | |
| output('Beta', $desktop['LATEST_FIREFOX_RELEASED_DEVEL_VERSION']); | |
| output('DevEdition', $desktop['FIREFOX_DEVEDITION']); | |
| output('Nightly', $desktop['FIREFOX_NIGHTLY']); | |
| output('ANDROID'); | |
| output('Release', $android['version']); | |
| output('Beta', $android['beta_version']); | |
| output('Nightly', $android['nightly_version']); | |
| output('DESKTOP ROLLOUT'); | |
| output('Release', $release_rollout['backgroundRate']); | |
| output('Beta', $beta_rollout['backgroundRate']); | |
| output('DevEdition', $deved_rollout['backgroundRate']); | |
| output('Nightly', $nightly_status ? green('OK') : red('STOPPED')); | |
| /* Display the reason for nightly updates stopped and bugs */ | |
| if (! $nightly_status) { | |
| echo ' ' . $response['nightly_status']['comment'] . PHP_EOL; | |
| $bugs = extractBugNumbers($response['nightly_status']['comment']); | |
| if (! empty($bugs)) { | |
| echo red(" https://bugzilla.mozilla.org/buglist.cgi?bug_id=" . implode('%2C', $bugs)) . PHP_EOL; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment