-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Reporting/Build Chromium] Add a developer script to find the Chromium commit #94033
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
da7110e
script that finds the chromium commit
tsullivan a419f1b
use run from dev-utils
tsullivan 7876cb0
update docs and inch towards build pipeline
tsullivan 2f88240
more docs updates
tsullivan 8d53001
move the scripts the root
tsullivan 88c00bc
Merge branch 'master' into spacetime/build-chromium
tsullivan 4b95dfe
review feedback
tsullivan File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,139 @@ | ||
/* | ||
* 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 dedent from 'dedent'; | ||
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: dedent(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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we already pass the description to
dedent