2017-05-15 03:05:41 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2018-05-31 23:53:51 +00:00
|
|
|
const assert = require('assert');
|
2018-02-07 17:31:53 +00:00
|
|
|
const puppeteer = require('..');
|
2017-08-02 19:06:47 +00:00
|
|
|
const https = require('https');
|
2018-02-07 17:31:53 +00:00
|
|
|
const SUPPORTER_PLATFORMS = ['linux', 'mac', 'win32', 'win64'];
|
2017-05-15 03:05:41 +00:00
|
|
|
|
2018-02-07 17:31:53 +00:00
|
|
|
const fetchers = SUPPORTER_PLATFORMS.map(platform => puppeteer.createBrowserFetcher({platform}));
|
2017-12-08 21:39:13 +00:00
|
|
|
|
2017-08-02 19:06:47 +00:00
|
|
|
const colors = {
|
2017-06-21 20:51:06 +00:00
|
|
|
reset: '\x1b[0m',
|
|
|
|
red: '\x1b[31m',
|
|
|
|
green: '\x1b[32m',
|
|
|
|
yellow: '\x1b[33m'
|
2017-05-15 03:05:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Table {
|
2017-06-21 20:51:06 +00:00
|
|
|
/**
|
2017-06-21 20:36:04 +00:00
|
|
|
* @param {!Array<number>} columnWidths
|
|
|
|
*/
|
2017-06-21 20:51:06 +00:00
|
|
|
constructor(columnWidths) {
|
|
|
|
this.widths = columnWidths;
|
|
|
|
}
|
2017-05-15 03:05:41 +00:00
|
|
|
|
2017-06-21 20:51:06 +00:00
|
|
|
/**
|
2017-06-21 20:36:04 +00:00
|
|
|
* @param {!Array<string>} values
|
|
|
|
*/
|
2017-06-21 20:51:06 +00:00
|
|
|
drawRow(values) {
|
2018-05-31 23:53:51 +00:00
|
|
|
assert(values.length === this.widths.length);
|
2017-06-22 20:38:10 +00:00
|
|
|
let row = '';
|
|
|
|
for (let i = 0; i < values.length; ++i)
|
2017-06-21 20:51:06 +00:00
|
|
|
row += padCenter(values[i], this.widths[i]);
|
|
|
|
console.log(row);
|
|
|
|
}
|
2017-05-15 03:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (process.argv.length === 2) {
|
2017-06-21 20:51:06 +00:00
|
|
|
checkOmahaProxyAvailability();
|
|
|
|
return;
|
2017-05-15 03:05:41 +00:00
|
|
|
}
|
|
|
|
if (process.argv.length !== 4) {
|
2017-06-21 20:51:06 +00:00
|
|
|
console.log(`
|
2017-05-15 03:05:41 +00:00
|
|
|
Usage: node check_revisions.js [fromRevision] [toRevision]
|
|
|
|
|
|
|
|
This script checks availability of different prebuild chromium revisions.
|
|
|
|
Running command without arguments will check against omahaproxy revisions.`);
|
2017-06-21 20:51:06 +00:00
|
|
|
return;
|
2017-05-15 03:05:41 +00:00
|
|
|
}
|
|
|
|
|
2017-08-21 23:39:04 +00:00
|
|
|
const fromRevision = parseInt(process.argv[2], 10);
|
|
|
|
const toRevision = parseInt(process.argv[3], 10);
|
2019-07-29 21:29:50 +00:00
|
|
|
checkRangeAvailability(fromRevision, toRevision, false /* stopWhenAllAvailable */);
|
2017-05-15 03:05:41 +00:00
|
|
|
|
|
|
|
async function checkOmahaProxyAvailability() {
|
2018-05-31 21:20:41 +00:00
|
|
|
const lastchanged = (await Promise.all([
|
|
|
|
fetch('https://storage.googleapis.com/chromium-browser-snapshots/Mac/LAST_CHANGE'),
|
|
|
|
fetch('https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/LAST_CHANGE'),
|
|
|
|
fetch('https://storage.googleapis.com/chromium-browser-snapshots/Win/LAST_CHANGE'),
|
|
|
|
fetch('https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/LAST_CHANGE'),
|
|
|
|
])).map(s => parseInt(s, 10));
|
|
|
|
const from = Math.max(...lastchanged);
|
2019-07-29 21:29:50 +00:00
|
|
|
checkRangeAvailability(from, 0, true /* stopWhenAllAvailable */);
|
2017-05-15 03:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} fromRevision
|
|
|
|
* @param {number} toRevision
|
2019-07-29 21:29:50 +00:00
|
|
|
* @param {boolean} stopWhenAllAvailable
|
2017-05-15 03:05:41 +00:00
|
|
|
*/
|
2019-07-29 21:29:50 +00:00
|
|
|
async function checkRangeAvailability(fromRevision, toRevision, stopWhenAllAvailable) {
|
2017-08-21 23:39:04 +00:00
|
|
|
const table = new Table([10, 7, 7, 7, 7]);
|
2018-02-07 17:31:53 +00:00
|
|
|
table.drawRow([''].concat(SUPPORTER_PLATFORMS));
|
2017-08-21 23:39:04 +00:00
|
|
|
const inc = fromRevision < toRevision ? 1 : -1;
|
2019-07-29 21:29:50 +00:00
|
|
|
for (let revision = fromRevision; revision !== toRevision; revision += inc) {
|
|
|
|
const allAvailable = await checkAndDrawRevisionAvailability(table, '', revision);
|
|
|
|
if (allAvailable && stopWhenAllAvailable)
|
|
|
|
break;
|
|
|
|
}
|
2017-05-15 03:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {!Table} table
|
|
|
|
* @param {string} name
|
|
|
|
* @param {number} revision
|
2019-07-29 21:29:50 +00:00
|
|
|
* @return {boolean}
|
2017-05-15 03:05:41 +00:00
|
|
|
*/
|
|
|
|
async function checkAndDrawRevisionAvailability(table, name, revision) {
|
2018-02-07 17:31:53 +00:00
|
|
|
const promises = fetchers.map(fetcher => fetcher.canDownload(revision));
|
2017-08-21 23:39:04 +00:00
|
|
|
const availability = await Promise.all(promises);
|
|
|
|
const allAvailable = availability.every(e => !!e);
|
|
|
|
const values = [name + ' ' + (allAvailable ? colors.green + revision + colors.reset : revision)];
|
2017-06-22 20:38:10 +00:00
|
|
|
for (let i = 0; i < availability.length; ++i) {
|
2017-08-21 23:39:04 +00:00
|
|
|
const decoration = availability[i] ? '+' : '-';
|
|
|
|
const color = availability[i] ? colors.green : colors.red;
|
2017-06-21 20:51:06 +00:00
|
|
|
values.push(color + decoration + colors.reset);
|
|
|
|
}
|
|
|
|
table.drawRow(values);
|
2019-07-29 21:29:50 +00:00
|
|
|
return allAvailable;
|
2017-05-15 03:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} url
|
2018-05-31 21:20:41 +00:00
|
|
|
* @return {!Promise<?string>}
|
2017-05-15 03:05:41 +00:00
|
|
|
*/
|
2018-05-31 21:20:41 +00:00
|
|
|
function fetch(url) {
|
2017-06-22 20:38:10 +00:00
|
|
|
let resolve;
|
2017-08-21 23:39:04 +00:00
|
|
|
const promise = new Promise(x => resolve = x);
|
2017-06-21 20:51:06 +00:00
|
|
|
https.get(url, response => {
|
|
|
|
if (response.statusCode !== 200) {
|
|
|
|
resolve(null);
|
|
|
|
return;
|
|
|
|
}
|
2017-06-22 20:38:10 +00:00
|
|
|
let body = '';
|
2017-06-21 20:51:06 +00:00
|
|
|
response.on('data', function(chunk){
|
|
|
|
body += chunk;
|
|
|
|
});
|
|
|
|
response.on('end', function(){
|
2018-05-31 21:20:41 +00:00
|
|
|
resolve(body);
|
2017-05-15 03:05:41 +00:00
|
|
|
});
|
2017-06-21 20:51:06 +00:00
|
|
|
}).on('error', function(e){
|
|
|
|
console.error('Error fetching json: ' + e);
|
|
|
|
resolve(null);
|
|
|
|
});
|
|
|
|
return promise;
|
2017-05-15 03:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} size
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
function spaceString(size) {
|
2017-06-21 20:51:06 +00:00
|
|
|
return new Array(size).fill(' ').join('');
|
2017-05-15 03:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} text
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
function filterOutColors(text) {
|
2017-08-21 23:39:04 +00:00
|
|
|
for (const colorName in colors) {
|
|
|
|
const color = colors[colorName];
|
2017-06-21 20:51:06 +00:00
|
|
|
text = text.replace(color, '');
|
|
|
|
}
|
|
|
|
return text;
|
2017-05-15 03:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} text
|
|
|
|
* @param {number} length
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
function padCenter(text, length) {
|
2017-08-21 23:39:04 +00:00
|
|
|
const printableCharacters = filterOutColors(text);
|
2017-06-21 20:51:06 +00:00
|
|
|
if (printableCharacters.length >= length)
|
|
|
|
return text;
|
2017-08-21 23:39:04 +00:00
|
|
|
const left = Math.floor((length - printableCharacters.length) / 2);
|
|
|
|
const right = Math.ceil((length - printableCharacters.length) / 2);
|
2017-06-21 20:51:06 +00:00
|
|
|
return spaceString(left) + text + spaceString(right);
|
2017-05-15 03:05:41 +00:00
|
|
|
}
|