|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +// Updates browsers.json to the latest Chrome for Testing on the same branch, |
| 18 | +// so that the docker image ships the latest security fixes. Chrome releases |
| 19 | +// fixes as patch bumps on the same branch, e.g. 156.0.8078.4 -> 156.0.8078.80. |
| 20 | +// The revision is kept, so that the browser directory name stays the same. |
| 21 | + |
| 22 | +import fs from 'fs'; |
| 23 | + |
| 24 | +const browsersJSONPath = process.argv[2]; |
| 25 | +if (!browsersJSONPath) |
| 26 | + throw new Error('usage: update-chromium-version.mjs <path to browsers.json>'); |
| 27 | + |
| 28 | +const browsersJSON = JSON.parse(fs.readFileSync(browsersJSONPath, 'utf8')); |
| 29 | +const descriptors = ['chromium', 'chromium-headless-shell'].map(name => { |
| 30 | + const descriptor = browsersJSON.browsers.find(browser => browser.name === name); |
| 31 | + if (!descriptor) |
| 32 | + throw new Error(`Missing browser descriptor: ${name}`); |
| 33 | + return descriptor; |
| 34 | +}); |
| 35 | + |
| 36 | +const patchOf = version => Number(version.split('.')[3]); |
| 37 | +const currentVersion = descriptors[0].browserVersion; |
| 38 | +if (!/^\d+\.\d+\.\d+\.\d+$/.test(currentVersion)) |
| 39 | + throw new Error(`Unexpected Chrome for Testing version: ${currentVersion}`); |
| 40 | +const branchPrefix = currentVersion.split('.').slice(0, 3).join('.') + '.'; |
| 41 | + |
| 42 | +const url = 'https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json'; |
| 43 | +const response = await fetch(url, { signal: AbortSignal.timeout(30_000) }); |
| 44 | +if (!response.ok) |
| 45 | + throw new Error(`Failed to fetch ${url}: ${response.status}`); |
| 46 | +const { versions } = await response.json(); |
| 47 | + |
| 48 | +let latestVersion = currentVersion; |
| 49 | +for (const { version, downloads } of versions) { |
| 50 | + if (!version.startsWith(branchPrefix) || !downloads.chrome || !downloads['chrome-headless-shell']) |
| 51 | + continue; |
| 52 | + if (patchOf(version) > patchOf(latestVersion)) |
| 53 | + latestVersion = version; |
| 54 | +} |
| 55 | + |
| 56 | +if (latestVersion === currentVersion) { |
| 57 | + console.log(`Chrome for Testing ${currentVersion} is the latest on its branch`); |
| 58 | +} else { |
| 59 | + console.log(`Updating Chrome for Testing ${currentVersion} to ${latestVersion}`); |
| 60 | + for (const descriptor of descriptors) |
| 61 | + descriptor.browserVersion = latestVersion; |
| 62 | + fs.writeFileSync(browsersJSONPath, JSON.stringify(browsersJSON, null, 2) + '\n'); |
| 63 | +} |
0 commit comments