-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Reporting/Build Chromium] Add a developer script to find the Chromiu…
…m commit (#94033) * script that finds the chromium commit * use run from dev-utils * update docs and inch towards build pipeline * more docs updates * move the scripts the root * review feedback
- Loading branch information
Showing
5 changed files
with
164 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
require('../src/setup_node_env'); | ||
require('../src/dev/chromium_version'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { run, REPO_ROOT, ToolingLog } from '@kbn/dev-utils'; | ||
import chalk from 'chalk'; | ||
import cheerio from 'cheerio'; | ||
import fs from 'fs'; | ||
import fetch from 'node-fetch'; | ||
import path from 'path'; | ||
import { PackageJson } from 'type-fest'; | ||
|
||
type PuppeteerRelease = string; | ||
type ChromiumRevision = string; | ||
type ChromiumCommit = string; | ||
|
||
// We forked the Puppeteer node module for Kibana, | ||
// So we need to translate OUR version to the official Puppeteer Release | ||
const forkCompatibilityMap: Record<string, PuppeteerRelease> = { | ||
'5.4.1-patch.1': '5.4.1', | ||
}; | ||
|
||
async function getPuppeteerRelease(log: ToolingLog): Promise<PuppeteerRelease> { | ||
// open node_modules/puppeteer/package.json | ||
const puppeteerPackageJson: PackageJson = JSON.parse( | ||
fs.readFileSync(path.resolve(REPO_ROOT, 'node_modules', 'puppeteer', 'package.json'), 'utf8') | ||
); | ||
const { version } = puppeteerPackageJson; | ||
if (version == null) { | ||
throw new Error( | ||
'Could not get the Puppeteer version! Check node_modules/puppteer/package.json' | ||
); | ||
} | ||
log.info(`Kibana is using Puppeteer ${version} (${forkCompatibilityMap[version]})`); | ||
return forkCompatibilityMap[version]; | ||
} | ||
|
||
async function getChromiumRevision( | ||
kibanaPuppeteerVersion: PuppeteerRelease, | ||
log: ToolingLog | ||
): Promise<ChromiumRevision> { | ||
const url = `https://raw.githubusercontent.com/puppeteer/puppeteer/v${kibanaPuppeteerVersion}/src/revisions.ts`; | ||
let body: string; | ||
try { | ||
log.info(`Fetching code from Puppeteer source: ${url}`); | ||
const rawSource = await fetch(url); | ||
body = await rawSource.text(); | ||
} catch (err) { | ||
log.error(err); | ||
throw new Error(`Could not fetch ${url}. Check the URL in a browser and try again.`); | ||
} | ||
|
||
let revision: ChromiumRevision | undefined; | ||
const lines = body.split('\n'); | ||
let cursor = lines.length; | ||
while (--cursor >= 0) { | ||
// look for the line of code matching ` chromium: '0123456',` | ||
const test = lines[cursor].match(/^\s+chromium: '(\S+)',$/); | ||
if (test != null) { | ||
log.debug(`Parsed revision from source text: \`${lines[cursor]}\``); | ||
[, revision] = test; | ||
break; | ||
} | ||
} | ||
|
||
if (revision == null) { | ||
throw new Error( | ||
`Could not find a Chromium revision listed in Puppeteer source! Check ${url} in a browser` | ||
); | ||
} | ||
|
||
log.info(`Found Chromium revision ${revision} from Puppeteer ${kibanaPuppeteerVersion}`); | ||
return revision; | ||
} | ||
|
||
async function getChromiumCommit( | ||
revision: ChromiumRevision, | ||
log: ToolingLog | ||
): Promise<ChromiumCommit> { | ||
const url = `https://crrev.com/${revision}`; | ||
log.info(`Fetching ${url}`); | ||
const pageText = await fetch(url); | ||
const $ = cheerio.load(await pageText.text()); | ||
|
||
// get the commit from the page title | ||
let commit: ChromiumCommit | null = null; | ||
const matches = $('title') | ||
.text() | ||
.match(/\S{40}/); | ||
if (matches != null) { | ||
log.debug(`Parsed commit hash from page title: \`${$('title').text()}\``); | ||
[commit] = matches; | ||
} | ||
|
||
if (commit == null) { | ||
throw new Error(`Could not find a Chromium commit! Check ${url} in a browser.`); | ||
} | ||
|
||
log.info(`Found Chromium commit ${commit} from revision ${revision}.`); | ||
return commit; | ||
} | ||
|
||
run( | ||
async ({ | ||
log, | ||
flags: { | ||
_: [puppeteerVersionArg], | ||
}, | ||
}) => { | ||
try { | ||
let puppeteerVersion: PuppeteerRelease; | ||
if (puppeteerVersionArg) { | ||
puppeteerVersion = puppeteerVersionArg; | ||
} else { | ||
puppeteerVersion = await getPuppeteerRelease(log); | ||
} | ||
|
||
const chromiumRevision = await getChromiumRevision(puppeteerVersion, log); | ||
await getChromiumCommit(chromiumRevision, log); | ||
} catch (err) { | ||
log.error(err); | ||
} | ||
}, | ||
{ | ||
description: chalk` | ||
Display the Chromium git commit that correlates to a given Puppeteer release. | ||
- node x-pack/dev-tools/chromium_version 5.5.0 {dim # gets the Chromium commit for Puppeteer v5.5.0} | ||
- node x-pack/dev-tools/chromium_version {dim # gets the Chromium commit for the Kibana dependency version of Puppeteer} | ||
You can use https://omahaproxy.appspot.com/ to look up the Chromium release that first shipped with that commit. | ||
`, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ef768c94bcb42dca4c27048615d07efadbb1c1c2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters