Skip to content

Commit

Permalink
tests(devtools): dynamically fetch chromium version (#12232)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny authored Mar 16, 2021
1 parent 8d38cb5 commit fe17b61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions third-party/download-content-shell/download-content-shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ const MAX_CONTENT_SHELLS = 10;
const PLATFORM = getPlatform();
const LH_ROOT = `${__dirname}/../..`;
const CACHE_PATH = path.resolve(LH_ROOT, '.tmp', 'chromium-web-tests', 'content-shells');
const COMMIT_POSITION_UPDATE_PERIOD = 420;

function main() {
fs.mkdirSync(CACHE_PATH, {recursive: true});
deleteOldContentShells();

findPreviousUploadedPosition(findMostRecentChromiumCommit())
findMostRecentChromiumCommit()
.then(findPreviousUploadedPosition)
.then(onUploadedCommitPosition)
.catch(onError);

Expand Down Expand Up @@ -64,13 +66,13 @@ function getPlatform() {
throw new Error(`Unrecognized platform detected: ${process.platform}`);
}

function findMostRecentChromiumCommit() {
// TODO: this code works only if there is a full chromium checkout present.
// const commitMessage = shell('git log --max-count=1 --grep="Cr-Commit-Position"').toString().trim();
// const commitPosition = commitMessage.match(/Cr-Commit-Position: refs\/heads\/master@\{#([0-9]+)\}/)[1];
// return commitPosition;
// TODO: make this dynamic.
return '856956';
async function findMostRecentChromiumCommit() {
const snapshotUrl = `https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/${PLATFORM}%2FLAST_CHANGE?alt=media`;
const commitPosition = Number((await utils.fetch(snapshotUrl)).toString());

// Only update the content shell roughly once a day.
// see https://github.com/GoogleChrome/lighthouse/pull/12232#discussion_r592016416
return commitPosition - commitPosition % COMMIT_POSITION_UPDATE_PERIOD;
}

function deleteOldContentShells() {
Expand Down
2 changes: 1 addition & 1 deletion third-party/download-content-shell/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function fetch(url) {

function getCallback(resolve, reject, response) {
if (response.statusCode !== 200) {
reject(new Error(`Request error: + ${response.statusCode}`));
reject(new Error(`Request error: ${response.statusCode}`));
return;
}
const body = new Stream();
Expand Down

0 comments on commit fe17b61

Please sign in to comment.