-
Notifications
You must be signed in to change notification settings - Fork 91
/
find-version.mjs
91 lines (79 loc) · 2.83 KB
/
find-version.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Copyright 2023 Google LLC
*
* 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
*
* https://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.
*/
// This script gets Chrome release version numbers per platform
// from the Chromium Dash API, figures out the most appropriate version
// number to use for bundling with Puppeteer, and prints its download
// URLs + their HTTP status codes.
import fs from 'node:fs/promises';
import {binaries, checkDownloadsForVersion} from './url-utils.mjs';
import {isOlderVersion} from './is-older-version.mjs';
const findVersionForChannel = async (channel = 'Stable') => {
const result = {
channel,
version: '0.0.0.0',
revision: '0',
ok: false,
downloads: {},
};
for (const binary of binaries) {
result.downloads[binary] = [];
}
console.log(`Checking the ${channel} channel…`);
const apiEndpoint = `https://chromiumdash.appspot.com/fetch_releases?channel=${channel}&num=1&platform=Win32,Windows,Mac,Linux`;
const response = await fetch(apiEndpoint);
const data = await response.json();
let minVersion = `99999.99999.99999.99999`;
const versions = new Set();
let minRevision = 9999999999999999;
for (const entry of data) {
const version = entry.version;
const revision = String(entry.chromium_main_branch_position);
versions.add(version);
if (isOlderVersion(version, minVersion)) {
minVersion = version;
minRevision = revision;
}
}
console.log(`Found versions:`, versions);
console.log(`Recommended version for ${channel} channel:`, minVersion);
result.version = minVersion;
result.revision = minRevision;
const version = minVersion;
const checked = await checkDownloadsForVersion(version);
for (const {binary, platform, url, status} of checked.downloads) {
result.downloads[binary].push({ platform, url, status });
console.log(url, status);
}
console.log(checked.isOk ? '\u2705 OK' : '\u274C NOT OK');
result.ok = checked.isOk;
return result;
};
const allResults = {
timestamp: new Date().toISOString(),
ok: false,
channels: {},
};
const channels = ['Stable', 'Beta', 'Dev', 'Canary'];
let hasFailure = false;
for (const channel of channels) {
const result = await findVersionForChannel(channel);
if (!result.ok) hasFailure = true;
allResults.channels[channel] = result;
console.log('');
}
allResults.ok = !hasFailure;
const json = JSON.stringify(allResults, null, '\t');
await fs.writeFile('./data/dashboard.json', `${json}\n`);