Last active
December 22, 2021 23:39
-
-
Save pascalchevrel/ea63c0470155218dafa51fd5953ff778 to your computer and use it in GitHub Desktop.
Get all the changesets in Nightly between the current build and the previous one
This file contains 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
<?php | |
function getBuilId(string $raw_build_id): array { | |
return [ | |
'year' => substr($raw_build_id, 0, 4), | |
'month' => substr($raw_build_id, 4, 2), | |
'day' => substr($raw_build_id, 6, 2), | |
'hour' => substr($raw_build_id, 8, 2), | |
'minute' => substr($raw_build_id, 10, 2), | |
'second' => substr($raw_build_id, 12, 2), | |
]; | |
} | |
function getRemoteJSON(string $url): array { | |
return json_decode(file_get_contents($url), true); | |
} | |
function extractLinksFromHTML(string $html): array { | |
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>"; | |
if (preg_match_all("/$regexp/siU", $html, $matches)) { | |
return $matches[2]; | |
} | |
return []; | |
} | |
$nightly_version = getRemoteJSON('https://product-details.mozilla.org/1.0/firefox_versions.json')['FIREFOX_NIGHTLY']; | |
$nightly_archive = 'https://archive.mozilla.org/pub/firefox/nightly/'; | |
$file_name = 'firefox-' . $nightly_version . '.en-US.win64.json'; | |
$latest_metadata = getRemoteJSON($nightly_archive . 'latest-mozilla-central/' . $file_name); | |
$latest_build_id = getBuilId($latest_metadata['buildid']); | |
$latest_changeset = $latest_metadata['moz_source_stamp']; | |
$latest_build_date = new DateTime(implode(array_slice($latest_build_id, 0, 3), '/')); | |
$yesterday = $latest_build_date->add(DateInterval::createFromDateString('yesterday'))->format('Y/m/'); | |
// Get all the links from yesterday | |
$links = extractLinksFromHTML(file_get_contents($nightly_archive . $yesterday)); | |
$links = preg_grep("/mozilla-central\//", $links); | |
$links = preg_grep("/" . $latest_build_date->format('Y-m-d') ."/", $links); | |
// We often have 2 builds a day, we want the first one (not taskcluster-based, they are built later) | |
$yesterday_build = 'https://archive.mozilla.org' . array_shift($links) . $file_name; | |
$previous_changeset = getRemoteJSON($yesterday_build)['moz_source_stamp']; | |
$target_url = 'https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=' | |
. $previous_changeset | |
. '&tochange=' | |
. $latest_changeset; | |
header('Location: ' . $target_url); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment