Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more options to check_availability script #5827

Merged
merged 2 commits into from May 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
149 changes: 117 additions & 32 deletions utils/check_availability.js
Expand Up @@ -16,12 +16,14 @@
*/

const assert = require('assert');
const puppeteer = require('..');
const https = require('https');
const SUPPORTER_PLATFORMS = ['linux', 'mac', 'win32', 'win64'];

const fetchers = SUPPORTER_PLATFORMS.map((platform) =>
puppeteer.createBrowserFetcher({ platform })
const packageJSON = require('../package.json');
const BrowserFetcher = require('../lib/BrowserFetcher').BrowserFetcher;

const SUPPORTER_PLATFORMS = ['linux', 'mac', 'win32', 'win64'];
const fetchers = SUPPORTER_PLATFORMS.map(
(platform) => new BrowserFetcher('', { platform })
);

const colors = {
Expand Down Expand Up @@ -51,29 +53,79 @@ class Table {
}
}

if (process.argv.length === 2) {
checkOmahaProxyAvailability();
return;
}
if (process.argv.length !== 4) {
console.log(`
Usage: node check_revisions.js [fromRevision] [toRevision]
const helpMessage = `
This script checks availability of prebuilt Chromium snapshots.

This script checks availability of different prebuild chromium revisions.
Running command without arguments will check against omahaproxy revisions.`);
return;
}
Usage: node check_availability.js [<options>] [<browser version(s)>]

const fromRevision = parseInt(process.argv[2], 10);
const toRevision = parseInt(process.argv[3], 10);
checkRangeAvailability(
fromRevision,
toRevision,
false /* stopWhenAllAvailable */
);
options
-f full mode checks availability of all the platforms, default mode
-r roll mode checks for the most recent Chromium roll candidate
-h show this help

browser version(s)
<revision> single revision number means checking for this specific revision
<from> <to> checks all the revisions within a given range, inclusively

Examples
To check Chromium availability of a certain revision
node check_availability.js [revision]

To find a Chromium roll candidate for current Stable Linux version
node check_availability.js -r

To check Chromium availability from the latest revision in a descending order
node check_availability.js
`;

function main() {
const args = process.argv.slice(2);

if (args.length > 3) {
console.log(helpMessage);
return;
}

if (args.length === 0) {
checkOmahaProxyAvailability();
return;
}

if (args[0].startsWith('-')) {
const option = args[0].substring(1);
switch (option) {
case 'f':
break;
case 'r':
checkRollCandidate();
return;
default:
console.log(helpMessage);
return;
}
args.splice(0, 1); // remove options arg since we are done with options
}

if (args.length === 1) {
const revision = parseInt(args[0], 10);
checkRangeAvailability({
fromRevision: revision,
toRevision: revision,
stopWhenAllAvailable: false,
});
} else {
const fromRevision = parseInt(args[0], 10);
const toRevision = parseInt(args[1], 10);
checkRangeAvailability({
fromRevision,
toRevision,
stopWhenAllAvailable: false,
});
}
}

async function checkOmahaProxyAvailability() {
const lastchanged = (
const latestRevisions = (
await Promise.all([
fetch(
'https://storage.googleapis.com/chromium-browser-snapshots/Mac/LAST_CHANGE'
Expand All @@ -89,24 +141,55 @@ async function checkOmahaProxyAvailability() {
),
])
).map((s) => parseInt(s, 10));
const from = Math.max(...lastchanged);
checkRangeAvailability(from, 0, true /* stopWhenAllAvailable */);
const from = Math.max(...latestRevisions);
checkRangeAvailability({
fromRevision: from,
toRevision: 0,
stopWhenAllAvailable: false,
});
}

async function checkRollCandidate() {
const omahaResponse = await fetch(
'https://omahaproxy.appspot.com/all.json?channel=stable&os=linux'
);
const stableLinuxInfo = JSON.parse(omahaResponse)[0];
if (!stableLinuxInfo) {
console.error('no stable linux information available from omahaproxy');
return;
}

const stableLinuxRevision = parseInt(
stableLinuxInfo.versions[0].branch_base_position,
10
);
const currentRevision = parseInt(packageJSON.puppeteer.chromium_revision, 10);

checkRangeAvailability({
fromRevision: stableLinuxRevision,
toRevision: currentRevision,
stopWhenAllAvailable: true,
});
}

/**
* @param {number} fromRevision
* @param {number} toRevision
* @param {boolean} stopWhenAllAvailable
* @param {*} options
*/
async function checkRangeAvailability(
async function checkRangeAvailability({
fromRevision,
toRevision,
stopWhenAllAvailable
) {
stopWhenAllAvailable,
}) {
const table = new Table([10, 7, 7, 7, 7]);
table.drawRow([''].concat(SUPPORTER_PLATFORMS));

const inc = fromRevision < toRevision ? 1 : -1;
for (let revision = fromRevision; revision !== toRevision; revision += inc) {
const revisionToStop = toRevision + inc; // +inc so the range is fully inclusive
for (
let revision = fromRevision;
revision !== revisionToStop;
revision += inc
) {
const allAvailable = await checkAndDrawRevisionAvailability(
table,
'',
Expand Down Expand Up @@ -200,3 +283,5 @@ function padCenter(text, length) {
const right = Math.ceil((length - printableCharacters.length) / 2);
return spaceString(left) + text + spaceString(right);
}

main();