feat: add more options to check_availability script (#5827)
This commit is contained in:
parent
510354054f
commit
ce097426af
@ -16,12 +16,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const puppeteer = require('..');
|
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
const SUPPORTER_PLATFORMS = ['linux', 'mac', 'win32', 'win64'];
|
|
||||||
|
|
||||||
const fetchers = SUPPORTER_PLATFORMS.map((platform) =>
|
const packageJSON = require('../package.json');
|
||||||
puppeteer.createBrowserFetcher({ platform })
|
const BrowserFetcher = require('../lib/BrowserFetcher').BrowserFetcher;
|
||||||
|
|
||||||
|
const SUPPORTER_PLATFORMS = ['linux', 'mac', 'win32', 'win64'];
|
||||||
|
const fetchers = SUPPORTER_PLATFORMS.map(
|
||||||
|
(platform) => new BrowserFetcher('', { platform })
|
||||||
);
|
);
|
||||||
|
|
||||||
const colors = {
|
const colors = {
|
||||||
@ -51,29 +53,79 @@ class Table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.argv.length === 2) {
|
const helpMessage = `
|
||||||
checkOmahaProxyAvailability();
|
This script checks availability of prebuilt Chromium snapshots.
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (process.argv.length !== 4) {
|
|
||||||
console.log(`
|
|
||||||
Usage: node check_revisions.js [fromRevision] [toRevision]
|
|
||||||
|
|
||||||
This script checks availability of different prebuild chromium revisions.
|
Usage: node check_availability.js [<options>] [<browser version(s)>]
|
||||||
Running command without arguments will check against omahaproxy revisions.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fromRevision = parseInt(process.argv[2], 10);
|
options
|
||||||
const toRevision = parseInt(process.argv[3], 10);
|
-f full mode checks availability of all the platforms, default mode
|
||||||
checkRangeAvailability(
|
-r roll mode checks for the most recent Chromium roll candidate
|
||||||
fromRevision,
|
-h show this help
|
||||||
toRevision,
|
|
||||||
false /* stopWhenAllAvailable */
|
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() {
|
async function checkOmahaProxyAvailability() {
|
||||||
const lastchanged = (
|
const latestRevisions = (
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
fetch(
|
fetch(
|
||||||
'https://storage.googleapis.com/chromium-browser-snapshots/Mac/LAST_CHANGE'
|
'https://storage.googleapis.com/chromium-browser-snapshots/Mac/LAST_CHANGE'
|
||||||
@ -89,24 +141,55 @@ async function checkOmahaProxyAvailability() {
|
|||||||
),
|
),
|
||||||
])
|
])
|
||||||
).map((s) => parseInt(s, 10));
|
).map((s) => parseInt(s, 10));
|
||||||
const from = Math.max(...lastchanged);
|
const from = Math.max(...latestRevisions);
|
||||||
checkRangeAvailability(from, 0, true /* stopWhenAllAvailable */);
|
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 {*} options
|
||||||
* @param {number} toRevision
|
|
||||||
* @param {boolean} stopWhenAllAvailable
|
|
||||||
*/
|
*/
|
||||||
async function checkRangeAvailability(
|
async function checkRangeAvailability({
|
||||||
fromRevision,
|
fromRevision,
|
||||||
toRevision,
|
toRevision,
|
||||||
stopWhenAllAvailable
|
stopWhenAllAvailable,
|
||||||
) {
|
}) {
|
||||||
const table = new Table([10, 7, 7, 7, 7]);
|
const table = new Table([10, 7, 7, 7, 7]);
|
||||||
table.drawRow([''].concat(SUPPORTER_PLATFORMS));
|
table.drawRow([''].concat(SUPPORTER_PLATFORMS));
|
||||||
|
|
||||||
const inc = fromRevision < toRevision ? 1 : -1;
|
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(
|
const allAvailable = await checkAndDrawRevisionAvailability(
|
||||||
table,
|
table,
|
||||||
'',
|
'',
|
||||||
@ -200,3 +283,5 @@ function padCenter(text, length) {
|
|||||||
const right = Math.ceil((length - printableCharacters.length) / 2);
|
const right = Math.ceil((length - printableCharacters.length) / 2);
|
||||||
return spaceString(left) + text + spaceString(right);
|
return spaceString(left) + text + spaceString(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
|
Loading…
Reference in New Issue
Block a user